I plot some data from pandas DataFrame in a Jupyter notebook cell like this:
ax = data.plot('Weight', 'Height', kind='scatter', backend='matplotlib')
print(type(ax))
ax.plot(xs, line1, color='red')
print(type(ax))
ax.plot(xs, line2, color='yellow')
print(type(ax))
I see that ax is of the type <class 'matplotlib.axes._subplots.AxesSubplot'>. All good.
Then, in the next cell, I am trying to plot another line, reusing ax, just like I did with ax.plot(xs, line2, color='yellow'):
ax.plot(w1_arr, errors, color='red')
print(type(ax))
However, nothing is rendered, except for the type of ax, it is the same <class 'matplotlib.axes._subplots.AxesSubplot'>.
Questions:
- Why is nothing rendered? Is it because within a single Jupyter cell it is fine to 'reuse'
axbecause it reads all of the commands to plot, and then plot everything at once? But it is not fine to try to 'reuse'axoutside that single cell? - Why is the type of
axAxesSubplotand not simplyAxes? As per DataFrame.plot(), it should return Axes, I have explicitly set backend='matplotlib'.