On Mon, Jul 11, 2011 at 11:16 AM, Sebastian Berg wrote:
Hi,

On Mon, 2011-07-11 at 07:13 -0700, SiggiN wrote:
> Hi all!
>
> following code shows the problem I have with placing a colorbar for several
> subplots.
>
> #-----------------------------code------------
> import matplotlib
> import numpy as np
> import matplotlib.cm as cm
> import matplotlib.mlab as mlab
> import matplotlib.pyplot as plt
>
> matplotlib.rcParams['xtick.direction'] = 'out'
> matplotlib.rcParams['ytick.direction'] = 'out'
>
> delta = 0.025
> x = np.arange(-3.0, 3.0, delta)
> y = np.arange(-2.0, 2.0, delta)
> X, Y = np.meshgrid(x, y)
> Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
> Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1)
> # difference of Gaussians
> Z = 10.0 * (Z2 - Z1)
>
> plt.figure()
>
> plt.subplot(211)
> CS = plt.contourf(X, Y, Z)
>
>
> plt.subplot(212)
> CS = plt.contourf(X, Y, Z)
>
>
> plt.colorbar(orientation='horizontal')
> plt.show()
>
> #-------------end code--------------
> result:
> http://old.nabble.com/file/p32037832/inttest.png
>
> is ther a way to not let the colorbar cut space from the 2nd subplot. I
> would like to have them both the same size.
>

the subplot command only takes from the last axes as default. What you
need to do (I think and I always do it like this) Define 3 sets of axes
by hand instead of subplot(211) you use plt.axes(...) to create them (I
guess there may be a nicer method, not sure). Then you can pass which
axes to draw into with the colorbar function.

Regards,

Sebastian

Personally, I prefer to use the axes_grid toolkit that allows you to specify if and how you want colorbar axes and provides an array of colorbar axes.  http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/index.html#toolkit-axesgrid-index

Enjoy!
Ben Root