gnuplot:对数轴使用直方图 [英] gnuplot : using a logarithmic axis for a histogram

查看:90
本文介绍了gnuplot:对数轴使用直方图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要从中创建直方图的数据文件.

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

数据文件是:

-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

我的gnuplot脚本是:

My gnuplot script is :

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

我想将此数据绘制在y的对数刻度上.但是,有些set logscale y无法处理某些0值(因为某些垃圾箱为空).我收到错误Warning: empty y range [1:1], adjusting to [0.99:1.01].

I would like to plot this data on a logscale in y. However there are some 0 values (because some of the bins are empty) that cannot be handled by set logscale y. I get the error Warning: empty y range [1:1], adjusting to [0.99:1.01].

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

According to gnuplot's help, "The frequency option makes the data monotonic in x; points with the same x-value are replaced by a single point having the summed y-values."

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

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

推荐答案

您至少可以做两件事.一种方法是使用0到1之间的线性轴,然后按照本

There are at least two things that you could do. One is to use a linear axis between 0 and 1 and then use the logarithmic one as explained in this answer. The other one is to plot to a table first and then set the log scale ignoring the points with zero value.

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

With a normal linear axis and your code (plus set yrange [0:11]) your data looks:

现在让我们绘制到表格中,然后设置对数刻度,然后忽略零值进行绘制:

Now lets plot to a table, then set the log scale, then plot ignoring the zero values:

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

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

set table sometimes generates some undesirable points in the plot, which you can see at x = 0. To get rid of them you can use "< grep -v u data" instead of "data".

这篇关于gnuplot:对数轴使用直方图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆