Search code examples
gnuplotaxisevenly

gnuplot - change scale of axis


I have the following data in cr.dat

0.03 0.0227352
0.02 0.0276084
0.01 0.0386684
0.009 0.0407197
0.008 0.0431688
0.007 0.04612
0.006 0.0497781
0.005 0.0545085
0.004 0.0608376
0.003 0.069918
0.002 0.0844434

And the following plot script

set xtics ( 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01, 0.02, 0.03)
plot "cr.dat" u 1:2 title "cr";

Which produces this image plot cr

Is it possible to remove the large spaces between 0.01, 0.02 and 0.03?

I hoped the set xtics command would plot the given tics evenly along the x axis. But it doesn't.

Update

I tried the in Irregular gnuplot x-values suggested solution with xticlabels but this produces a strange x and y axis.

The new plot script is

set xtics ( 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009, 0.01, 0.02, 0.03)
plot "cr.dat" u xticlabels(1):2 title "cr";

end the result plot cr2

Did I misunderstand something?


Solution

  • To get evenly spaced xtics, you must give evenly space x-values. Each of those x-values can be given a custom label taken from the data file using the xticlabel function. Note, that this function must always be the last you give in the using statement.

    In order to get evenly space x-values, use the row number, which is contained in the pseudo-column 0. So, in order to get the desired plot, use

    plot 'cr.dat' using 0:2:xticlabel(1) title "cr"
    

    That uses the row number as x-value, the values from the second column as y-value, and the value in the first column as xtic label.

    If you want the values to be sorted in ascending order, you have several choices:

    1. Sort the data file.
    2. Sort the data file on the fly (works fine using the Unix command line tool sort:

      plot '< sort cr.dat' using 0:2:xticlabel(1)
      
    3. Use the negative value of the row number, which effectively gives you a reversed x-axis:

      plot 'cr.dat' using (-$0):2:xticlabel(1)
      

    The result of the latter command is

    enter image description here