nvcleemp
nvcleemp

Reputation: 560

x range for non-numerical data in Gnuplot

When running the following script, I get an error message:

set terminal postscript enhanced color
set output '| ps2pdf - histogram_categorie.pdf'
set auto x
set key off
set yrange [0:20]
set style fill solid border -1
set boxwidth 5
unset border
unset ytic
set xtics nomirror
plot "categorie.dat" using 1:2 ti col with boxes

The error message that I get is

smeik:plots nvcleemp$ gnuplot categorie.gnuplot 

plot "categorie.dat" using 1:2 ti col with boxes
                                            ^
"categorie.gnuplot", line 13: x range is invalid

The content of the file categorie.dat is

categorie   aantal
poussin  13
pupil  9
miniem  15
cadet  15
junior  6
senior  5
veteraan  8

I understand that the problem is that I haven't defined an x range. How can I make him use the first column as values for the x range? Or do I need to take the row numbers as x range and let him use the first column as labels? I'm using Gnuplot 4.4.

I'm ultimately trying to get a plot that looks the same as the plot I made before this one. That one worked fine, but had numerical data on the x axis.

set terminal postscript enhanced color
set output '| ps2pdf - histogram_geboorte.pdf'
set auto x
set key off
set yrange [0:40]
set xrange [1935:2005]
set style fill solid border -1
set boxwidth 5
unset border
unset ytic
set xtics nomirror
plot "geboorte.dat" using 1:2 ti col with boxes,\
     "geboorte.dat" using 1:($2+2):2 with labels

and the content of the file geboorte.dat is

decennium aantal
1940  2
1950  1
1960  3
1970  2
1980  3
1990  29
2000  30

Upvotes: 4

Views: 8874

Answers (1)

mgilson
mgilson

Reputation: 309831

the boxes style expects that the x-values are numeric. That's an easy one, we can give it the pseudo-column 0 which is essentially the script's line number:

plot "categorie.dat" using (column(0)):2 ti col with boxes

Now you probably want the information in the first column on the plot somehow. I'll assume you want those strings to become the x-tics:

plot "categorie.dat" using (column(0)):2:xtic(1) ti col with boxes

*careful here, this might not work with your current boxwidth settings. You might want to consider set boxwidth 1 or plot ... with (5*column(0)):2:xtic(1) ....

EDIT -- Taking your datafiles posted above, I've tested both of the above changes to get the boxwidth correct, and both seemed to work.

Upvotes: 10

Related Questions