我想使用gnuplot制作条形图,使用数据文件第3列的值,第2列的xtic标签和第4列的颜色。该文件如下所示:
0 "13 Sep" 2400.18 "blue"
1 "13 Oct" 440.86 "blue"
2 "13 Nov" 867.03 "blue"
3 "13 Dec" -247.32 "red"
4 "14 Jan" -3457.56 "red"
5 "14 Feb" 666.94 "blue"
目前,我使用以下命令进行绘制,
plot "output.txt" using 1:3:xtic(2) with boxes
并且该图在x轴上具有正确的tic标记,并且所有条形均为红色。我想做的是从文件中获取条形颜色,或者选择具有平滑的调色板,从蓝色到红色,并通过白色。
我尝试了很多不同的建议,但发现都在搜索互联网,但没有成功。我该怎么办?
要根据数据选择线条颜色,可以使用linecolor variable
。在这种情况下,您必须将线型索引作为附加列。
您的数据文件有些多余。您不需要第一列,您始终可以将行号访问为column(0)
。颜色可以从值符号得出:
"13 Sep" 2400.18
"13 Oct" 440.86
"13 Nov" 867.03
"13 Dec" -247.32
"14 Jan" -3457.56
"14 Feb" 666.94
脚本是:
set style fill solid noborder
set xzeroaxis lt -1 lw 2
set boxwidth 0.9 relative
plot "output.txt" using 0:2:($2 < 0 ? 1 : 3):xtic(1) with boxes linecolor variable t ''
结果(版本4.6.3):
您也可以使用linecolor rgb variable
,linecolor palette
等等。
如果要根据框的值将框着色为红色/蓝色和白色的混合物,则可以执行以下操作:
set style fill solid border lt -1
set xzeroaxis lt -1 lw 2
set boxwidth 0.9 relative
unset key
stats "output.txt" using 2 nooutput
set palette defined (STATS_min 'red', 0 'white', STATS_max 'blue')
set autoscale cbfix
plot "output.txt" using 0:2:2:xtic(1) with boxes linecolor palette
结果:
在框内获取渐变更加复杂,并且需要一些技巧,请参见Gnuplot框上的垂直渐变取决于值吗?。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句