imshow clim question

Hi,

    > I would like to do the following:

    > 1. Display an image using pylab.imshow. Works well and I
    > am happy with the v1,v2 values that are auto computed.

    > Next I need to:

    > 2. Display a second image using the EXACT v1,v2 values
    > that matplotlib determined for the first image.

    > I read through the documentation for
    > matplotlib.image.AxesImage that the fisrt imshow would
    > return, but could not determine exactly how to access the
    > v1,v2 values for that object.

You can access the vmin and vmax attributes from the image
normalization instance and pass them on to subsequent images

  In [3]: im = imshow(rand(20,20))

  In [4]: im.norm.vmin
  Out[4]: 0.001056874287314713

  In [5]: im.norm.vmax
  Out[5]: 0.99817508459091187

  In [6]: newim = imshow(rand(30,30), vmin=im.norm.vmin, vmax=im.norm.vmax)

FYI, imshow returns an image.AxesImage (which derives from
colors.ScalarMappable) and this contains a colors.normalize instance,
which has the attributes you are looking for. The clim command works
by setting the vmin and vmax attrs. More details are documented here:

  http://matplotlib.sourceforge.net/matplotlib.image.html#AxesImage
  http://matplotlib.sourceforge.net/matplotlib.cm.html#ScalarMappable
  http://matplotlib.sourceforge.net/matplotlib.colors.html#normalize

JDH

Hi,

I encounter problems with the solution below. My test case from yesterday
was really not a 'test case' because both images had near identical
values. Thus, the auto vmin,vmax settings were the same in both images.

The problem seems to be with the type of im.norm.vmin

  In [3]: im = imshow(rand(20,20))

In [1]: im = imshow(rand(20,20))

  In [4]: im.norm.vmin
  Out[4]: 0.001056874287314713

In [2]: im.norm.vmin

In [3]: type(im.norm.vmin)
Out[3]: <type 'NoneType'>

  In [5]: im.norm.vmax
  Out[5]: 0.99817508459091187

In [4]: im.norm.vmax

In [5]: type(im.norm.vmax)
Out[5]: <type 'NoneType'>

  In [6]: newim = imshow(rand(30,30), vmin=im.norm.vmin, vmax=im.norm.vmax)

In [7]: newim = imshow(rand(30,30), vmin=im.norm.vmin, vmax=im.norm.vmax)

This works but im.norm.vmin and im.norm.vmax are not used!

I am using matplotlib-0.87.1 and Python 2.3.4 on Fedora Core 3.

Yogesh