Gnuplot: using a logarithmic axis for a histogram

I have a data file from which I am creating a histogram.

Data file:

-0.1  0  0  JANE
1  1  1  BILL
2  2  1  BILL
1  3  1  BILL
6  4  0  JANE
35 5  0  JANE
9  6  1  BILL
4  7  1  BILL
24 8  1  BILL
28 9  1  BILL
9  10  0  JANE
16 11  1  BILL
4  12  0  JANE
45 13  1  BILL

My gnuplot script:

file='test.txt'
binwidth=10
bin(x,width)=width*floor(x/width)
set boxwidth 1

plot file using (bin($1,binwidth)):(1.0) smooth freq with boxes, \
file using (1+(bin($2,binwidth))):(1.0) smooth freq with boxes

I would like to plot this data in a log scale in y. However, there are some 0 values ​​(because some of the boxes are empty) that cannot be processed set logscale y. I get an error message Warning: empty y range [1:1], adjusting to [0.99:1.01].

According to gnuplot help: "The frequency option makes the data monotonous at x, points with the same value of x are replaced by one point with the summed values ​​of y."

How can I take log10 () of the summed y values ​​computed with smooth freq with boxes?

+4
source share
1 answer

, , , . - 0 1, , . , table, , .

( set yrange [0:11]) :

enter image description here

, , :

file='test.txt'
binwidth=10
bin(x,width)=width*floor(x/width)

set table "data"

plot file using (bin($1,binwidth)):(1.0) smooth freq, \
file using (1+(bin($2,binwidth))):(1.0) smooth freq

unset table

set boxwidth 1
set logscale y
set yrange [0.1:11]

plot "data" index 0 using ($1):($2 == 0 ? 1/0 : $2) with boxes lc 1, \
"data" index 1 using ($1):($2 == 0 ? 1/0 : $2) with boxes lc 2

enter image description here

set table , x = 0. , "< grep -v u data" "data".

+5

Source: https://habr.com/ru/post/1606474/


All Articles