请参见以下最小示例(空行是Jupyter Lab中的新单元格)。如标题中所述,我无法通过运行draw()命令来更新一个单元格中的图形。
import numpy as np
import matplotlib.pyplot as plt
xs = np.linspace(0, 1, 100)
fig = plt.figure();plt.ion()
ax = fig.add_subplot(1,1,1)
testplot = ax.plot(xs, 0.5*xs)
# this draws a straight line in figure fig
testplot[0].set_ydata(0.5-xs)
fig.canvas.draw()
# this should in principle update the figure with a line having negative slope (and it works in "plain python", even before redrawing the canvas)
fig
# this shows the updated figure in this new cell but does still not update the "old" figure above
我在做什么错了?