gpt4 book ai didi

python - Matplotlib 热图自动旋转图像

转载 作者:行者123 更新时间:2023-12-01 04:25:14 25 4
gpt4 key购买 nike

我有一系列坐标数据(纬度和经度)。

我设法从点的散点图中创建了一个漂亮的热图,但该图似乎向右旋转了 90 度......我不明白为什么会发生这种情况。

import numpy as np
import numpy.random
import matplotlib.pyplot as plt
plt.style.use('ggplot')

x = coords.longtitude
y = coords.latitude

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

plt.imshow(heatmap, extent=extent)
plt.show(p)

这是结果: enter image description here

敏锐的人可以看到荷兰的图像......只是旋转。

最佳答案

正如 Jblasco 所建议的,这是一个带有虚假数据的最小工作示例。

import numpy as np
import numpy.random
import matplotlib.pyplot as plt
p = plt.figure()
plt.style.use('ggplot')

np.random.seed(0)
x = np.random.rand(50)
y = np.random.rand(50)

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

plt.imshow(heatmap, extent=extent)
plt.show(p)

这两张图片都带有 np.histogram2d(x, y, bins=30)np.histogram2d(y, x, bins=30)

这当然会旋转图像(实际上,它会转置图像)。因此我也不明白你的问题。 enter image description here enter image description here

关于python - Matplotlib 热图自动旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33229872/

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