imshow() with a colorbar?

Hi,

I am trying to add a (configurable) colorbar to a an array which I simply plot with imshow().

Could anyone please help me how to enhance it with a colorbar?

import scipy,pylab
import matplotlib.cm as cm # colormaps

import matplotlib.colors as col # colormaps

dat = scipy.array([[1,2,3,4],[5,6,7,8]])

fig = pylab.figure()
ax = pylab.gca()
ax.set_title(‘the title’)

here’s chaos :slight_smile:

#cmap = cm.get_cmap(‘rainbow’, 20) # 10 discrete colors

#ax.imshow(dat, cmap=cmap, interpolation=‘nearest’)
#fig.colorbar(dat)
#min,max = dat.min(),dat.max()

ax.imshow(dat,interpolation=‘nearest’)
pylab.show()

Thanks a lot in advance,

Daniel

Hi,

I am trying to add a (configurable) colorbar to a an array which I
simply plot with imshow().

Could anyone please help me how to enhance it with a colorbar?

Check out the gallery; several examples there use a colorbar. http://matplotlib.sourceforge.net/gallery.html

Then look for relevant sections in the docs, such as
http://matplotlib.sourceforge.net/users/image_tutorial.html
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.colorbar
etc.

Eric

···

On 02/07/2011 10:48 AM, Daniel Mader wrote:

import scipy,pylab
import matplotlib.cm <http://matplotlib.cm> as cm # colormaps
import matplotlib.colors as col # colormaps

dat = scipy.array([[1,2,3,4],[5,6,7,8]])

fig = pylab.figure()
ax = pylab.gca()
ax.set_title('the title')

## here's chaos :slight_smile:
#cmap = cm.get_cmap('rainbow', 20) # 10 discrete colors
#ax.imshow(dat, cmap=cmap, interpolation='nearest')
#fig.colorbar(dat)
#min,max = dat.min(),dat.max()

ax.imshow(dat,interpolation='nearest')
pylab.show()

Thanks a lot in advance,
Daniel

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Thanks a lot Thomas,

besides that it should be

fig.colorbar(im)
instead of
ax.colorbar(im)

the example works great!

Best regards,
Daniel

2011/2/7 Eric Firing

···

On 02/07/2011 10:48 AM, Daniel Mader wrote:

Hi,

I am trying to add a (configurable) colorbar to a an array which I

simply plot with imshow().

Could anyone please help me how to enhance it with a colorbar?

Check out the gallery; several examples there use a colorbar.

http://matplotlib.sourceforge.net/gallery.html

Then look for relevant sections in the docs, such as

http://matplotlib.sourceforge.net/users/image_tutorial.html

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

etc.

Eric

import scipy,pylab

import matplotlib.cm <http://matplotlib.cm> as cm # colormaps
import matplotlib.colors as col # colormaps

dat = scipy.array([[1,2,3,4],[5,6,7,8]])

fig = pylab.figure()

ax = pylab.gca()

ax.set_title(‘the title’)

here’s chaos :slight_smile:

#cmap = cm.get_cmap(‘rainbow’, 20) # 10 discrete colors

#ax.imshow(dat, cmap=cmap, interpolation=‘nearest’)

#fig.colorbar(dat)

#min,max = dat.min(),dat.max()

ax.imshow(dat,interpolation=‘nearest’)

pylab.show()

Thanks a lot in advance,

Daniel