[英]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)
樣本x和y的二維直方圖。 x中的值沿第一維直方圖,y中的值沿第二維直方圖。
與matplotlib所做的恰好相反,第一個軸是垂直軸。 我建議您在創建熱圖時轉置x和y。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.