Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logarithmic y with zero in GnuPlot

Tags:

gnuplot

My goal is to display 0 values on a logarithmic scale a little bit under 1.

I managed to plot my own simple histogram (with boxes) with logarithmic Y scale. My Y values are non-negative integers up to 25000. I cannot differentiate the 0 and 1 values as the Y scale begins at 1. Which is mathematically correct, but I want to hack a zero just under the one.

If I were to write a program that plots my graph, I would add 1 to all of my data, and remove 1 from the Y labels. Is there any tricks that would do something like that for me?

like image 887
Notinlist Avatar asked Jan 10 '23 11:01

Notinlist


2 Answers

gnuplot> set xrange [0:2]
gnuplot> set log y
gnuplot> set yrange [0.1:100]
gnuplot> set ytics ("0" 0.1, "1" 1, "10" 10)
gnuplot> plot cosh(x)
gnuplot> 
like image 83
gboffi Avatar answered Jan 31 '23 10:01

gboffi


I think the best option would be to plot your histogram using a modified function:

plot 'data' using 1:($2 < 1 ? $2 : log10($2)+1) with boxes

The above command plots the log10()+1 of your data if it is above or equal to 1, otherwise it plots simply your data. Then, you can modify your y axis so that it's linear between 0 and 1 and logarithmic between 1 and the highest value:

ymax = 10000
set yrange [0:log10(ymax)]
unset ytics
set ytics 1 add ("0" 0, "1" 1)
set for [i=2:log10(ymax)] ytics add (sprintf("%g",10**(i-1)) i) # Add major tics
set for [i=1:log10(ymax)] for [j=2:9] ytics add ("" log10(10**i*j) 1) # Add minor tics
set for [j=1:9] ytics add ("" j/10. 1) # Add minor tics between 0 and 1
plot 'data' using 1:($2 < 1 ? $2 : log10($2)+1) with boxes

The 1 after the tic position is to adjust the minor tics' length (thanks to @Christoph). Anyway, this looks like the following figure for a test case x^2, where you can see how the y axis is linear up to 1 and logarithmic beyond:

enter image description here

like image 27
Miguel Avatar answered Jan 31 '23 11:01

Miguel