On 11/21/11 8:45 PM, Arlindo da Silva wrote:
Hi,
(A similar issue was reported back in 7/4/11 without a definite
solution, so I am reposting with some additional diagnostics. ) Up to
Matplotlib 0.99 (EPD 6.3) the code snippet below produced a plot with
an aligned colorbar as in the attached "correct.png" plot:
fig = plt.figure()
ax = fig.add_axes(...)
m = Basemap(..., ax=ax, ...)
im = m.imshow(...)
# show()
# setup colorbar axes and draw colorbar
bbox = ax.get_position()
l,b,w,h = bbox.bounds
cax = fig.add_axes([l+w+0.05, b, 0.05, h],frameon=False)
fig.colorbar(im, cax=cax)
Starting with Matplotlib 1.0.0 this no longer works. The
ax.get_position() no longer returns the bounding box of the plot but
the bbox of the window, see the attached "wrong.png" attached. Some
odd behavior:
1) I can get the code above to work correctly under MPL 1.0 if I
uncomment theshow() line above. (This is not an acceptable solution
because show() blocks if not in interactive mode).
2) Under ipython, if after plotting I print
gca().get_position().bounds I get the correct bounding box, even when
I just got the wrong colorbar positioning.
3) If I run the code above twice in a row (without creating a new
fig), the second time around the correct bounding box is returned.
Can someone explain to me what is going on? Is this one of those
arcane features of matplotlib transform caching? It appears that
show() is flushing some type of buffer. Is there any way of
accomplishing this without actually calling show()?
Thank you,
Hi Arlindo: I'm not sure what changed in matplotlib to cause this (I'm
sure someone else on the list will). However, if you upgrade to basemap
1.0.2/matplotlib 1.1.0 you can use the new matplotlib colorbar method,
which does what you want automatically without having to use
ax.get_position. If uses the axes_grid toolkit under the hood to
compute the correct location and size for the colorbar. See
http://matplotlib.github.com/basemap/api/basemap_api.html?highlight=colorbar#mpl_toolkits.basemap.Basemap.colorbar
The examples at http://matplotlib.github.com/basemap/users/examples.html
use this.
Regards,
Jeff
------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure
contains a definitive record of customers, application performance,
security threats, fraudulent activity, and more. Splunk takes this
data and makes sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-novd2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users