1

I have seen those nice solutions for making multiple subplots maintaining the aspect ratio "equal" of each subplot:

Matplotlib 2 Subplots, 1 Colorbar

https://stackoverflow.com/a/23953487/10659110

...but with a different geometry. I wave 3 "square" plots (3 colormaps with the same x and y ranges) and I want to arrange them in a vertical column, with a single horizontal colorbar at the top or bottom.

Here an example:

#!/usr/bin/env python3

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from pylab import meshgrid,cm,imshow,contour,clabel,colorbar,axis,title,show

Nlatt  = 200 
Lrange = 20  

# Create grid values first.
xs = np.linspace(-Lrange, Lrange, Nlatt,  endpoint=True)
ys = np.linspace(-Lrange, Lrange, Nlatt , endpoint=True)
X,Y = meshgrid(xs, ys)         # grid of point

Zx = np.sin(Y-X)*np.sin(Y+X)
Zy = np.cos(Y)*np.sin(X)
ZZ = np.sqrt( Zx**2 + Zy**2 )

fig = plt.figure()  #e.g. "2,3,4" means "2x3 grid, 4th subplot"
ax1 = fig.add_subplot(3,1,1, aspect = "equal")
ax2 = fig.add_subplot(3,1,2, aspect = "equal")
ax3 = fig.add_subplot(3,1,3, aspect = "equal")

im1 = ax1.pcolor( X , Y , Zx , cmap='bwr' ,vmin=-2.5, vmax=2.5)
im2 = ax2.pcolor( X , Y , Zy , cmap='bwr' ,vmin=-2.5, vmax=2.5)
im3 = ax3.pcolor( X , Y , ZZ , cmap='bwr' ,vmin=-2.5, vmax=2.5)

plt.tight_layout()

plt.show()

I want to add the common horizontal colorbar at the top (or at the bottom) and share the x-axis, so that the label "x" and the x-coordinate numbers appear only on the bottom of the third plot. in practice, the desired output is the one described in Matplotlib shared horizontal colorbar aligned with bottom axis in subplots , but it is not very clear to me how this solution works. Moreover, I also want a single label and numbers for the x-axis at the bottom. Thank you for every hint.

Quillo
  • 123
  • 4

0 Answers0