我有一个要从中创建直方图的数据文件。
数据文件为:
-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脚本是:
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的对数刻度上。但是,存在一些无法使用的0值(因为某些垃圾箱为空)set logscale y
。我得到了错误Warning: empty y range [1:1], adjusting to [0.99:1.01]
。
根据gnuplot的帮助,“频率选项使数据在x中单调;具有相同x值的点将替换为具有y值总和的单个点。”
如何取由计算得出的y值的对数log10()smooth freq with boxes
?
您至少可以做两件事。一种方法是使用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
set table
有时会在绘图中生成一些不良点,您可以在x = 0处看到这些点。要摆脱它们,可以使用"< grep -v u data"
代替"data"
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句