I need plots of radar images to have the same size for different variables such that I can vertically align them on a web page.
The units are different and the width of the colorbar (including tick lables and label) changes accordingly, since the tick values of some colorbars are negative and just need more space than others. Using the bbox_inches="tight" option in the savefig command however leads to different figure widths. If I embed the plots, they are resized, but the box within the figure where the data is drawn, is adjusted, too, and the boxes are not aligned anymore.
Is there a way how I can prevent the bbox to be tight on one side, but keep it tight on the others while setting a fixed image width?
Here's a simplified version of the code I use:
import numpy as np
import matplotlib.pyplot as plt
import pylab
method=1
fs=12
height=600
width=3200
my_dpi=200
x, y = np.meshgrid(np.linspace(0,1000,100),np.linspace(0,31*100,32))
if method ==1:
z=numpy.random.rand(32,100)
else:
z=-3*numpy.random.rand(32,100)
plt.figure(figsize=(width/my_dpi, height/my_dpi), dpi=my_dpi)
plt.pcolor(x,y,z,cmap='jet', vmin=z.min(), vmax=z.max())
cbar=plt.colorbar()
plt.ylabel('Height above Radar [m]',fontsize=fs)
plt.xlabel('Time UTC',fontsize=fs)
plt.title("MRR roof 20150729")
plt.axis([x.min(), x.max(),y.min(), y.max()])
cbar.set_label('Reflectivity [dBZ]', rotation=90)
plotname="somename"+str(method)+".png"
pylab.savefig(plotname,dpi=my_dpi,bbox_inches='tight')
PS: Using subplots is not an option, because the actual web page will use JavaScript and the plots will be changeable individually.