Genschman
Genschman

Reputation: 187

Gnuplot: How to specify label format when using xtic

In my file.dat the values are in scientific format like this:

0.00000000E+00    0.00000000E+00  
0.70000000E+01  -0.27957985E+01  
0.26000000E+02  -0.85755510E+01  
...  

I would like to use the values directly as x- and y-labels in the plot, but in a decimal format. I have this in my plot script:

set format x '%.1f'
set xtics format "%.1f" rotate by +40 right
plot"file.dat" u 1:2:xtic(1):ytic(2) t 'xxx' w l ls 1 lc rgb "blue" lw 2

But the labels appear in scientific format (like in the "file.dat") not in the decimal format. Why?

Upvotes: 2

Views: 1421

Answers (1)

Miguel
Miguel

Reputation: 7627

This is happening because by using set format x you are changing the format of the x labels in the standard usage. When you pass xtic() you are telling gnuplot to override the standard value and use the supplied value as label instead. To change the format in this case, you need to pass the format specifier to xtic(). This should work for you:

plot "file.dat" u 1:2:xtic(sprintf("%.1f", $1)):ytic(sprintf("%.1f", $2))

Upvotes: 1

Related Questions