I have a strange problem with matplotlib that I can not seem to figure out. When using the ipython notebook with the pylab flag, ipython notebook --pylab inline
I have a line of code that looks like this that is used to generate a colorbar with matplotlib:
im = ax.imshow(df, vmin=vmin, vmax=vmax)
The code works correctly and I get a nice colorbar. When I run this code as a python file I get an error, NameError: name 'ax' is not defined
. I understand that the ipython notebook --pylab inline
automatically imports a bunch of stuff into the notebook, but I cannot figure out what I need to import to fix the problem. print type(ax)
gives:
<class 'matplotlib.axes.AxesSubplot'>
Can anyone point out why my code works in ipython but not a plain python file? Thanks in advance.