On Friday 20 June 2008 5:40:04 pm 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'

I think you are looking for the Figure.colorbar() method if you are using the 
OO API. If you are using the pylab interface, it is pylab.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.

Try:

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)
colorbar()
ax2.axvline(x=0, color='gray', linestyle='--')
ax2.axhline(y=0, color='gray', linestyle='--')
ax2.plot([offaxisX], [offaxisY], 'r+', mew=1)

or:

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')
mappable = 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)
colorbar(mappable, ax=ax2)

or:

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')
mappable = 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)
cax = axes([0.65, 0.1, 0.2, 0.8], axisbg='w')
colorbar(mappable, cax=cax)




-------------------------------------------------------------------------
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

Reply via email to