Search code examples
gnuplotscale

Inversed logarithmic scale in gnuplot


When plotting data which are very dense in small ranges of y, the logarithmic scale of gnuplot is the right scale to use.

But what scale to use when the opposite is the case? let's say most y values of different curves are between 90 and 100. In this case I want to use something like a inversed logarithmic scale. I tried a log scale between 0 and 1 but gnuplot wants me to choose a scale greater than 1

How can I achieve this?


Solution

  • You are right, you can use the inverse of the logarithmic function, which is the exponential. But gnuplot only supports logarithmic scales, so you have to do the conversion on your own:

    plot "myData" using 1:(exp($2))
    

    You will also have to handle the axis tics on your own. Either you just set them via a list like

    set ytics ("0" 1.00, "1" 2.72, "2" 7.39, "3" 20.09, "4" 54.60, "5" 148.41)
    

    or you use the link feature for axes of gnuplot 5. The following code uses the y2axis (right y-axis) to plot the data and calculates the tics on the left y-axis from the right one.

    set link y via log(x) inverse exp(x)
    plot "myData" using 1:(exp($2)) axes x1y2
    

    Side note: Always remember that a non-linear axis is hard to understand. Logarithmic scales are common, but everything else not. So, be careful when presenting the data