15

是否可以动态更改 Gnuplot 脚本中的条形颜色?我有以下脚本

reset
fontsize = 12
set term postscript enhanced eps fontsize
set output "bargraph_speedup.eps"
set style fill solid 1.00 border 0
set style histogram
set style data histogram
set xtics rotate by -45
set grid ytics linestyle 1
set xlabel "Benchmarks" font "bold"
set ylabel "Relative execution time vs. reference implementation" font "bold"
set datafile separator ","
plot 'bm_speedup.dat' using 2:xtic(1) ti "Speedup" linecolor rgb "#00FF00"

生成此图:

生成的图

是否可以将零以下的条形颜色设为红色?

谢谢,
斯文

4

4 回答 4

12

boxes您可以使用以下样式模仿此行为:

我的测试数据:

zip 2
baz 2
bar -1
cat 4
foo -3

然后用 gnuplot 绘图:

set style line 1 lt 1 lc rgb "green"
set style line 2 lt 1 lc rgb "red"
set style fill solid
plot 'test.dat'  u (column(0)):2:(0.5):($2>0?1:2):xtic(1) w boxes lc variable
#                  #xval:ydata:boxwidth:color_index:xtic_labels
于 2012-09-02T23:37:43.417 回答
4

您可以将数据文件分成两部分,正值和负值,并分别绘制它们:

plot 'bm_speedup_pos.dat' using 2:xtic(1) ti "Faster" linecolor rgb "#00FF00", \
     'bm_speedup_neg.dat' using 2:xtic(1) ti "Slower" linecolor rgb "#FF0000"

或者,如果你只需要生成几张图,几次,一种常见的技术是在 gnuplot 中生成原始图,然后在图像编辑器中对其进行后期处理以调整颜色。如果你走那条路,我建议让 gnuplot 以 SVG 格式生成图形,这将为你提供比任何位图格式更好看的图形。

于 2012-09-01T06:33:11.367 回答
2

直方图似乎不允许您这样做。可能是这样的:

set boxwidth 0.3
f(v)=v<0?1:2
plot 'bm_speedup.dat' using 0:2:(f($2)):xticlabels(1) with boxes ti "Speedup" lc variable
于 2012-09-01T06:08:36.887 回答
2

实际上,您也可以使用 linecolor rgb 变量并给出如下颜色:

plot 'bm_speedup.dat' using 2:xtic(1):($2 >= 0 ? 0x00FF00 : 0xFF0000) ti Speedup lc rgb variable
于 2014-01-09T21:12:07.807 回答