ColorbarBase usage

Friends,
I have created a figure (with two rows and two columns) and i drew four contourf plots (A,B,C,D etc). All the four contourf has the same coloring and bounds. I do not want to draw a colorbar() for each of the plots separately but only one colorbar at the bottom of the four plots.Something like the following scheme.

plot1 plot2
plot3 plot4
colorbar

I tried using mpl.colorbar.ColorbarBase as given in http://matplotlib.sourceforge.net/examples/api/colorbar_only.html example to draw the colorbar. However i find the colorbar that is created is overlapping over the plots. Kindly let me know what is the correct way of adjuting its location and size or any other way to create this colorbar.

My code is attached with this mail.

Thanks,
Bala

test.py (1.72 KB)

Hi Bala,

Bala subramanian, on 2011-01-17 16:42, wrote:

I have created a figure (with two rows and two columns) and i drew four
contourf plots (A,B,C,D etc). All the four contourf has the same coloring
and bounds. I do not want to draw a colorbar() for each of the plots
separately but only one colorbar at the bottom of the four plots.Something
like the following scheme.

plot1 plot2
plot3 plot4
          colorbar

Here's one way of getting the type of plot you want.
I just incremented NROW by one, and for the colorbar axes
creation, changed it to be:
  ax5=FIG.add_subplot(NROW,1,NROW)

which is a quick way to get the last row to span both columns.

(I had to comment some things out to get the plot to run without
needing the data).

I tried using mpl.colorbar.ColorbarBase as given in
http://matplotlib.sourceforge.net/examples/api/colorbar_only.html example to
draw the colorbar. However i find the colorbar that is created is
overlapping over the plots. Kindly let me know what is the correct way of
adjuting its location and size or any other way to create this colorbar.

There, the axes are created to not overlap by hand tuning the
rectangle parameters passed (left, bottom, width, top). You can
get the same using the trick I used above, or get more
sophisticated combinations using GridSpec [1], or if you want to
get even fancier, with the AxesGrid toolkit [2]

1. http://matplotlib.sourceforge.net/users/gridspec.html
2. http://matplotlib.sourceforge.net/mpl_toolkits/axes_grid/index.html#toolkit-axes

best,

···

--
Paul Ivanov
314 address only used for lists, off-list direct email at:
http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7

Friends,
I have created a figure (with two rows and two columns) and i drew four
contourf plots (A,B,C,D etc). All the four contourf has the same
coloring and bounds. I do not want to draw a colorbar() for each of the
plots separately but only one colorbar at the bottom of the four
plots.Something like the following scheme.

plot1 plot2
plot3 plot4
           colorbar

I tried using mpl.colorbar.ColorbarBase as given in
http://matplotlib.sourceforge.net/examples/api/colorbar_only.html
example to draw the colorbar. However i find the colorbar that is
created is overlapping over the plots. Kindly let me know what is the
correct way of adjuting its location and size or any other way to create
this colorbar.

You should not ordinarily need to use ColorbarBase. For something like what you are describing, see

http://matplotlib.sourceforge.net/examples/pylab_examples/multi_image.html

Eric

···

On 01/17/2011 05:42 AM, Bala subramanian wrote:

My code is attached with this mail.

Thanks,
Bala

------------------------------------------------------------------------------
Protect Your Site and Customers from Malware Attacks
Learn about various malware tactics and how to avoid them. Understand
malware threats, the impact they can have on your business, and how you
can protect your company and customers by using code signing.
http://p.sf.net/sfu/oracle-sfdevnl

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Well, I learned something today. I had always been turning to
ColorbarBase for cases like this.

Ryan

···

On Mon, Jan 17, 2011 at 11:35 AM, Eric Firing <efiring@...202...> wrote:

On 01/17/2011 05:42 AM, Bala subramanian wrote:

Friends,
I have created a figure (with two rows and two columns) and i drew four
contourf plots (A,B,C,D etc). All the four contourf has the same
coloring and bounds. I do not want to draw a colorbar() for each of the
plots separately but only one colorbar at the bottom of the four
plots.Something like the following scheme.

plot1 plot2
plot3 plot4
colorbar

I tried using mpl.colorbar.ColorbarBase as given in
http://matplotlib.sourceforge.net/examples/api/colorbar_only.html
example to draw the colorbar. However i find the colorbar that is
created is overlapping over the plots. Kindly let me know what is the
correct way of adjuting its location and size or any other way to create
this colorbar.

You should not ordinarily need to use ColorbarBase. For something like
what you are describing, see

http://matplotlib.sourceforge.net/examples/pylab_examples/multi_image.html

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma