I'm currently learning the basic philosophy of making plots with matplotlib in Python with Jupyter Notebook. My main gripe is when it comes to creating subplots, why do I have to run the code in one single chunk? And whenever I try to run it in separate steps, it throws me weird plots. For exampple:
plt.subplot(211)
plt.plot(range(10))
plt.subplot(212, facecolor='y')
plt.plot(randn(50))
I have to excute those four lines of codes in one step as opposed to run them each in four steps. What's exactly going on here? Why is there such a difference between the two approaches?

plt.subplots()(with an "s"). This approach is a little different from the classical matlab style and allows you to declare the figure and a tuple of axes in a single line, e.g.fig, (ax1, ax2) = plt.subplots(1, 2, sharey=True). These axes can be assigned new data at any time.plt.subplotor usingplt.subplots. The point is whether to use the statemachine or the oo api, i.e. whether to keep a reference to the object or not.add_subplotsdoes not modify any position. It just adds a subplot at a given position on the grid. Anyways I think the main point got across: You can do what ever you like in any cell you like, as long as you keep track of you object handles.