K.K*_*.K. 10 matplotlib heatmap python-3.x seaborn
有没有办法改变 Seaborn 热图的单元格大小?我找到了这个,但我无法按预期工作。
所以,我在 y 轴标签中有长文本。由于所有文本都被切掉了,我想将热图的单元格缩小得更小。我不需要那个大矩形。(突出显示只是例如。)
当我通过类似的方式更改图形大小时,
plt.figure(figsize=(8, 6)) or
figure.set_size_inches(12, 12)
Run Code Online (Sandbox Code Playgroud)
单元格也会变大,因此文本仍然被切断。
这是代码。
sns.set(font_scale=1.2)
ax0 = plt.axes()
ax1 = sns.heatmap(hmap, cbar=0, cmap="YlGnBu",linewidths=2, ax=ax0,vmax=3000, vmin=0)
ax1.set_title('test heatmap')
for item in ax1.get_yticklabels():
item.set_rotation(0)
for item in ax1.get_xticklabels():
item.set_rotation(0)
figure = plt.gcf() # get current figure
figure.set_size_inches(12, 12)
plt.savefig('test.png') , dpi=400)
Run Code Online (Sandbox Code Playgroud)
Nat*_*ins 12
尝试square=True
在您的sns.heatmap
通话中使用该参数。这会将热图单元格限制为方形纵横比。
ax1 = sns.heatmap(hmap, cbar=0, cmap="YlGnBu",linewidths=2, ax=ax0,vmax=3000, vmin=0, square=True)
Run Code Online (Sandbox Code Playgroud)
您实际上不想更改单元格大小,但想缩小轴的大小。实现此目的的方法:
plt.tight_layout()
fig.subplots_adjust(left=0.4)
ax1 = fig.add_axes([0.4,0.2,0.5,0.6])
(数字所在的位置)[left, bottom, width, height]
并使用该轴绘制热图,sns.heatmap(... , ax=ax1)
. 归档时间: |
|
查看次数: |
14860 次 |
最近记录: |