Gnuplot how to lower the number of tics in x axis

前端 未结 4 399
故里飘歌
故里飘歌 2020-12-06 18:42

The figure has too many xtics and ytics. Can I have half of them?

I know I can manually set tics in a way similar to this:

set xtics (1,2,4,8,16,32,6         


        
相关标签:
4条回答
  • 2020-12-06 19:14

    I had a similar problem that I wanted to handle a little more generically in case the data changes while still using somewhat round looking numbers. Therefore I made a helper function:

    endsinone(n) = strstrt(gprintf("%g", incrguess), "1")
    getincr(range, maxincr, guess) = range/guess < maxincr ? guess : \
        (endsinone(guess) ? getincr(range, maxincr, 5*guess) : getincr(range, maxincr, 2*guess))
    

    Then I just have to pass in the range for the axis, the most increments I want on it, and a very lower bound guess about what I would expect the smallest possible increment to be. To keep the rounded looking numbers my functions assume the guess is expressible in the form 1eN or 5eN for some value N. Ie (50 is good, so is 0.0000001, 505 is not). With this function you just have to do something like

    set xtics getincr(STATS_max, 6, 1e-9)
    

    will return an incr of less than 6 tics, and there should be several of them assuming STATS_MAX > 1e-9.

    0 讨论(0)
  • 2020-12-06 19:28

    There is no option in gnuplot to explicitly set the number of tics you want on an axis and have gnuplot decide where to put them. (I really wish there were.)

    One option you have is to use the stats command (in gnuplot 4.6+) to find out the range of the data:

    ntics = 4
    
    stats 'data.dat' using 1 name 'x' nooutput
    stats 'data.dat' using 2 name 'y' nooutput
    stats 'data.dat' using 3 name 'z' nooutput
    
    set xtics x_max/ntics
    set ytics y_max/ntics
    set ztics z_max/ntics
    

    You might have to adjust whether you want the tics to be at integer values or not, but that is the general idea.

    0 讨论(0)
  • 2020-12-06 19:29

    You can just use for example

     set xtic 10 
    

    and it will display the tics on x-axis each 10.

    0 讨论(0)
  • 2020-12-06 19:35

    There are different ways to set the number of tics depending on what exactly you want to do. For a fixed segment of length 2, starting at zero and ending at 32:

    set xrange [0:32]
    set xtics 0,2,32
    plot sin(x)
    

    enter image description here

    If you want an exponential increment, try the following

    set xrange [0:32]
    set for [i=0:5] xtics (0,2**i)
    plot sin(x)
    

    enter image description here

    Or you can use a logarithmic scale (in base 2 in this case):

    set xrange [1:32]
    set logscale x 2
    plot sin(x)
    

    enter image description here

    0 讨论(0)
提交回复
热议问题