Gnuplot直方图配置:如何为不同条形设置不同颜色?
解决gnuplot直方图条形颜色问题
你的脚本已经定义了各系列的颜色,但需要在每个绘图项中同时指定填充颜色(fillcolor)和边框颜色(linecolor),因为默认情况下set style fill不会自动继承linecolor的设置。以下是修改后的完整脚本:
set title font "Monospaced,13" 'Total duration' set terminal png size 650,350 enhanced font "Monospaced,13" set grid set key right top set style data histograms set style histogram cluster gap 2 set style fill solid border 2 set xtics format "" set grid ytics set ylabel "Milliseconds" set yrange [0:70000] ArrayListColor = "#491d75"; IndexedListColor = "#b32929"; LinkedListColor = "#d49435"; TreeListColor = "#12520b"; # 为每个条形同时指定填充色和边框色 plot 'TotalDurationBarPlot.dat' using 1 title "Indexed list" linecolor rgb IndexedListColor fillcolor rgb IndexedListColor, \ '' using 2 title "Tree list" linecolor rgb TreeListColor fillcolor rgb TreeListColor, \ '' using 3 title "Array list" linecolor rgb ArrayListColor fillcolor rgb ArrayListColor, \ '' using 4 title "Linked list" linecolor rgb LinkedListColor fillcolor rgb LinkedListColor, \ '' u 0:1:1 with labels offset -6.0,-100.0 title "" set output 'TotalDuration.png' replot exit
关键修改点:
- 在每个
plot的绘图项末尾添加fillcolor rgb [对应颜色变量],确保条形的填充颜色和边框颜色都使用你定义的自定义色值。 - 用反斜杠
\换行让脚本更易读,这是gnuplot支持的语法。
这样修改后,四个条形就会分别显示你指定的IndexedListColor、TreeListColor、ArrayListColor和LinkedListColor四种颜色。
内容的提问来源于stack exchange,提问作者coderodde
相关产品推荐
相关产品推荐

