cmap normalization question

Hi,

   I have been looking around but can't find what I want.
I have two arrays, one with numbers from 0.02 to 0.20 and
the other from 0.03 to 0.50. I am trying to plot them together
with other arrays in a scatterplot where these two are the
color term

plt.scatter(x1,y1,c=myarr1,cmap=plt.get_cmap("gist_heat))
plt.scatter(x2,y2,c=myarr2,cmap=plt.get_cmap("gist_heat))

but it seems that each instance of the plot command rescales
the array such that myarr1.max() and myarr2.max() are both with,
which means that the two color scales are out of sync. Is there
a way to force the two plots to respect the values in the array
have the cmap go from 0 to 1, not from myarr1.min() to myarr1.max()?

Cheers
  Tommy

Tommy,

The general method is to use a Normalize object and pass it as kwarg ‘norm’. However, as a convenience, some plotting functions has a ‘vmin’ and ‘vmax’ kwarg that can be specified:

plt.scatter(x1,y1,c=myarr1,cmap=plt.get_cmap("gist_heat), vmin=0.0, vmax=1.0)
plt.scatter(x2,y2,c=myarr2,cmap=plt.get_cmap("gist_heat), vmin=0.0, vmax=1.0)

Cheers!
Ben Root

···

On Mon, Oct 31, 2011 at 11:02 AM, Tommy Grav <tgrav@…935…> wrote:

Hi,

I have been looking around but can’t find what I want.

I have two arrays, one with numbers from 0.02 to 0.20 and

the other from 0.03 to 0.50. I am trying to plot them together

with other arrays in a scatterplot where these two are the

color term

plt.scatter(x1,y1,c=myarr1,cmap=plt.get_cmap("gist_heat))

plt.scatter(x2,y2,c=myarr2,cmap=plt.get_cmap("gist_heat))

but it seems that each instance of the plot command rescales

the array such that myarr1.max() and myarr2.max() are both with,

which means that the two color scales are out of sync. Is there

a way to force the two plots to respect the values in the array

have the cmap go from 0 to 1, not from myarr1.min() to myarr1.max()?

Cheers

Tommy

Try

nm = matplotlib.colors.Normalize(desired_min, desired_max)

plt.scatter(x1,y1,c=myarr1,cmap=plt.get_cmap("gist_heat"),norm=nm)

You could just use the vmin/vmax keywords in the scatter() call, but
I've just always preferred using Normalize(); you have more control
over what happens that way (see docs for Normalize).

ref: http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.scatter

···

On Mon, Oct 31, 2011 at 12:02 PM, Tommy Grav <tgrav@...935...> wrote:

Hi,

I have been looking around but can't find what I want.
I have two arrays, one with numbers from 0.02 to 0.20 and
the other from 0.03 to 0.50. I am trying to plot them together
with other arrays in a scatterplot where these two are the
color term

plt.scatter(x1,y1,c=myarr1,cmap=plt.get_cmap("gist_heat))
plt.scatter(x2,y2,c=myarr2,cmap=plt.get_cmap("gist_heat))

but it seems that each instance of the plot command rescales
the array such that myarr1.max() and myarr2.max() are both with,
which means that the two color scales are out of sync. Is there
a way to force the two plots to respect the values in the array
have the cmap go from 0 to 1, not from myarr1.min() to myarr1.max()?

Cheers
Tommy

------------------------------------------------------------------------------
Get your Android app more play: Bring it to the BlackBerry PlayBook
in minutes. BlackBerry App World&#153; now supports Android&#153; Apps
for the BlackBerry&reg; PlayBook&#153;. Discover just how easy and simple
it is! http://p.sf.net/sfu/android-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

--
Daniel Hyams
dhyams@...287...