gnuplot 不显示数据框

data boxes not displayed by gnuplot

我想使用 gnuplot 制作条形图。

我使用了这个设置

set style data boxes
set style fill solid  
plot 'foo.dat' using 1:2:(1) linewidth 2

foo.dat的内容为

8 1
10 1
11 4
12 4

gnuplot 只显示与最后两行对应的条形。

为什么? 除了在我的数据文件中添加“9 0”之外,还有其他解决方案吗?

提前致谢

默认情况下,您的图形将在 y 轴上从 1 自动缩放到 4。这就是为什么您看不到前两个条形的原因。

解决方案:正确设置您的 y 范围。

set yrange[0:5]

编辑: @Christoph 的好建议 set yrange[0:*] 将方便地自动缩放上限。然而,从 [0:4] 开始,当盒子接触上部 x 轴时看起来不太好。 因此,我建议增加一些边距 set offsets 0,0,1,0 # left,right,top,bottom。检查 help margins.

代码:

### plot boxes 
reset session

$Data <<EOD
8 1
10 1
11 4
12 4
EOD

set style data boxes
set style fill solid
set yrange [0:*]
set offsets 0,0,1,0   # left,right,top,bottom

plot $Data using 1:2:(1) w boxes linewidth 2
### end of code

结果:

您的 y 轴可能自动缩放为 [1:4]。使用例如

set yrange [0:*]

然后轴始终从 0 开始,但在另一端自动缩放。