在gnuplot中使用logscale时,数据会消失

时间:2013-06-25 17:03:14

标签: scale gnuplot histogram

我已经成功地在gnuplot中以正常比例制作了漂亮的直方图,但是当我添加

set logscale y

到我的代码,数据消失。

我发现logscale不能用于我用来制作直方图的函数(如下面的链接所示)。 https://stackoverflow.com/a/2538846/2506689

有人对如何解决此问题有任何建议吗?

1 个答案:

答案 0 :(得分:3)

set table救援!

请注意,我将所有这些输入到交互式提示中并复制/粘贴了我的终端内容。因此,我后面的命令以gnuplot>作为前缀,您不会在脚本中包含这些命令: - )

首先,我使用python生成一些数据......

import numpy as np
np.savetxt('foobar.txt',np.random.random(1000))

这并不难。现在是时候设置gnuplot函数/常量了:

gnuplot> binwidth = 0.05
gnuplot> bin(x,width)=width*floor(x/width)
gnuplot> plot 'foobar.txt' using (bin($1,binwidth)):(1.0) smooth freq with boxes 

好的,它适用于非logscale数据。非常好。让我们使用set table

将数据写入单独的文件中
gnuplot> set table 'foobar.table'
gnuplot> plot 'foobar.txt' using (bin($1,binwidth)):(1.0) smooth freq with boxes
gnuplot> unset table

现在我看看gnuplot写的数据,看看有什么。

gnuplot> !head foobar.table

# Curve 0 of 1, 21 points
# Curve title: "'foobar.txt' using (bin($1,binwidth)):(1.0)"
# x y xlow xhigh type
 0  40  0  0  i
 0.05  57  0.05  0.05  i
 0.1  52  0.1  0.1  i
 0.15  56  0.15  0.15  i
 0.2  49  0.2  0.2  i
 0.25  55  0.25  0.25  i

不幸的是,看起来xlowxhigh总是一样的(可能的错误?)。但那没关系,我们仍然使用恒定的binwidth。我们只是将它用作宽度。

gnuplot> set logscale y
gnuplot> plot 'foobar.table' u 1:2:(binwidth) w boxes

我应该注意到我的箱子位置有点宽松。要真正做到正确,您可能需要将框的中心向右移动一半binwidth

gnuplot> plot 'foobar.table' u ($1+0.5*binwidth):2:(binwidth) w boxes