gnuplot 中对数刻度的直方图
我必须使用 gnuplot 在两个轴上以对数刻度绘制直方图。我需要 log10 中的 bin 等距。在 y 轴上使用对数刻度不是问题。主要问题是在 x 轴上创建 bin。例如,在 log10 中使用 10 个 bin,第一个 bin 将为 [1]、[2]、[3]....[10 - 19][20 - 29].....[100 190] 等等。我在网上搜索过但找不到任何实用的解决方案。如果在 gnuplot 中实现它太复杂,您可以建议其他软件/语言来实现吗?
正如有人问的,我会更具体地解释我需要做什么。我有一个(巨大的)列表,如下所示:
1 14000000
2 7000000
3 6500000
.
.
.
.
6600 1
8900 1
15000 1
19000 1
例如,它显示 1400 万个 ip 地址已发送 1 个数据包,700 万个 2 个数据包...1 个 ip 地址已发送 6600 个数据包,...,1 个 ip 地址已发送 19000 个数据包。正如您所看到的,两个轴上的值都非常高,因此如果没有对数刻度,我无法绘制它。
我尝试的第一件事是绘制这个列表,因为我需要快速完成它,就像使用 gnuplot 在两个轴上使用框设置对数刻度一样。结果可以理解,但不太恰当。事实上,x 轴右侧的方框变得越来越细,因为显然 10-100 中的点比 1-10 中的点更多!所以第二个十年之后它变得一团糟。
I have to plot an histogram in logarithmic scale on both axis using gnuplot. I need bins to be equally spaced in log10. Using a logarithmic scale on the y axis isn't a problem. The main problem is creating the bin on the x axis. For example, using 10 bins in log10, first bins will be [1],[2],[3]....[10 - 19][20 - 29].....[100 190] and so on. I've searched on the net but I couldn't find any practical solution. If realizing it in gnuplot is too much complicated could you suggest some other software/language to do it?
As someone asked I will explain more specifically what I need to do. I have a (huge) list like this:
1 14000000
2 7000000
3 6500000
.
.
.
.
6600 1
8900 1
15000 1
19000 1
It shows, for example, that 14 milions of ip addresses have sent 1 packet, 7 milions 2 packets.... 1 ip address have sent 6600 packets, ... , 1 ip address have sent 19000 packets. As you can see the values on both axes are pretty high so I cannot plot it without a logarithmic scale.
The first things I tried because I needed to do it fast was plotting this list as it is with gnuplot setting logscale on both axes using boxes. The result is understandable but not too appropriate. In fact, the boxes became more and more thin going right on the x axis because, obviously, there are more points in 10-100 than in 1-10! So it became a real mess after the second decade.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我尝试绘制一个直方图,其中两个轴均以对数缩放,并通过错误
X 上的对数比例与直方图不兼容
进行 gnuplot。因此,gnuplot 似乎不支持带有直方图的 x 轴上的对数刻度。
I tried plotting a histogram with both axis being logarithmically scaled and gnuplot through the error
Log scale on X is incompatible with histogram plots
.So it appears that gnuplot does not support a log scale on the x axis with histograms.
与本线程中的其他帖子相反,在 GnuPlot 中以对数比例进行绘图是完全可行的。
可以使用命令
set logscale
在 GnuPlot 中设置对数刻度。然后,假设我们有一个在 x 轴和 y 轴上都有正值(严格非零)的文件。例如,以下文件是有效文件:
设置双对数刻度后,可以使用以下命令绘制该文件:
plot "file.txt" w p
其中 file.txt 是文件的名称。该命令将生成带有点的输出。另请注意,绘制方框很棘手,可能不推荐。首先必须使用
set xrange [1:4]
形式的命令限制 x 范围,然后才用方框绘制。否则,当 x 范围未定义时,将返回错误。我假设在这种情况下,绘图需要(对于适当的 x 值)一些框的大小为 log(0),这当然是未定义的,因此返回错误。希望它很清楚,也对其他人有帮助。
Plotting in log-log scale in GnuPlot is perfectly doable contrary to the other post in this thread.
One can set the log-log scale in GnuPlot with the command
set logscale
.Then, the assumption is that we have a file with positive (strictly non-zero) values both in the x-axis, as well as the y-axis. For example, the following file is a valid file:
After setting the log-log scale one can plot the file with the command:
plot "file.txt" w p
where of course file.txt is the name of the file. This command will generate the output with points.Note also that plotting boxes is tricky and is probably not recommended. One first has to restrict the x-range with a command of the form
set xrange [1:4]
and only then plot with boxes. Otherwise, when the x-range is undefined an error is returned. I am assuming that in this case plot requires (for appropriate x-values) some boxes to have size log(0), which of course is undefined and hence the error is returned.Hope it is clear and it will also help others.
您是否尝试过 Matplotlib 和 Python? Matplotlib 是一个非常好的绘图库,当与 Python 的简单语法一起使用时,您可以非常轻松地绘制图形:
Have you tried Matplotlib with Python? Matplotlib is a really nice plotting library and when used with Python's simple syntax, you can plot things quite easily: