簡體   English   中英

Matplotlib熱圖自動旋轉圖像

[英]Matplotlib heatmap rotates image automatically

我有一系列坐標數據(緯度和經度)。

我設法根據散點圖創建了一個不錯的熱圖,但是該圖似乎向右旋轉了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)

結果如下: 在此處輸入圖片說明

具有感知力的人可以看到荷蘭的圖像……只是旋轉了。

正如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)

當然可以旋轉圖像(實際上,它可以對圖像進行轉置)。 因此,我也不理解您的問題。 在此處輸入圖片說明 在此處輸入圖片說明

來自numpy.histogram2D的文檔

樣本x和y的二維直方圖。 x中的值沿第一維直方圖,y中的值沿第二維直方圖。

與matplotlib所做的恰好相反,第一個軸是垂直軸。 我建議您在創建熱圖時轉置x和y。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM