gpt4 book ai didi

python - 如何在 Matplotlib 中为 hist2d 使用对数刻度和对数箱?

转载 作者:太空宇宙 更新时间:2023-11-04 04:25:03 25 4
gpt4 key购买 nike

以下最小示例显示了我的问题:

import matplotlib.pyplot as plt
import numpy as np

X = np.random.normal(30, 10, 1000)
Y = np.random.normal(200, 500, 1000)

x_space = np.linspace(0, 60, 6)
print('x_space:', x_space)

y_space = np.logspace(np.log10(1.0), np.log10(1000.0), 30)
print('y_space:', y_space)

plt.hist2d(X, Y, bins=(x_space, y_space))
plt.yscale('log')
plt.show()

我希望图表中的 bin 大小相同,因为 y 轴上的对数刻度和 y 的对数空间应该相等。然而,情况似乎并非如此。

enter image description here

生成的 bin 的文本输出对我来说看起来不错:

x_space: [ 0. 12. 24. 36. 48. 60.]
y_space: [ 1. 1.268961 1.61026203 2.04335972 2.5929438
3.29034456 4.17531894 5.29831691 6.72335754 8.53167852
10.82636734 13.73823796 17.43328822 22.12216291 28.07216204
35.6224789 45.20353656 57.3615251 72.78953844 92.36708572
117.21022975 148.73521073 188.73918221 239.502662 303.91953823
385.66204212 489.39009185 621.01694189 788.04628157 1000. ]

但它与绘制的内容不对应。

我做错了什么,或者这可能是库中的错误?

(我使用的是 Matplotlib 版本 2.2.2。)

最佳答案

这似乎是版本 2.2.2 中的错误。在 3.02 版中,代码的输出与预期的一样:

result of the OPs code with matplotlib version 3.02

关于python - 如何在 Matplotlib 中为 hist2d 使用对数刻度和对数箱?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53665027/

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