1

I am trying to plot a figure using GNUPLOT, but I want to have a hierarchical x-axis, it should be six tick points in x-axis with first level of label in x-axis being 32,64,128,32,64 and 128. Here the first 32, 64 and 128 should be grouped as stencil and the second 32, 64 and 128 should be grouped as diamond in second level of label . Current i am doing this as stencil-32, stencil-64, stencil-128, diamond-32, diamond-64 and diamond-128. Is there a way to change it into hierarchical axis lableling?

tmdavison
  • 64,360
  • 12
  • 187
  • 165
Sap BH
  • 71
  • 1
  • 6
  • Maybe. But I am not familiar with the terms you use to describe what you want. Could you provide an image or a link to an image showing an example? – Ethan Sep 14 '20 at 04:30

1 Answers1

2

If I correctly understand what you mean with hierachical axis the following code could be one possible way of many others. You could simply increase the bottom margin and add some labels. But if you want to have some axis, using multiplot might be an option. You need to make sure that the margins are identical (especially the left margin).

Code:

### 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

Result:

enter image description here

theozh
  • 22,244
  • 5
  • 28
  • 72