I want to create a output widget with several drop boxes and a plot with Seaborn as follows. The intention is having different drop boxes to choose variables and according to user input output a different Seaborn plot.
Here the code. It works but not as desired.
dd = wd.Dropdown(
options=["YlGnBu","Blues","BuPu","Greens"],
value="Blues",
description='chosse cmap:',
disabled=False,
)
myout = wd.Output()
def draw_plot(change):
with myout:
myout.clear_output()
print('plotting out the following: sns.heatmap(df.corr(), annot=True, cmap = "YlGnBu")')
plt.figure(figsize=(8, 3))
sns.heatmap(df.corr(), annot=True, cmap = change.new)
plt.title("Correlation matrix");
dd.observe(draw_plot, names='value')
display(dd)
display(myout)
The above code DOES NOT CLEAR THE OUTPUT WIDGET every time a new variable of dropbox is selected, and Seaborn plots are added.
I saw these solutions: Stop seaborn plotting multiple figures on top of one another
that are not satisfactory according to my opinion. I would like to display in the output widget a new figure every time, i.e. totally clear the content and then add stuff again; plot again. I don't understand why clear_output() clears the text line but not the figure.
secondly, as some answers in the mentioned linked pointed out if working with Seaborn I don't want to resort to an underlying library, i.e. Matplotlib. I considere that a work around.
So how is the proper way to go?
thanks