【发布时间】:2020-05-19 01:39:03
【问题描述】:
我设法生成了一个交互式 matplotlib 图形,它使用一些 ipywidget 滑块改变了椭圆的位置。
但是绘图显示在新窗口中,我无法在笔记本中找到绘图的有效解决方案。
我可以在 jupyter notebook 中生成其他交互式图形,比如线图,但是用椭圆,没办法..
%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()
【问题讨论】:
标签: python matplotlib jupyter-notebook interactive