如何更改 Seaborn 中子图的比例?
How to change scale of subplots in Seaborn?
我正在创建一个包含两个热图的图形
fig, axs = plt.subplots(ncols=2, figsize=(20, 15))
heatmap(data1, cmap=color_palette('Greys_r'), square=True, ax=axs[0])
heatmap(data2, cmap=color_palette('Greys_r'), square=True, ax=axs[1])
fig.savefig('heatmap.png')
但是,生成的热图太小(或者,图例太大)
我试过setting figsize
to (20, 15)
,但没有明显的效果。我该如何解决这个问题?
可能是一个丑陋的技巧,您必须手动操作 shrink
参数,但可用于解决当前问题。
import numpy as np
import seaborn as sns
data1 = np.random.rand(10, 12)
data2 = np.random.rand(10, 12)
fig, axs = plt.subplots(ncols=2, figsize=(20, 15))
sns.heatmap(data1, cmap=sns.color_palette('Greys_r'), square=True, cbar_kws={"shrink": .42}, ax=axs[0])
sns.heatmap(data2, cmap=sns.color_palette('Greys_r'), square=True, cbar_kws={"shrink": .42}, ax=axs[1])
输出
我正在创建一个包含两个热图的图形
fig, axs = plt.subplots(ncols=2, figsize=(20, 15))
heatmap(data1, cmap=color_palette('Greys_r'), square=True, ax=axs[0])
heatmap(data2, cmap=color_palette('Greys_r'), square=True, ax=axs[1])
fig.savefig('heatmap.png')
但是,生成的热图太小(或者,图例太大)
我试过setting figsize
to (20, 15)
,但没有明显的效果。我该如何解决这个问题?
可能是一个丑陋的技巧,您必须手动操作 shrink
参数,但可用于解决当前问题。
import numpy as np
import seaborn as sns
data1 = np.random.rand(10, 12)
data2 = np.random.rand(10, 12)
fig, axs = plt.subplots(ncols=2, figsize=(20, 15))
sns.heatmap(data1, cmap=sns.color_palette('Greys_r'), square=True, cbar_kws={"shrink": .42}, ax=axs[0])
sns.heatmap(data2, cmap=sns.color_palette('Greys_r'), square=True, cbar_kws={"shrink": .42}, ax=axs[1])
输出