How to keep the current figure when using ipython notebook with %matplotlib inline?

时间秒杀一切 提交于 2019-12-04 11:54:17

Use ax.plot instead of plt.plot to make sure you are plotting to the same axes both times. Use fig (in the second cell) to display the plot.

In cell 1:

%matplotlib inline
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.plot([1,2,3,6],[4,2,3,4])

In cell 2:

ax.plot([3.3, 4.4, 4.5, 6.5], [3., 5., 6., 7.])
fig 

yields

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!