[Matplotlib-users] Understanding axes position

Adrien VINCENT vincent.adrien at gmail.com
Wed Sep 20 13:03:01 EDT 2017


Hi Nunzio,

Quick comment because I do not have much time unfortunately : did you think about using Gridspec (there is a nice tutorial on the Matplotlib website). You may have to set one extra axes instance to "not visible" but overall it may be easier.

Playing a bit with your code, I cannot tell why but when printing `pos` and `ax2.get_position()`, I do not get the same thing, which puzzles me. Maybe somebody else will know why.

Regards,
Adrien

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

-- 
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.


More information about the Matplotlib-users mailing list