如何在 GNUPlot 的箱线图中制作 xtics 标签颜色变量?
How to make xtics label color variable in box plot in GNUPlot?
这是我尝试使 xtics 标签颜色与 gnuplot 中的箱形图中的线条颜色相匹配:
$DATA << EOD
1 1
2 2
3 3
EOD
set linetype 1 linecolor rgb "red"
set linetype 2 linecolor rgb "green"
set linetype 3 linecolor rgb "blue"
set key off
set boxwidth 0.5
set style fill solid 0.5
set xrange [0:4]
set yrange [0:4]
set xtics ("1" 1) textcolor rgb "red"
set xtics add ("2" 2) textcolor rgb "green"
set xtics add ("3" 3) textcolor rgb "blue"
plot $DATA using 1:2:1 with boxes linecolor variable
但它不起作用:
有什么想法吗?谢谢!
我不确定您是否可以将 xtics 单独设置为不同的颜色。因此,以下解决方案将 xtics 设置为空行,并以一定的偏移量绘制 xtics with labels
。缺点是你必须在这里设置y-position:(0)
和offset 0,-1
。希望有更好的解决办法。
代码:
### "xtic labels" in different colors
reset session
$Data << EOD
1 1
2 2
3 3
EOD
set linetype 1 lc "red"
set linetype 2 lc "green"
set linetype 3 lc "blue"
set key off
set boxwidth 0.5
set style fill solid 0.5
set xrange [0:4]
set yrange [0:4]
set format x "\n" # xtic label empty line
plot $Data u 1:2:1 w boxes lc var, \
'' u 1:(0):1:1 w labels tc var offset 0,-1
### end of code
或者,您可以使用相对于图形的偏移量:
plot $Data u 1:2:1 w boxes lc var, \
'' u 1:(0):1:1 w labels tc var offset 0, graph -0.05
结果:
这是我尝试使 xtics 标签颜色与 gnuplot 中的箱形图中的线条颜色相匹配:
$DATA << EOD
1 1
2 2
3 3
EOD
set linetype 1 linecolor rgb "red"
set linetype 2 linecolor rgb "green"
set linetype 3 linecolor rgb "blue"
set key off
set boxwidth 0.5
set style fill solid 0.5
set xrange [0:4]
set yrange [0:4]
set xtics ("1" 1) textcolor rgb "red"
set xtics add ("2" 2) textcolor rgb "green"
set xtics add ("3" 3) textcolor rgb "blue"
plot $DATA using 1:2:1 with boxes linecolor variable
但它不起作用:
有什么想法吗?谢谢!
我不确定您是否可以将 xtics 单独设置为不同的颜色。因此,以下解决方案将 xtics 设置为空行,并以一定的偏移量绘制 xtics with labels
。缺点是你必须在这里设置y-position:(0)
和offset 0,-1
。希望有更好的解决办法。
代码:
### "xtic labels" in different colors
reset session
$Data << EOD
1 1
2 2
3 3
EOD
set linetype 1 lc "red"
set linetype 2 lc "green"
set linetype 3 lc "blue"
set key off
set boxwidth 0.5
set style fill solid 0.5
set xrange [0:4]
set yrange [0:4]
set format x "\n" # xtic label empty line
plot $Data u 1:2:1 w boxes lc var, \
'' u 1:(0):1:1 w labels tc var offset 0,-1
### end of code
或者,您可以使用相对于图形的偏移量:
plot $Data u 1:2:1 w boxes lc var, \
'' u 1:(0):1:1 w labels tc var offset 0, graph -0.05
结果: