How to tweak automatic-tics-number in gnuplot?

后端 未结 2 470
温柔的废话
温柔的废话 2021-01-22 20:18

It is helpful that gnuplot automatically picks up reasonably good x/y-range, and x/y-tics number (say approx 5 as attached figure).

However, I sometimes would like to in

2条回答
  •  情歌与酒
    2021-01-22 20:34

    OK, now I see your point. Especially in multiplots or when the graphs are getting small relative to the size of the tic labels there are too many tics. Find below a workaround which seems to work in the demonstrated cases. If it works nicely all the time you need to test. The disadvantage is that you have to plot first to a dummy table in order to get gnuplot's suggestion about the minimum and maximum tics which gnuplot puts into the GPVAL_... variables and then replot again.

    In the graph below the first row is gnuplot auto-tic, the second row the attempt for semi-auto-approximate-tic. Maybe it is a starting point for further tweaking.

    ### semi-automatic tics
    reset session
    
    Round(n) = gprintf("%.0e",n)
    # or alternatively with less approximate tics: 
    # Round(n) = gprintf("%.0e",n) + sgn(n)*10**gprintf("%T",n)
    SemiAutoTicX(ApproxTicN) = Round((GPVAL_X_MAX - GPVAL_X_MIN)/ApproxTicN)
    SemiAutoTicY(ApproxTicN) = Round((GPVAL_Y_MAX - GPVAL_Y_MIN)/ApproxTicN)
    
    set multiplot layout 2,3 rowsfirst
    
    ### with gnuplot auto-tic
    set xrange [-10:10]
    plot x
    
    set xrange [-100:100]
    plot x**2
    
    set xrange [-90:90]
    plot x
    
    ### now with semi-auto tics
    set style line 1 lc rgb "red"
    set xrange [-10:10]
    set table $Dummy
        plot x ls 1
    unset table
    set xtics SemiAutoTicX(5)
    set ytics SemiAutoTicY(5)
    replot
    
    set xrange [-100:100]
    set table $Dummy
        plot x**2 ls 1
    unset table
    set xtics SemiAutoTicX(5)
    set ytics SemiAutoTicY(5)
    replot
    
    set xrange [-90:90]
    set table $Dummy
        plot x ls 1
    unset table
    set xtics SemiAutoTicX(5)
    set ytics SemiAutoTicY(5)
    replot
    
    unset multiplot
    

提交回复
热议问题