Python seaborn 热图 y 轴逆序
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34232073/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
seaborn heatmap y-axis reverse order
提问by john kals
Have a look at thisheatmap found in the seaborn heatmap documentation.
看看在 seaborn heatmap 文档中找到的这个热图。
Right now the y-axis starts with 9 at the bottom, and ends with 0 on top. Is there a way to turn this around, i.e. start with 0 at bottom and end with 9 at the top?
现在 y 轴从底部的 9 开始,到顶部的 0 结束。有没有办法扭转这种局面,即从底部的 0 开始,顶部的 9 结束?
回答by user3412205
回答by ryanjdillon
回答by terence hill
I found a simpler method to set the axes order, using the options ylimand xlim. In the following examples I plot H, a 2d matrix (NX x NY), changing the axes order:
我找到了一种更简单的方法来设置轴顺序,使用选项ylim和xlim。在以下示例中,我绘制了 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()