Bra*_*rad 113
简单的条形图:
set boxwidth 0.5
set style fill solid
plot "data.dat" using 1:3:xtic(2) with boxes
Run Code Online (Sandbox Code Playgroud)
data.dat文件:
0 label 100
1 label2 450
2 "bar label" 75
Run Code Online (Sandbox Code Playgroud)
如果您想以不同的方式设置酒吧样式,您可以执行以下操作:
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
Run Code Online (Sandbox Code Playgroud)
如果您想为每个条目执行多个条形:
data.dat文件:
0 5
0.5 6
1.5 3
2 7
3 8
3.5 1
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
如果你想变得棘手并使用一些巧妙的gnuplot技巧:
Gnuplot有伪列,可以用作颜色的索引:
plot 'data.dat' using 1:2:0 with boxes lc variable
Run Code Online (Sandbox Code Playgroud)
此外,您可以使用函数来选择所需的颜色:
mycolor(x) = ((x*11244898) + 2851770)
plot 'data.dat' using 1:2:(mycolor($0)) with boxes lc rgb variable
Run Code Online (Sandbox Code Playgroud)
注意:您必须添加其他几个基本命令才能获得与示例图像相同的效果.
tat*_*ght 25
plot "data.dat" using 2: xtic(1) with histogram
这里data.dat包含表单的数据
title 1 title2 3 "long title" 5
Mar*_*sas 14
我想扩展一下最佳答案,它使用GNUPlot为绝对的初学者创建一个条形图,因为我读了答案并且仍然从语法的泛滥中感到困惑.
我们首先编写GNUplot命令的文本文件.让我们称之为commands.txt:
set term png
set output "graph.png"
set boxwidth 0.5
set style fill solid
plot "data.dat" using 1:3:xtic(2) with boxes
Run Code Online (Sandbox Code Playgroud)
set term png
将GNUplot设置为输出.png文件,并将set output "graph.png"
其输出到的文件的名称.
接下来的两行是相当自我解释的.第五行包含很多语法.
plot "data.dat" using 1:3:xtic(2) with boxes
Run Code Online (Sandbox Code Playgroud)
"data.dat"
是我们正在操作的数据文件.1:3
表示我们将使用data.dat的第1列作为x坐标,使用data.dat的第3列作为y坐标.xtic()
是一个负责编号/标记x轴的函数.xtic(2)
因此,表示我们将使用data.dat的第2列作为标签.
"data.dat"看起来像这样:
0 label 100
1 label2 450
2 "bar label" 75
Run Code Online (Sandbox Code Playgroud)
要绘制图形,请输入gnuplot commands.txt
终端.