There are essentially two ways to tackle this.
A. Object-oriented approach
Use the object-oriented approach, i.e. keep handles to the figure and/or axes and reuse them in later cells.
import matplotlib.pyplot as plt
%matplotlib inline
fig, ax=plt.subplots()
ax.plot([1,2,3])
Then in a later cell,
ax.plot([4,5,6])
Suggested reading:
-
How to keep the current figure when using ipython notebook with %matplotlib inline?
-
How to add plot commands to a figure in more than one cell, but display it only in the end?
-
How do I show the same matplotlib figure several times in a single IPython notebook?
B. Keep figure in pyplot
The other option is to tell the matplotlib inline backend to keep the figures open at the end of a cell.
import matplotlib.pyplot as plt
%matplotlib inline
%config InlineBackend.close_figures=False # keep figures open in pyplot
plt.plot([1,2,3])
Then in a later cell
plt.plot([4,5,6])
Suggested reading: