4

运行以下脚本时,我收到一条错误消息:

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

我得到的错误信息是

smeik:plots nvcleemp$ gnuplot categorie.gnuplot 

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

该文件的内容categorie.dat

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

我知道问题是我没有定义 x 范围。我怎样才能让他使用第一列作为 x 范围的值?还是我需要将行号作为 x 范围并让他使用第一列作为标签?我正在使用 Gnuplot 4.4。

我最终试图得到一个看起来与我之前制作的情节相同的情节。那个工作正常,但在 x 轴上有数字数据。

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

文件的内容geboorte.dat

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

1 回答 1

10

boxes样式要求 x 值是数字。这很简单,我们可以给它一个伪列 0,它本质上是脚本的行号:

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

现在您可能希望以某种方式在绘图的第一列中获取信息。我假设您希望这些字符串成为 x-tics:

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

*注意这里,这可能不适用于您当前的boxwidth设置。您可能要考虑set boxwidth 1plot ... with (5*column(0)):2:xtic(1) ...

编辑- 以您在上面发布的数据文件,我已经测试了上述两个更改以使 boxwidth 正确,并且两者似乎都有效。

于 2012-12-18T14:04:49.480 回答