I have a data file that I am creating a histogram from.
我有一个正在创建直方图的数据文件。
The data file is :
数据文件为:
-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 is :
我的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
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]
.
我想用y中的logscale来绘制这个数据,但是有一些0值(因为有些箱子是空的)不能通过设置logscale y来处理,我得到了错误警告:空y范围[1:1],调整到[0.91:1.01]。
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."
根据gnuplot的帮助,“频率选项使x中的数据单调;同一x值的点被一个具有求和值的单点所取代。
How can I take the log10() of the summed y-values computed by smooth freq with boxes
?
如何使用由光滑的freq和box计算的汇总y值的log10() ?
1 个解决方案
#1
5
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.
你至少可以做两件事。一种是在0和1之间用一个线性轴,然后用对数轴,就像这个答案中解释的那样。另一种方法是先绘制到一个表,然后设置日志标度,忽略值为0的点。
With a normal linear axis and your code (plus set yrange [0:11]
) your data looks:
使用正线轴和您的代码(加上set yrange[0:11]),您的数据看起来是:
Now lets plot to a table, then set the log scale, then plot ignoring the zero values:
现在让我们绘制到一个表,然后设置日志标度,然后绘制忽略0的值:
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
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"
.
set表有时会在图中生成一些不需要的点,在x = 0处可以看到。要删除它们,可以使用“< grep -v u data”而不是“data”。
#1
5
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.
你至少可以做两件事。一种是在0和1之间用一个线性轴,然后用对数轴,就像这个答案中解释的那样。另一种方法是先绘制到一个表,然后设置日志标度,忽略值为0的点。
With a normal linear axis and your code (plus set yrange [0:11]
) your data looks:
使用正线轴和您的代码(加上set yrange[0:11]),您的数据看起来是:
Now lets plot to a table, then set the log scale, then plot ignoring the zero values:
现在让我们绘制到一个表,然后设置日志标度,然后绘制忽略0的值:
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
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"
.
set表有时会在图中生成一些不需要的点,在x = 0处可以看到。要删除它们,可以使用“< grep -v u data”而不是“data”。