2

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?

Community
  • 1
  • 1
tiom
  • 137
  • 1
  • 2
  • 7
  • Basically `xtics` is doing what you ask him to: displaying tics at the given position. Is an irregular scale what you want? – Arcturus B Jul 02 '15 at 15:44
  • I would say yes. I want evenly spaced tics along the x axis. – tiom Jul 02 '15 at 15:49
  • Your question is a possible duplicate of [Irregular gnuplot x-values](http://stackoverflow.com/questions/13507565/irregular-gnuplot-x-values) – Arcturus B Jul 02 '15 at 15:51
  • @ArcturusB Yes, that question is a possible duplicate. But since the accepted answer is not very clear about which values are used on the x-axis, I'm adding a new answer here, which is hopefully more verbose. – Christoph Jul 02 '15 at 22:03

2 Answers2

3

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

Christoph
  • 47,569
  • 8
  • 87
  • 187
  • Thanks for the in depth answer. I didn't know you had to sort the gnuplot input data. I always assumed gnuplot would just plot them from start to finish. One never stops learning. – tiom Jul 03 '15 at 13:23
  • Gnuplot plots the data according to the given x-value, but in your case the order of the x-values is reversed compared to the row number. – Christoph Jul 03 '15 at 13:32
0

Use

set logscale x

to convert linear x-axis to logarithm x-axis which will normalize gaps to some extent.

Alternatively, change the size of the plot to get more space

set term . . . size 1920, 1080
Shreevardhan
  • 12,233
  • 3
  • 36
  • 50