繁体   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