如何在gnuplot中用文本标签绘制条形图?如何在gnuplot中绘制条形图?
回答
plot "data.dat" using 2: xtic(1) with histogram
这里data.dat文件包含表单
title 1 title2 3 "long title" 5
我建议德里克·布鲁宁的条形图发电机Perl脚本的数据。可在http://www.burningcutlery.com/derek/bargraph/
简单条形图:
set boxwidth 0.5
set style fill solid
plot "data.dat" using 1:3:xtic(2) with boxes
data.dat文件:
0 label 100
1 label2 450
2 "bar label" 75
如果您希望以不同风格你吧,你可以这样做:
set style line 1 lc rgb "red"
set style line 2 lc rgb "blue"
set style fill solid
set boxwidth 0.5
plot "data.dat" every ::0::0 using 1:3:xtic(2) with boxes ls 1, \
"data.dat" every ::1::2 using 1:3:xtic(2) with boxes ls 2
如果你想为每个条目做多的酒吧:
data.dat文件:
0 5
0.5 6
1.5 3
2 7
3 8
3.5 1
gnuplot的:
set xtics ("label" 0.25, "label2" 1.75, "bar label" 3.25,)
set boxwidth 0.5
set style fill solid
plot 'data.dat' every 2 using 1:2 with boxes ls 1,\
'data.dat' every 2::1 using 1:2 with boxes ls 2
如果你想成为非常棘手,并使用一些巧妙的gnuplot的招数:
的Gnuplot有伪列可以作为指标的颜色:
plot 'data.dat' using 1:2:0 with boxes lc variable
此外,你可以使用一个功能来选择你想要的颜色:
mycolor(x) = ((x*11244898) + 2851770)
plot 'data.dat' using 1:2:(mycolor($0)) with boxes lc rgb variable
注意:您必须添加一些其他基本命令才能获得与示例图像相同的效果。
我只想扩展最重要的答案,它使用GNUPlot为绝对初学者创建条形图,因为我阅读了答案,并且仍然从语法洪水中感到困惑。
我们从编写GNUplot命令的文本文件开始。让我们把它叫做commands.txt中:
一组项PNG
组输出 “graph.png”
集boxwidth 0。5
集样式填固体
情节 “data.dat文件” 使用1:3:xtic(2)与盒
“设置术语PNG” 将GNUPLOT设置为输出PNG文件和“set output”graph.png“”是要输出到的文件的名称。
接下来的两行很自我解释。第五行包含很多语法。
情节 “data.dat文件” 使用1:3:xtic(2)与盒
“data.dat文件” 是我们正在操作的数据文件。 “1:3”表示我们将data.dat的第1列用于x坐标,data.dat的第3列用于y坐标。 xtic()是一个负责编号/标记x轴的函数。因此,xtic(2)表示我们将使用data.dat的第2列作为标签。
“data.dat文件” 看起来像这样:
0标签100
1 LABEL2 450
2 “栏中标记” 75
要绘制的曲线图,在终端中输入“gnuplot commands.txt”。
对于许多应用程序,使用“直方图”绘图样式更加方便,特别是对于分组和堆栈值。 – Christoph 2015-02-01 14:18:18