Search code examples
colorsgnuplotaxis

Gnuplot - Show different tick color at 0


I want to display different tick color at 0. For eg, the image below I want to set tick color at 0 in y axis to blue. Can it possible? Thanks.

enter image description here


Solution

  • I am not aware of a direct Gnuplot feature that would allow to do this, nevertheless one might use some workaround.

    For example, one could unset the tic at position zero and place there a custom label instead:

    set terminal pngcairo enhanced font ",14"
    set output 'fig.png'
    
    set multiplot
    
    xMin = 0
    xMax = 2*pi
    
    set xr [xMin:xMax]
    set yr [-1:1]
    
    set xtics out nomirror
    set ytics out nomirror 
    set ytics add ("" 0)
    
    set label "0" at xMin,0 offset char -1.5,0 right textcolor rgb "blue"
    
    plot sin(x) w l t 'sin(x)'
    

    Alternatively, one could use a technique based on multiplot, where the strategy is basically first to plot the function/data of interest without the tic at position zero and then overlay this with a plot which is empty but for the customized tic at position zero:

    set terminal pngcairo enhanced font ",14"
    set output 'fig.png'
    
    set xr [0:2*pi]
    set yr [-1:1]
    
    set xtics out nomirror
    set ytics out nomirror 
    set ytics add ("" 0)
    
    plot sin(x) w l t 'sin(x)'
    
    set lmargin at screen GPVAL_TERM_SCALE * GPVAL_TERM_XMIN / (1.*GPVAL_TERM_XSIZE)
    set rmargin at screen GPVAL_TERM_SCALE * GPVAL_TERM_XMAX / (1.*GPVAL_TERM_XSIZE)
    set bmargin at screen GPVAL_TERM_SCALE * GPVAL_TERM_YMIN / (1.*GPVAL_TERM_YSIZE)
    set tmargin at screen GPVAL_TERM_SCALE * GPVAL_TERM_YMAX / (1.*GPVAL_TERM_YSIZE)
    
    unset border
    unset key
    unset xtics
    unset ytics
    
    set ytics ("0" 0) out nomirror textcolor rgb 'blue'
    
    plot 1/0
    

    Both approaches result in a nearly identical plot: enter image description here