I want to change a seaborn heatmap interactively. However, running sns.heatmap
twice makes a colorbar multiply (Fig. 1: Before clicking "Reset", Fig. 2: After clicking "Reset"
)
I tried to set cbar=0
to heatmap in reset
callback, the text of the colorbar does NOT change, although the scale of the latter matrix is 1000 times large.
Do you know the way to change BOTH a heatmap and a colorbar? Note that the heatmaps have differenet matrix sizes and different color palettes.
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib.widgets import Slider, Button, RadioButtons
fig, ax = sns.plt.subplots()
sns.heatmap(np.random.rand(10, 12), ax=ax)
resetax = sns.plt.axes([0.8, 0.025, 0.1, 0.04])
button = Button(resetax, 'Reset', hovercolor='0.975')
def reset(event):
sns.heatmap(np.random.rand(8, 8)*1000, ax=ax, cmap = sns.diverging_palette(220, 10, as_cmap=True))
button.on_clicked(reset)
sns.plt.show()