nalzok
nalzok

Reputation: 16107

How to change scale of subplots in Seaborn?

I'm creating a figure with two heat maps

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')

However, the resulting heatmaps are too small (or, the legends are too large)

heatmaps.png

I've tried setting figsize to (20, 15), but it doesn't have any obvious effect. How can I fix this?

Upvotes: 1

Views: 387

Answers (1)

Sheldore
Sheldore

Reputation: 39042

Probably an ugly hack where you have to manipulate the shrink parameter manually but can be used for the current problem.

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])

Output enter image description here

Upvotes: 1

Related Questions