GNUPLOT 中的层次轴

Hierarchial Axis in GNUPLOT

我正在尝试使用 GNUPLOT 绘制图形,但我想要一个分层的 x 轴,它应该是 x 轴上的六个刻度点,x 轴上的第一级标签是 32,64,128, 32,64 和 128。这里第一个 32、64 和 128 应该分组为模板,第二个 32、64 和 128 应该分组为第二级标签中的菱形。目前我正在这样做,如 stencil-32、stencil-64、stencil-128、diamond-32、diamond-64 和 diamond-128。有没有办法将其更改为分层轴标签?

如果我正确理解了您对分层轴的含义,则以下代码可能是许多其他方法中的一种。 您可以简单地增加底部边距并添加一些标签。但是如果你想要一些轴,使用 multiplot 可能是一个选择。您需要确保边距相同(尤其是左边距)。

代码:

### hierarchical axis
reset session

$Data <<EOD
1    stencil   32   0.3
2    stencil   64   0.4
3    stencil  128   0.5
4    diamond   32   0.6
5    diamond   64   0.7
6    diamond  128   0.8
EOD

myBottomMargin = 0.12
myColor(col) = strcol(col) eq "stencil" ? 0xff0000 : 0x0000ff

set multiplot

    set origin 0, myBottomMargin
    set size 1, 1-myBottomMargin
    set lmargin screen 0.1
    set style fill solid 1.0 
    set boxwidth 0.8
    set yrange [0:1]
    plot $Data u 0:4:(myColor(2)):xtic(3) w boxes lc rgb var notitle
    
    set origin 0, 0
    set size 1, myBottomMargin
    set border 1    # only bottom border
    set xtics nomirror
    set xrange [0.5:2.5]
    set mxtics 2
    set xtics 1 add ("stencil" 1, "diamond" 2) scale 0,1
    set yrange [0:1]
    unset ytics
    unset key
    plot NaN  # dummy plot just for the extra axis
    
unset multiplot
### end of code

结果: