【发布时间】:2016-09-05 21:46:47
【问题描述】:
我想做这样的事情:
import matplotlib.pyplot as plt
%matplotlib inline
fig1 = plt.figure(1)
plt.plot([1,2,3],[5,2,4])
plt.show()
在一个单元格中,然后在另一个单元格中重新绘制完全相同的绘图,如下所示:
plt.figure(1) # attempting to reference the figure I created earlier...
# four things I've tried:
plt.show() # does nothing... :(
fig1.show() # throws warning about backend and does nothing
fig1.draw() # throws error about renderer
fig1.plot([1,2,3],[5,2,4]) # This also doesn't work (jupyter outputs some
# text saying matplotlib.figure.Figure at 0x..., changing the backend and
# using plot don't help with that either), but regardless in reality
# these plots have a lot going on and I'd like to recreate them
# without running all of the same commands over again.
我也弄乱了这些东西的一些组合,但没有任何效果。
这个问题类似于IPython: How to show the same plot in different cells?,但我并不是特别想更新我的情节,我只是想重绘它。
【问题讨论】:
-
不要认为你可以用
inline做到这一点,它会丢弃 python 端的对象并将一个 png 和 base64 编码的文本存储在笔记本中。你应该可以用 nbagg (%matplotlib notebook) 做到这一点,你绝对可以用 ipympl 做到这一点
标签: python matplotlib jupyter