gpt4 book ai didi

python - 如何在 Python 中放大图像轴?

转载 作者:行者123 更新时间:2023-11-28 16:37:23 25 4
gpt4 key购买 nike

我正在尝试创建两个变量的热图。代码的问题部分看起来像这样:

import numpy as np
import matplotlib.pyplot as plt

x = [0.99, 0.98, 0.99, 1, 1]
y = [1, 1, 0.5, 0.8, 1]

heatmap, xedges, yedges = np.histogram2d(x, y, bins=50)
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]

plt.clf()
plt.imshow(heatmap, extent=extent, origin="lower")
plt.show()

这里我只使用了我想要绘制的数据的前几行。两个变量中的一个非常聚集在 0.95-1 附近,而另一个运行得更自由(甚至可以达到数十万)。问题是输出如下图所示。

enter image description here

我想加宽 x 轴,以便可以更详细地查看正在绘制的区域。我试过使用 axis() 命令,但它只是添加了空格(即没有数据的空格)。有办法吗?

最佳答案

如果您要使用 extent 请注意

extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]

给出 extent=[0.99,1,1,1]。您应该将其更改为:

extent = [min(xedges), max(xedges), min(yedges), max(yedges)]

您可能还会发现 plt.axis("equal") 很有用。 imshow默认情况下也会进行插值,这通常不是您想要的。参数 interpolation="none" 停止了这个。这个相关问题可能会解决您的更多问题:

figure of imshow() is too small

关于python - 如何在 Python 中放大图像轴?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24174747/

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