plotting heatmap matrices in matplotlib with scale

Hi all,

How can I plot a matrix of values as a heatmap where values are shown
from green to red intensities, or blue to yellow intensities, like in
the following figure?

http://www.coriell.org/images/microarray.gif

I want to have the option of doing this with either green-red maps or
blue-yellow maps. Is the right function for this imshow, or pcolor?
Also, how can I get the scale bar to the left of it that shows the
ranges of the intensities, and how can this scale be adjusted?

Thanks very much.

I think what you are looking for is a way to specify the colormap of your plot. While the documentation is a little sparse on this topic, there is plenty of functionality in matplotlib regarding colormaps.

Here is a list of built-in colormaps:

http://matplotlib.sourceforge.net/api/pyplot_api.html?highlight=colormap#matplotlib.pyplot.colormaps

Just about any matplotlib plotting function accepts a cmap keyword where you can specify a colormap of your choice to override the default. You can even create your own colormap if you can’t find one to suit your needs.

I hope this is helpful.

Ben Root

···

On Sat, Jun 5, 2010 at 9:41 PM, per freem <perfreem@…287…> wrote:

Hi all,

How can I plot a matrix of values as a heatmap where values are shown

from green to red intensities, or blue to yellow intensities, like in

the following figure?

http://www.coriell.org/images/microarray.gif

I want to have the option of doing this with either green-red maps or

blue-yellow maps. Is the right function for this imshow, or pcolor?

Also, how can I get the scale bar to the left of it that shows the

ranges of the intensities, and how can this scale be adjusted?

Thanks very much.


ThinkGeek and WIRED’s GeekDad team up for the Ultimate

GeekDad Father’s Day Giveaway. ONE MASSIVE PRIZE to the

lucky parental unit. See the prize list and enter to win:

http://p.sf.net/sfu/thinkgeek-promo


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi all,

How can I plot a matrix of values as a heatmap where values are shown
from green to red intensities, or blue to yellow intensities, like in
the following figure?

http://www.coriell.org/images/microarray.gif

I want to have the option of doing this with either green-red maps or
blue-yellow maps. Is the right function for this imshow, or pcolor?

pcolor is general but slow, and best suited for moderate numbers of points. pcolormesh is faster. imshow can be good if you have a uniform Cartesian grid. imshow(...., interpolation='nearest') is the closest analogy to pcolor and pcolormesh.

Also, how can I get the scale bar to the left of it that shows the
ranges of the intensities, and how can this scale be adjusted?

In the gallery, and in the corresponding examples subdirectory of the mpl distribution, search for "colorbar". Note that the color scale is not set via colorbar options, but via vmin and vmax kwargs in imshow etc., or via the pylab clim command, or via the set_clim method of the image object returned by imshow. In other words, the colorbar is used for showing a color scale used by another image-like plot element--it is not used for controlling that scale, or any other aspect of the image itself.

Eric

···

On 06/05/2010 04:41 PM, per freem wrote:

Thanks very much.

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options