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
#!/usr/bin/env python   
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl

# Creating input file list
flist=open('lstcor').read().split()

# Assignments
FIG=plt.figure(dpi=300)
FIG.subplots_adjust(hspace=0.20,wspace=0.15)
NROW=2;NCOL=2 # two rows, two columns
TXT=['A','B','C','D']
mpl.rcParams['font.size']=10
mpl.rcParams['lines.linewidth']=0.8
mpl.rcParams['axes.linewidth']=1.5
mpl.rcParams['legend.handletextpad']=0.01
mpl.rcParams['legend.fontsize']=10
mpl.rcParams['legend.labelspacing']=0.005

lev=[-1,-0.75,-.50,-0.25,0,0.25,0.5,0.75,1]
col=['#0000ff','#696969','#a9a9a9','#d3d3d3','#ffffff','#2e8b57','#ffff00','#ff0000']

# Loading all the matrices
M1=np.loadtxt(flist[0]) 
M2=np.loadtxt(flist[1])
M3=np.loadtxt(flist[2])
M4=np.loadtxt(flist[3])

# Block 1
ax1=FIG.add_subplot(NROW,NCOL,1)
CNF1=ax1.contourf(M1,levels=lev,colors=col,origin='lower')

# Block 2
ax2=FIG.add_subplot(NROW,NCOL,2)
CNF2=ax2.contourf(M2,levels=lev,colors=col,origin='lower')

# Block 3
ax3=FIG.add_subplot(NROW,NCOL,3)
CNF3=ax3.contourf(M3,levels=lev,colors=col,origin='lower')

# Block 4
ax4=FIG.add_subplot(NROW,NCOL,4)
CNF4=ax4.contourf(M4,levels=lev,colors=col,origin='lower')

for index,name in enumerate(FIG.axes):
    name.set_xlim(auto=True)
    name.set_ylim(auto=True)
    name.set_xticks(range(0,342,50))
    name.set_yticks(range(0,342,50))
    name.axvspan(149,183,facecolor='#a9a9a9',alpha=0.2)
    name.axhspan(149,183,facecolor='#a9a9a9',alpha=0.2)
    name.text(5,350,TXT[index],fontsize=12)

cmap=mpl.colors.ListedColormap(col)
norm = mpl.colors.BoundaryNorm(lev,cmap.N)
ax5=FIG.add_axes(([0.05, 0.65, 0.9, 0.15])
mpl.colorbar.ColorbarBase(ax5,cmap=cmap,norm=norm,spacing='proportional',ticks=[-1,-0.75,0.25,0.5,0.75,1.0])

------------------------------------------------------------------------------
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
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to