IPython: How to show the same plot in different cells?

你。 提交于 2019-12-04 06:48:02

I have found a solution! Basically you create a figure and the axis with fig, ax = plt.subplots() and then use the ax variable to draw (potentially in multiple cells). In any of the cells you want to replot the figure, just write fig as the last line of the cell, resulting in the cell using the updated figure as output.
See my answer here for more details.

Try the object-oriented interface of matplotlib - matplotlib.figure; you can use the reference of the Figure object created, as required.

  • Create a figure object - fig = plt.figure()
  • Add axes to it - ax = fig.add_axes([0.025, 0.025, 0.95, 0.95])
  • Plot on the axis created - ax.plot(X, Y)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!