admin 管理员组文章数量: 1086019
I'm trying to plot the absolute values of a datablock (called $dif) with solid boxes, whose colors depend on whether the y-coordinate is greater or lower than zero, namely
plot $dif u (timecolumn(1,"%d/%m/%Y")):(abs($2)) w boxes fs solid 0.7 fc (($2)>=0 ? "green":"red") axis x1y2 notitle
I'm obviously making a syntax error since I'm getting the following error message: "colorspec option not recognized". Does anyone see what I'm doing wrong ?
I'm trying to plot the absolute values of a datablock (called $dif) with solid boxes, whose colors depend on whether the y-coordinate is greater or lower than zero, namely
plot $dif u (timecolumn(1,"%d/%m/%Y")):(abs($2)) w boxes fs solid 0.7 fc (($2)>=0 ? "green":"red") axis x1y2 notitle
I'm obviously making a syntax error since I'm getting the following error message: "colorspec option not recognized". Does anyone see what I'm doing wrong ?
Share Improve this question asked Mar 27 at 21:28 ifffamifffam 1879 bronze badges1 Answer
Reset to default 2If you want variable color depending on the data file you should use the option lc variable
(please check help colorspec
). The last given column in ... using 1:2:(<column or function for color>)
will determine the color.
So, either use RGB codes (0xrrggbb
) for the color
plot $Data u 1:2:($2>0?0x00ff00:0xff0000) w boxes lc rgb var
or since gnuplot 5.5
plot $Data u 1:2:($2>0?rgbcolor("green"):rgbcolor("red")) w boxes lc rgb var
As minimal complete example:
Script:
### variable colors
reset session
# create some random test data
set table $Data
set samples 9
plot '+' u 0:(rand(0)*10-5) w table
unset table
set key noautotitle
set boxwidth 0.9
set xrange noextend
set xzeroaxis lt -1
set style fill solid 0.5
plot $Data u 1:2:($2>0?0x00ff00:0xff0000) w boxes lc rgb var
### end of script
Result:
本文标签: gnuplotTo plot boxes with different colors depending on a given conditionStack Overflow
版权声明:本文标题:gnuplot - To plot boxes with different colors depending on a given condition - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/p/1744067182a2527819.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论