gnuplot:使用对数轴作为直方图

irr*_*rom 4 gnuplot histogram

我有一个数据文件,我正在创建一个直方图.

数据文件是:

-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
Run Code Online (Sandbox Code Playgroud)

我的gnuplot脚本是:

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
Run Code Online (Sandbox Code Playgroud)

我想在y中的logscale上绘制这些数据.但是有一些无法处理的值(因为某些箱是空的)set logscale y.我收到了错误Warning: empty y range [1:1], adjusting to [0.99:1.01].

根据gnuplot的帮助,"频率选项使数据在x中单调;具有相同x值的点被具有相加y值的单个点替换."

如何获取由smooth freq with boxes?计算的求和y值的log10()?

Mig*_*uel 5

你可以做至少两件事.一种是使用介于0和1之间的线性轴,然后使用对数的线性轴,如本答案中所述.另一个是绘制table第一个,然后设置对数刻度忽略零值的点.

使用正常的线性轴和您的代码(加号set yrange [0:11]),您的数据看起来如下:

在此输入图像描述

现在让我们绘制一个表,然后设置对数刻度,然后绘制忽略零值:

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
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

set table有时会在绘图中生成一些不需要的点,你可以在x = 0处看到.要摆脱它们,你可以使用"< grep -v u data"而不是"data".