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'
Bryan, A colorbar is a plot in its own axes, so just as a figure has an "add_subplot" method to add a general-purpose axes, it has a "colorbar" method to add a special-purpose axes with a colorbar in it. One way to modify your example is something like this (untested): 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') # Save the "mappable" returned by pcolormesh: pcm = 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) # Call the figure method, give it the mappable: ax2.get_figure().colorbar(pcm, ax=ax2) This will steal space from ax2 to make the colorbar axes. If you want to make the colorbar axes yourself, called ax_cbar, for example, then the last line would be ax2.get_figure().colorbar(pcm, cax=ax_cbar) Of course, if you make the figure at the start, and save the reference to it, then you can use that reference in place of "ax2.get_figure()" Eric > > 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. ------------------------------------------------------------------------- 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