gnuplot plot scientific notation (exponential value on x-axis)

I'm new using gnuplot, today I learned a lot on stackoverflow for a problem that I had with a plot, but now for my research I need to do another one like the following image:

enter image description here

The data are of the same tipe, I collected them and isolate only the column that I need in a file.dat, and a sample is the following:

5.38e-51 1
2.75e-81 1
5.3e-67 1
8.71e-170 4
3.62e-59 3
2.98e-52 2
3.2e-31 1
2.98e-54 2
3.85e-29 2
5.38e-57 1
3.2e-33 2
2.75e-88 1
3.2e-34 1
9.89e-37 1
5.38e-59 2
3.2e-35 2
1.68e-168 1
1.81e-101 1
9.89e-39 1
2.98e-59 2
3.2e-39 1
1.07e-110 3
1.07e-111 2
1.81e-107 2
2.82e-40 4
2.6e-108 1
1.07e-115 1

My problem is that I would like on the x-axis that my x is the exponent, as 1E-x. I tried using set format set format x '%.0f'.sprintf('e%d') but it doesn't work. How can I do that? thank you.


Solution 1:

If you want to plot values which span many order of magnitudes you either plot it on logarithmic scale or take log10() of your values and plot them in linear scale. From your description without code and details, I'm guessing that you have the data you've shown and want to create a histogram and display the negative log10 value on the x-axis.

NB: In your earlier data you had also 0.0, which will mess-up the smooth freq option together with the logarithmic bins. Note that set datafile missing "0.0" will only exclude 0.0 as text, i.e. 0, 0.00, or 0e-10 will not be excluded. So, make sure you don't have zeros in your data, this will not work with logarithmic scale.

Code:

### plot histogram with logarithmic bins
reset session

$Data <<EOD
5.38e-51   1
2.75e-81   1
5.3e-67    1
8.71e-170  4
3.62e-59   3
2.98e-52   2
3.2e-31    1
2.98e-54   2
3.85e-29   2
5.38e-57   1
3.2e-33    2
2.75e-88   1
3.2e-34    1
9.89e-37   1
5.38e-59   2
3.2e-35    2
1.68e-168  1
1.81e-101  1
9.89e-39   1
2.98e-59   2
3.2e-39    1
1.07e-110  3
1.07e-111  2
1.81e-107  2
2.82e-40   4
2.6e-108   1
1.07e-115  1
EOD

set xlabel "-log_{10}(x)"
set xrange[-15:200]
set xtics 10 out
set ylabel "Sequences"
set yrange [0:]
set key noautotitle

# Histogram with logarithmic bins
BinWidth = 10 
Bin(x)   = floor(-log10(x)/BinWidth)*BinWidth + BinWidth*0.5

set boxwidth BinWidth
set style fill solid 0.3
set offset 1,1,1,0
set grid x,y

set datafile missing "0.0"    # exclude zero, otherwise it will mess up "smooth freq"

plot $Data u (Bin($1)):2 smooth freq with boxes lc "red"
### end of code

Result:

enter image description here