我有下一个代码:
heatmap = sns.clustermap(corrMatrix, row_colors=row_colors,
#metric='correlation',
#method='single',
xticklabels=True, yticklabels=True,
cmap='coolwarm', annot=False, fmt=".2f",
#annot_kws={'size':6}, square=False,
dendrogram_ratio=(.1, .2),
cbar_pos=(1, .2, .03, .4))
loc, labels = plt.xticks()
heatmap.set_xticklabels(labels, rotation=90)
heatmap.set_yticklabels(labels, rotation=0)
bottom, top = heatmap.get_ylim()
heatmap.set_ylim(bottom + 0.5, top -0.5)
heatmap.savefig(r'similarity' + '.svg', format='svg', dpi=600, bbox_inches = "tight" )
工作正常,但不保存图形,仅使用我尝试使用的plt.savefig()
和figure = heatmap.get_figure()
的这种类型的绘图(clustermap),什么都没有
您的代码在
heatmap.set_xticklabels(...)
行上崩溃sns.clustermap
是一个figure-level function。它返回一个ClusterGrid
(轴级函数返回一个matplotlibax
)在seaborn的文档中,调用图形级函数
g =
(其中g
是“grid”的第一个字母)的返回值是一种习惯。如果开始给这些变量起不同的名字,很容易在seaborn的文档中迷失方向,也很容易在尝试使用matplotlib函数进行进一步自定义时迷失方向以下代码显示了预期的命名约定和旋转标签的预期方式。(我不理解更改
ylim
的原因,可能这与an old problem with matplotlib有关?这样更改ylim
会使绘图看起来出错。)相关问题 更多 >
编程相关推荐