gpt4 book ai didi

scale - 在 gnuplot 中使用 logscale 时数据消失

转载 作者:行者123 更新时间:2023-12-04 04:52:00 26 4
gpt4 key购买 nike

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

set logscale y

到我的代码,数据消失。

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

有没有人对如何解决这个问题有任何建议?

最佳答案

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

好的,它适用于非对数数据。那很好。让我们使用 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

关于scale - 在 gnuplot 中使用 logscale 时数据消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17303323/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com