I want to create multiple (here: two) seaborn heatmaps in one figure where the heatmaps have different value ranges but should contain a single, shared legend.
The following code creates two heatmaps in a single figure, but the color-coding is different for the two plots.
import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame(np.random.random((4,4)))
df2 = pd.DataFrame([1., .5, .9, .6])
fig, ax = plt.subplots(ncols=2, sharey=True)
sns_g = sns.heatmap(df, annot=True, yticklabels=True, ax=ax[0])
sns_g2 = sns.heatmap(df2, annot=True, cbar=False, ax=ax[1])
# fig.subplots_adjust(right=0.6)
# cbar_ax = fig.add_axes([1.1, 0.15, 0.05, .77])
# fig.colorbar(ax[1], cax=cbar_ax)
plt.tight_layout()
plt.show()
I included cbar=True in sns_g only to show that the two legends represent a different range. I want explicitly create two plots.