簡體   English   中英

seaborn 熱圖 y 軸逆序

[英]seaborn heatmap y-axis reverse order

看看在 seaborn heatmap 文檔中找到的這個熱圖。

現在 y 軸從底部的 9 開始,到頂部的 0 結束。 有沒有辦法扭轉這種局面,即從底部的 0 開始,頂部的 9 結束?

看起來ax.invert_yaxis()解決了它。

按照您從中獲得圖形的示例:

import numpy as np; np.random.seed(0)
import seaborn as sns; sns.set()
uniform_data = np.random.rand(10, 12)
ax = sns.heatmap(uniform_data)
ax.invert_yaxis()

給出: 在此處輸入圖片說明

如果您像我一樣使用“十六進制” jointplot()作為熱圖,那么您可以這樣做:

import matplotlib.pyplot as plt
import numpy
import seaborn

x = numpy.arange(10)
y = x**2

g = seaborn.jointplot(x, y, kind='hex')
g.fig.axes[0].invert_yaxis()

plt.show()

在此處輸入圖片說明

我找到了一種更簡單的方法來設置軸順序,使用選項ylimxlim 在以下示例中,我繪制了 H,一個二維矩陣 (NX x NY),更改了軸順序:

import matplotlib.pyplot as plt
import seaborn as sns

NX=10
NY=20
H = np.random.rand(NY, NX)
sns.heatmap(H, xticklabels=True, yticklabels=True, annot = True)
plt.ylim(0,NY)
plt.xlim(0,NX)
plt.show()

在此處輸入圖片說明

NX=10
NY=20
H = np.random.rand(NY, NX)
sns.heatmap(H, xticklabels=True, yticklabels=True, annot = True)
plt.ylim(NY,0)
plt.xlim(NX,0)
plt.show()

在此處輸入圖片說明

暫無
暫無

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

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