python - Remove past Matplotlib plots in the same cell in Jupyter Notebook involving interactive widgets -
this small problem has been bugging me while.
i have pandas dataframe consisting of continuous variables. want draw scatter plot (using matplotlib) chosen pair of variables, making use of interactive widgets in jupyter well.
let's data has 3 numeric columns: 'a','b', , 'c'.
so far have these lines of codes:
def g(x,y): plt.scatter(x, y) interactive_plot = interactive(g, x=['a','b','c'], y=['a','b','c']) interactive_plot and work fine, in churn out scatter plot whenever toggle drop-down boxes x , y , select pair of variables 3 variables available. however, problem here previous plots churned out not erased before new plot shown. in other words, matplotlib doesn't update plot in existing figure, stack plots/figures on top of each other. if change choice of variable pairs 10 times, i'll 10 scatter plots, isn't want.
could me this?
thanks in advance.
you may add plt.show() @ end of function. replots graph in same cell instead of adding new one.
import numpy np import pandas pd import matplotlib.pyplot plt ipywidgets import interactive %matplotlib inline columns=['a','b','c'] data = np.cumsum(np.random.rand(10,3),axis=1) df = pd.dataframe(data,columns=columns) def g(x,y): plt.scatter(df[x], df[y]) plt.show() interactive_plot = interactive(g, x=columns, y=columns) interactive_plot 
Comments
Post a Comment