Pages

lundi 17 décembre 2012

display colorbar with python


I used pcolor, map.contourf, or map.imshow for drawing the 2_D arrray in colors. In order to show the color bar, I defined a small function cbar() as below. If I need to display the color bar, I use the "cbar()" directly.


def cbar():
     """
     Displays a colorbar.
     """
     if len(gcf().axes) > 1:
         gcf().axes[1].clear()
         cax = gcf().axes[1]
     else:
         # left, up, width, heigth, normalized in (0,1) unit
         #cax = pylab.axes([0.875, 0.1, 0.05, 0.75])
         cax = pylab.axes([0.92, 0.1, 0.025, 0.75])

     pylab.colorbar(cax = cax)

Aucun commentaire:

Enregistrer un commentaire