Bryan Fodness wrote: > Is there a way to get the colorbar to work with an axes instance. > > ax2 = axes([0.2, 0.1, 0.6, 0.8], axisbg='w') > ax2.fill([x1,x2,x2,x1], [y1,y1,y2,y2], fc='None', ec='r') > ax2.pcolormesh(X, Y, newa, shading='flat', cmap=cm.YlOrRd)#gray_r) > ax2.axvline(x=0, color='gray', linestyle='--') > ax2.axhline(y=0, color='gray', linestyle='--') > ax2.plot([offaxisX], [offaxisY], 'r+', mew=1) > ax2.colorbar() > > AttributeError: 'Axes' object has no attribute 'colorbar' > > colorbar() > > , line 499, in <module> > colorbar() > File "C:\Python25\Lib\site-packages\matplotlib\pyplot.py", line 1129, > in colorbar > ret = gcf().colorbar(mappable, cax = cax, ax=ax, **kw) > File "C:\Python25\Lib\site-packages\matplotlib\figure.py", line 956, > in colorbar > cb = cbar.Colorbar(cax, mappable, **kw) > File "C:\Python25\Lib\site-packages\matplotlib\colorbar.py", line 558, > in __init__ > mappable.autoscale_None() # Ensure mappable.norm.vmin, vmax > AttributeError: 'NoneType' object has no attribute 'autoscale_None' > > I am not sure how the mappable, ax, and cax options work.
You want pylab.colorbar() or figure.colorbar(). (The pylab version is just a simple wrapper around figure.colorbar()) In this case, I think you want to use the ax keyword for colorbar, as in: pylab.colorbar(ax=ax2) The ax keyword argument specifies an the axes for which you want the colorbar drawn. The cax keyword argument specifies the axes in which you want the colorbar drawn. If you don't specifiy cax, space will be taken from the ax keyword argument (or the current axes). Ryan -- Ryan May Graduate Research Assistant School of Meteorology University of Oklahoma ------------------------------------------------------------------------- Check out the new SourceForge.net Marketplace. It's the best place to buy or sell services for just about anything Open Source. http://sourceforge.net/services/buy/index.php _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users