【发布时间】:2020-09-24 11:45:39
【问题描述】:
我正在尝试使用具有相同 y 轴的子图并排打印两个热图。我正在使用 seaborn 绘制它们。
这是我的两个热图的代码。数据是具有 45 列的大型数据框的一部分。我为下面的两个热图分别使用了 4 列。
sns.heatmap(genre_top10.iloc[:,[13,16,19,22]], annot = True, fmt = '.0f', linewidths=.5)
plt.show()
sns.heatmap(genre_top10.iloc[:,[14,17,20,23]], annot = True, fmt = '.0f', linewidths=.5)
plt.show()
但无法弄清楚如何将它们打印为具有共享 y 轴的子图。请帮忙。
【问题讨论】:
-
在绘图前创建一个图形,其中有 2 个子图和共享 y 轴。然后将轴作为参数传递给 seaborn 热图绘图函数
-
fig, axes = plt.subplots(ncols=2, sharey=True)然后是sns.heatmap(...., ax=axes[0])和sns.heatmap(...., ax=axes[1])
标签: python matplotlib seaborn heatmap subplot