简体   繁体   中英

Update ellipse position interactive matplotlib figure jupyter notebook

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()

在大多数情况下,使用% matplotlib notebook解决了这个问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM