Retake control of colorbar?

Dear all,

This is probably a silly question based on my bias from matlab, but I have tried for two days without luck. I need to make pcolor plots in several figures, and the go back and add a scatter on each. This procedure is necessary due to how I read the data. My problem is that I can't figure out how update the colorbar in the end.

An example is as follows:

···

#=====
import random

import pylab as pl
import numpy as np

from numpy.random import rand

def pcl(fig,val):
   pl.figure(fig)
   pl.clf()
   pl.pcolor(val)
   pl.colorbar()

def sct(fig,xvec,yvec,cvec):
   pl.figure(fig)
   pl.scatter(xvec,yvec,40,cvec)
   pl.xlim(0,10)
   pl.ylim(0,10)
   pl.colorbar(orientation='horizontal')

pcl(1, rand(20,20)*10)
pcl(2, rand(20,20)*10)
pcl(3, rand(20,20)*10)

sct(1,rand(10)*10,rand(10)*10,rand(10)*40)
sct(2,rand(10)*10,rand(10)*10,rand(10)*40)
sct(3,rand(10)*10,rand(10)*10,rand(10)*40)
#=====

I would like the pcolor image and the colorbar to have the same clim extents as the scatter in the end. Is this in any way possible?

Many thanks for any help!

:-)Bror

How about returning the colorbar limits from pcl(), and using the larger extent of those limits and the ones from the scatter data when you call the colorbar in sct()? (ScalarMappables have get_clim(), set_clim().)

Or, more generally, record the data limits and have both functions check them, in case someday you want to call pcl() after sct().

In general, I like the figure style for an experiment or case to be a class, with plotting functions like the ones you've already written but data members that either pretty up the functions, or are useful for other reports ('Variability and drift between runs'...), etc.

&C

···

On Feb 10, 2010, at 10 Feb, 9:41 AM, Bror Jonsson wrote:

Dear all,

This is probably a silly question based on my bias from matlab, but I have tried for two days without luck. I need to make pcolor plots in several figures, and the go back and add a scatter on each. This procedure is necessary due to how I read the data. My problem is that I can't figure out how update the colorbar in the end.

An example is as follows:

#=====
import random

import pylab as pl
import numpy as np

from numpy.random import rand

def pcl(fig,val):
  pl.figure(fig)
  pl.clf()
  pl.pcolor(val)
  pl.colorbar()

def sct(fig,xvec,yvec,cvec):
  pl.figure(fig)
  pl.scatter(xvec,yvec,40,cvec)
  pl.xlim(0,10)
  pl.ylim(0,10)
  pl.colorbar(orientation='horizontal')

pcl(1, rand(20,20)*10)
pcl(2, rand(20,20)*10)
pcl(3, rand(20,20)*10)

sct(1,rand(10)*10,rand(10)*10,rand(10)*40)
sct(2,rand(10)*10,rand(10)*10,rand(10)*40)
sct(3,rand(10)*10,rand(10)*10,rand(10)*40)
#=====

I would like the pcolor image and the colorbar to have the same clim extents as the scatter in the end. Is this in any way possible?

Many thanks for any help!

:-)Bror

------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Chloe Lewis
Graduate student, Amundson Lab
Ecosystem Sciences
137 Mulford Hall
Berkeley, CA 94720-3114
http://nature.berkeley.edu/~chlewis