Description
Dear All,
I'm trying to update a single plot (or re-generate the same plot) depending on a value given by an ipywidget, but I get new plots when the ggplot call is inside a function call.
In my particular case, my "ggplot" call is inside a function called by an "observe" method attached to a widget. When the following example code is ran within a jupyter notebook, new plots are generated and appended to the notebook output every time the widget changes values:
from plotnine import *
from plotnine.data import *
from ipywidgets import widgets
from IPython.display import display
%matplotlib notebook
playSlider = widgets.IntSlider(min=0, max=5)
def createPlot(*args):
p = ggplot(mtcars, aes(x='hp', y='wt', color='mpg')) + geom_point() +facet_wrap("~cyl") + theme_bw()
p.draw()
playSlider.observe(createPlot, 'value')
display(playSlider)
Using %matplotlib notebook
or %matplotlib inline
makes no difference, new plot are appended to the cell's output.
I did find the "_draw_using_figure" and "_create_figure" methods in the code, but my attempts to force new plots to be created in the same matplotlib figure were unsuccessful.
Is this a problem in the implementation or just me missing the correct syntax?