<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8">
</head>
<body>
<div style="font-family:sans-serif"><div style="white-space:normal">
<p dir="auto">Hi Nunzio,</p>

<p dir="auto">The issue is that you call <code>ax.set_aspect(‘equal’)</code>, and that changes the axes box.  However, <code>ax.get_position</code> returns the <code>frozen</code> position, i.e. the old position.  I don’t see a method to return the new position (and I wonder why <code>get_position</code> behaves this way).</p>

<p dir="auto">As a work around, you can get the aspect-ratio changed position as:</p>

<pre style="border:thin solid gray; margin-left:15px; margin-right:15px; max-width:90vw; overflow-x:auto; padding:5px"><code>figW, figH <span style="color: #333333">=</span> fig<span style="color: #333333">.</span>get_size_inches()
fig_aspect <span style="color: #333333">=</span> figH <span style="color: #333333">/</span> figW
newpos <span style="color: #333333">=</span> pp<span style="color: #333333">.</span>shrunk_to_aspect(ax<span style="color: #333333">.</span>get_aspect() <span style="color: #333333">*</span> ax<span style="color: #333333">.</span>get_data_ratio(), pp, fig_aspect)<span style="color: #333333">.</span>anchored(ax<span style="color: #333333">.</span>get_anchor(), pp))
</code></pre>



<p dir="auto">which I appreciate is a bit of a pain….</p>

<p dir="auto">Cheers,   Jody</p>

<p dir="auto">On 20 Sep 2017, at 7:06, Nunzio Losacco wrote:</p>

<p dir="auto"></p></div>
<div style="white-space:normal"><blockquote style="border-left:2px solid #5855D5; color:#5855D5; margin:0 0 5px; padding-left:5px"><p dir="auto">Hi all,<br>
<br>
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>
As you can see I’m getting the wrong position. What am I missing?<br>
<br>
Thanks for any help<br>
<br>
NL<br>
<br>
# -*- coding: utf-8 -*-<br>
<br>
from __future__ import unicode_literals<br>
import numpy as np<br>
from scipy.interpolate import griddata<br>
import matplotlib<br>
import matplotlib.pyplot as plt<br>
from matplotlib.patches import Circle<br>
from matplotlib.pylab import cm<br>
import matplotlib.colors as colors<br>
from mpl_toolkits.axes_grid1 import make_axes_locatable, axes_size<br>
<br>
matplotlib.rcParams.update({'font.size': 8})<br>
<br>
fig = plt.figure()<br>
fig.set_size_inches(6.3,6.3)<br>
<br>
ax1 = plt.subplot(111)<br>
divider = make_axes_locatable(ax1)<br>
ax2 = divider.append_axes('right', size='100%', pad=0.3)<br>
<br>
axes = [ax1, ax2]<br>
ltypes = ['dashed', 'solid']<br>
<br>
xi = np.linspace(-18.125, 18.125, 11)<br>
yi = np.linspace(0, 28, 9)<br>
xv, yv = np.meshgrid(xi, yi)<br>
<br>
xcOdd = 0.2<br>
zcOdd = 0.725<br>
xcEven = 0.6<br>
zcEven = 0.725<br>
<br>
maskRadius = 0.15<br>
<br>
for i in range(2):<br>
    ax = axes[i]<br>
    ax.set_xlabel('distance [m]')<br>
    if i == 0:<br>
        ax.set_ylabel('depth [m]')<br>
    if i == 1:<br>
        ax.set_yticklabels([])<br>
    ax.invert_yaxis()<br>
    ax.tick_params(direction='in')<br>
    ax.set_aspect('equal')<br>
    odd = Circle((xcOdd, zcOdd), .15, linewidth=1.2, color='k', fill=False)<br>
    even = Circle((xcEven, zcEven), .15, linewidth=1.2, linestyle=ltypes[i], color='k', fill=False)<br>
<br>
    vmax = 15.<br>
    vmin =  0.<br>
    norm = matplotlib.colors.Normalize(vmin,vmax, clip=False)<br>
<br>
    color_map = matplotlib.colors.ListedColormap(plt.cm.Greys(np.linspace(0.25, 1, 5)), "name")<br>
<br>
    ax.add_patch(odd)<br>
    ax.add_patch(even)<br>
<br>
pad = 0.03<br>
width = 0.03<br>
<br>
pos = ax2.get_position()<br>
<br>
ax3 = fig.add_axes([pos.xmax + pad, pos.ymin, width, 0.7*(pos.ymax-pos.ymin) ])<br>
<br>
plt.savefig('prova-vect-paper-test-2.eps', format='eps')<br>
<br>
_______________________________________________<br>
Matplotlib-users mailing list<br>
Matplotlib-users@python.org<br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users">https://mail.python.org/mailman/listinfo/matplotlib-users</a></p>
</blockquote></div>
<div style="white-space:normal">
</div>
</div>
</body>
</html>