尝试添加 gnuplot 直方图标签时出错

error when trying to add gnuplot histogram labels

我是 gnuplot 的新手,我正在尝试绘制此数据(gnuplot 从标准输入接收此输入):

Regular 5
Block 3
Symbolic 8
Char 3
Socket 7

使用此 gnuplot 代码:

set style data histograms
set style fill solid
set terminal png
set output "plot.png"

plot '-' using 2:xtic(1), \
    '' using 0:( + .1) with labels notitle

我收到错误 Not enough columns for this style。我究竟做错了什么?如果我删除带有标签的最后一行,我就可以绘制直方图。我如何修改它以在每个直方图条形图顶部获取数据标签?

with labels 需要三栏信息 x y text。你给了坐标但没有实际的文字。尝试

$DATA << EOD
Regular 5
Block 3
Symbolic 8
Char 3
Socket 7
EOD

set style data histograms
set style fill solid
set yrange [0:*]
plot $DATA using 2:xtic(1), \
    '' using 0:( + .1):2 with labels notitle

试试这个:

plot 'input_file' using 2, '' using 0:2:1 with labels offset 0, char 1

请注意,我已将值添加到名为 input_file 的文件中,并已设置 set yrange [0:10] 以使情节更易于观看

这给出: