gpt4 book ai didi

python - 在 python 中的 matplotlib 中的 logscale 上绘制问题

转载 作者:太空宇宙 更新时间:2023-11-03 14:34:57 26 4
gpt4 key购买 nike

我试图在对数刻度上绘制以下数字作为 matplotlib 中的散点图。 x 和 y 轴上的数量都具有非常不同的尺度,其中一个变量具有巨大的动态范围(大致接近 0 到 1200 万),而另一个变量在接近 0 到 2 之间。我认为绘制可能会很好都是对数尺度。

对于两个变量的值的子集,我尝试了以下操作:

fig = plt.figure(figsize=(8, 8))
ax = fig.add_subplot(1, 1, 1)
ax.set_yscale('log')
ax.set_xscale('log')
plt.scatter([1.341, 0.1034, 0.6076, 1.4278, 0.0374],
[0.37, 0.12, 0.22, 0.4, 0.08])

x 轴以对数比例显示,但不显示点——仅显示两个点。知道如何解决这个问题吗?另外,如何使这个对数刻度出现在方轴上,以便可以从散点图中解释两个变量之间的相关性?

谢谢。

最佳答案

我不知道你为什么只得到那两点。对于这种情况,您可以手动调整限制以确保所有点都合适。我跑了:

import matplotlib.pyplot as plt

fig = plt.figure(figsize=(8, 8)) # You were missing the =
ax = fig.add_subplot(1, 1, 1)
ax.set_yscale('log')
ax.set_xscale('log')
plt.scatter([1.341, 0.1034, 0.6076, 1.4278, 0.0374],
[0.37, 0.12, 0.22, 0.4, 0.08])
plt.xlim(0.01, 10) # Fix the x limits to fit all the points
plt.show()

我不确定我是否理解理解什么“另外,我怎样才能使这个对数刻度出现在方轴上,以便可以从散点图中解释两个变量之间的相关性?” 的意思。也许其他人会理解,或者您可以澄清一下?

关于python - 在 python 中的 matplotlib 中的 logscale 上绘制问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2695598/

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