0
votes

I managed to generate an interactive matplotlib figure that changes the position of an ellipse using some ipywidget slider.
However the plot is displayed in a new window, I could not find a working solution with the plot in the notebook.
I could generate other interactive figures within a jupyter notebook, like line plots, but with the ellipse, no way..

%matplotlib
from matplotlib import patches
import matplotlib.pyplot as plt
from ipywidgets import interact

fig = plt.figure()
ax = fig.add_subplot(111)

ellipse = patches.Ellipse((0,0), width=50, height=25, angle=15)
ax.add_patch(ellipse)

ax.set_xlim(-100, 100)
ax.set_ylim(-100, 100)

@interact
def update(xcenter=(-50,50), ycenter=(-50,50)):
    ellipse.set_center((xcenter, ycenter))
    #fig.canvas.draw()
    plt.plot()
1

1 Answers

0
votes

Using % matplotlib notebook fixed the issue in most cases.