<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Thank you so much for your help,<div class=""><br class=""></div><div class="">in fact, as `ax.set_aspect(‘equal’)` changes the bounding box at drawing time, others pointed out <a href="https://stackoverflow.com/questions/46314646/change-matplotlib-colorbar-to-custom-height" class="">here</a> that I should do:</div><div class=""><br class=""></div><div class="">```python</div><div class=""><pre class="lang-py prettyprinted prettyprint" style="margin-top: 0px; margin-bottom: 1em; padding: 5px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-stretch: inherit; line-height: inherit; vertical-align: baseline; width: auto; max-height: 600px; overflow: auto; background-color: rgb(239, 240, 241); color: rgb(57, 51, 24); word-wrap: normal;"><code style="margin: 0px; padding: 0px; border: 0px; font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, sans-serif; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; white-space: inherit;" class=""><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">fig</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">canvas</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">.</span><span class="pln" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">draw</span><span class="pun" style="margin: 0px; padding: 0px; border: 0px; font-family: inherit; font-size: inherit; font-style: inherit; font-variant-caps: inherit; font-stretch: inherit; line-height: inherit; vertical-align: baseline; color: rgb(48, 51, 54);">()</span></code></pre></div><div class="">```</div><div class="">before  getting the position of the axes. I assume that</div><div class=""><br class=""></div><div class=""> ```python </div><div class="">ax.apply_aspect()</div><div class="">```</div><div class="">does the same.</div><div class=""><br class=""></div><div class="">I also found out that this does not work properly with the default MacOSX backend on a Mac,</div><div class="">with TkAgg produces a slight offset of the new axis wrt the desird position, but only in the interactive window,</div><div class="">with the qt5Agg backend it gives correct results both in the interactive window and in the output file.</div><div class=""><br class=""></div><div class="">Best,</div><div class=""><br class=""></div><div class="">Nunzio</div><div class=""><br class=""><div class=""><div><blockquote type="cite" class=""><div class="">On 20 Sep 2017, at 21:57, Jody Klymak <<a href="mailto:jklymak@uvic.ca" class="">jklymak@uvic.ca</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">


<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8" class="">

<div class="">
<div style="font-family:sans-serif" class=""><div style="white-space:normal" class=""><p dir="auto" class="">As pointed out by Eric Firing (<a href="https://github.com/matplotlib/matplotlib/issues/9207" class="">here</a>) you can also do:</p>

<pre style="border:thin solid gray; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px" class=""><code class="">ax<span style="color: #333333" class="">.</span>set_aspect(<span style="color: #6600EE; font-weight: bold" class="">1.</span>)
ax<span style="color: #333333" class="">.</span>apply_aspect()
pos <span style="color: #333333" class="">=</span> ax<span style="color: #333333" class="">.</span>get_position(original<span style="color: #333333" class="">=</span><span style="color: #007020" class="">False</span>)
</code></pre><p dir="auto" class="">Cheers,   Jody</p><p dir="auto" class="">On 20 Sep 2017, at 12:30, Jody Klymak wrote:</p><div class=""><br class="webkit-block-placeholder"></div></div>
<div style="white-space:normal" class=""></div>
<blockquote style="border-left:2px solid #5855D5; color:#5855D5; margin:0 0 5px; padding-left:5px" class=""><div id="A6B219A4-224F-49D9-A0BF-96F0E9AD6D9A" class="">

<div style="font-family:sans-serif" class=""><div style="white-space:normal" class=""><p dir="auto" class="">On 20 Sep 2017, at 11:32, Klymak Jody wrote:</p><div class=""><br class="webkit-block-placeholder"></div></div>
<div style="white-space:normal" class=""><blockquote style="border-left:2px solid #5855D5; color:#5855D5; margin:0 0 5px; padding-left:5px" class=""><p dir="auto" class="">Oops.  Just realized you can also just do<br class="">
<br class="">
Pos =ax._postion<br class="">
<br class="">
To get the current position.  Of course this could break because you are accessing a private variable.</p>
</blockquote></div>
<div style="white-space:normal" class=""><p dir="auto" class="">oops again, no you can’t, you need to use the formula below.  The reason is that <code class="">apply_aspect</code> doesn’t get called until the axes is drawn, so the new <code class="">_position</code> isn’t set until then.  </p><p dir="auto" class="">Sorry, I should have checked before I wrote….</p><p dir="auto" class="">Cheers,   Jody</p><div class=""><br class="webkit-block-placeholder"></div></div>
<div style="white-space:normal" class=""><blockquote style="border-left:2px solid #5855D5; color:#5855D5; margin:0 0 5px; padding-left:5px" class=""><p dir="auto" class="">Cheers.  Jody<br class="">
<br class="">
Sent from my iPhone<br class="">
</p>
<blockquote style="border-left:2px solid #5855D5; color:#00AFCC; margin:0 0 5px; padding-left:5px; border-left-color:#00AFCC" class=""><p dir="auto" class="">On Sep 20, 2017, at 11:07, Jody Klymak <<a href="mailto:jklymak@uvic.ca" class="">jklymak@uvic.ca</a>> wrote:<br class="">
<br class="">
Hi Nunzio,<br class="">
<br class="">
The issue is that you call ax.set_aspect(‘equal’), and that changes the axes box. However, ax.get_position returns the frozen position, i.e. the old position. I don’t see a method to return the new position (and I wonder why get_position behaves this way).<br class="">
<br class="">
As a work around, you can get the aspect-ratio changed position as:<br class="">
<br class="">
figW, figH = fig.get_size_inches()<br class="">
fig_aspect = figH / figW<br class="">
newpos = pp.shrunk_to_aspect(ax.get_aspect() * ax.get_data_ratio(), pp, fig_aspect).anchored(ax.get_anchor(), pp))<br class="">
which I appreciate is a bit of a pain….<br class="">
<br class="">
Cheers, Jody<br class="">
<br class="">
On 20 Sep 2017, at 7:06, Nunzio Losacco wrote:<br class="">
<br class="">
Hi all,<br class="">
<br class="">
what I’m trying to do here is having third plot with its base aligned with the others and with reduced height (the final aim is custom positioning a colorbar).<br class="">
As you can see I’m getting the wrong position. What am I missing?<br class="">
<br class="">
Thanks for any help<br class="">
<br class="">
NL<br class="">
<br class="">
# -*- coding: utf-8 -*-<br class="">
<br class="">
from __future__ import unicode_literals<br class="">
import numpy as np<br class="">
from scipy.interpolate import griddata<br class="">
import matplotlib<br class="">
import matplotlib.pyplot as plt<br class="">
from matplotlib.patches import Circle<br class="">
from matplotlib.pylab import cm<br class="">
import matplotlib.colors as colors<br class="">
from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size<br class="">
<br class="">
matplotlib.rcParams.update({'font.size': 8})<br class="">
<br class="">
fig = plt.figure()<br class="">
fig.set_size_inches(6.3,6.3)<br class="">
<br class="">
ax1 = plt.subplot(111)<br class="">
divider = make_axes_locatable(ax1)<br class="">
ax2 = divider.append_axes('right', size='100%', pad=0.3)<br class="">
<br class="">
axes = [ax1, ax2]<br class="">
ltypes = ['dashed', 'solid']<br class="">
<br class="">
xi = np.linspace(-18.125, 18.125, 11)<br class="">
yi = np.linspace(0, 28, 9)<br class="">
xv, yv = np.meshgrid(xi, yi)<br class="">
<br class="">
xcOdd = 0.2<br class="">
zcOdd = 0.725<br class="">
xcEven = 0.6<br class="">
zcEven = 0.725<br class="">
<br class="">
maskRadius = 0.15<br class="">
<br class="">
for i in range(2):<br class="">
ax = axes[i]<br class="">
ax.set_xlabel('distance [m]')<br class="">
if i == 0:<br class="">
ax.set_ylabel('depth [m]')<br class="">
if i == 1:<br class="">
ax.set_yticklabels([])<br class="">
ax.invert_yaxis()<br class="">
ax.tick_params(direction='in')<br class="">
ax.set_aspect('equal')<br class="">
odd = Circle((xcOdd, zcOdd), .15, linewidth=1.2, color='k', fill=False)<br class="">
even = Circle((xcEven, zcEven), .15, linewidth=1.2, linestyle=ltypes[i], color='k', fill=False)<br class="">
<br class="">
vmax = 15.<br class="">
vmin = 0.<br class="">
norm = matplotlib.colors.Normalize(vmin,vmax, clip=False)<br class="">
<br class="">
color_map = matplotlib.colors.ListedColormap(plt.cm.Greys(np.linspace(0.25, 1, 5)), "name")<br class="">
<br class="">
ax.add_patch(odd)<br class="">
ax.add_patch(even)<br class="">
<br class="">
pad = 0.03<br class="">
width = 0.03<br class="">
<br class="">
pos = ax2.get_position()<br class="">
<br class="">
ax3 = fig.add_axes([pos.xmax + pad, pos.ymin, width, 0.7*(pos.ymax-pos.ymin) ])<br class="">
<br class="">
plt.savefig('prova-vect-paper-test-2.eps', format='eps')<br class="">
<br class="">
_______________________________________________<br class="">
Matplotlib-users mailing list<br class="">
<a href="mailto:Matplotlib-users@python.org" class="">Matplotlib-users@python.org</a><br class="">
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" class="">https://mail.python.org/mailman/listinfo/matplotlib-users</a><br class="">
<br class="">
_______________________________________________<br class="">
Matplotlib-users mailing list<br class="">
<a href="mailto:Matplotlib-users@python.org" class="">Matplotlib-users@python.org</a><br class="">
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" class="">https://mail.python.org/mailman/listinfo/matplotlib-users</a></p>
</blockquote></blockquote><br class=""><p dir="auto" class="">_______________________________________________<br class="">
Matplotlib-users mailing list<br class="">
<a href="mailto:Matplotlib-users@python.org" class="">Matplotlib-users@python.org</a><br class="">
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" class="">https://mail.python.org/mailman/listinfo/matplotlib-users</a></p>
</div>
<div style="white-space:normal" class="">
</div>
</div></div></blockquote>
<div style="white-space:normal" class="">
<blockquote style="border-left:2px solid #5855D5; color:#5855D5; margin:0 0 5px; padding-left:5px" class="">
</blockquote></div>
<div style="white-space:normal" class="">
</div>
</div>
</div>

</div></blockquote></div><br class=""></div></div></body></html>