question about contours and clim

Hi! I have a question about contours and clim within matplotlib. I load in some files and do some processing and generate a contour plot using:

cmap=pylab.cm.jet
mycontour=pylab.contourf(x,y,z,95)#,
mycontour.set_clim(vmin=160, vmax=500)
mycbar=pylab.colorbar()
mycbar.set_clim(vmin=160, vmax=500)
pylab.xlim((17,19.6))
pylab.show()

However, the behavior is rather unexpected for me. I find that the colorbar has values rather stretched for values above the cutoff specified in clim. Also, are the values normalized between
the limits set in clim, or am I loosing a lot of dynamic range?

Thanks,
William

warming.png

william ratcliff wrote:

Hi! I have a question about contours and clim within matplotlib. I load in some files and do some processing and generate a contour plot using:

cmap=pylab.cm.jet
mycontour=pylab.contourf(x,y,z,95)#,

You don't really want 95 contour levels, do you?
Instead of using set_clim, set the contour levels you want, and I suspect everything will come out OK. E.g.,

pylab.contourf(x,y,z,pylab.linspace(160, 500, 18))

Eric

···

mycontour.set_clim(vmin=160, vmax=500)
mycbar=pylab.colorbar()
mycbar.set_clim(vmin=160, vmax=500)
pylab.xlim((17,19.6))
pylab.show()

However, the behavior is rather unexpected for me. I find that the colorbar has values rather stretched for values above the cutoff specified in clim. Also, are the values normalized between
the limits set in clim, or am I loosing a lot of dynamic range?

Thanks,
William

------------------------------------------------------------------------

------------------------------------------------------------------------

------------------------------------------------------------------------------
Crystal Reports - New Free Runtime and 30 Day Trial
Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects

------------------------------------------------------------------------

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

Here, I’ve changed the number of contours to 15 and 45 respectively–and the problem still remains. Do I need to manually set the ranges of the segments on the colorbar or something? It would seem to me that somehow the new limits are not being used in determining the boundaries of which color is used for which set of values. I should also mention that I am using a masked array for z (which is what gives rise to the white square in the bottom right corner).

Thanks,
William

···

On Mon, May 18, 2009 at 5:16 PM, Eric Firing <efiring@…202…> wrote:

william ratcliff wrote:

Hi! I have a question about contours and clim within matplotlib. I load in some files and do some processing and generate a contour plot using:

cmap=pylab.cm.jet

mycontour=pylab.contourf(x,y,z,95)#,

You don’t really want 95 contour levels, do you?

Instead of using set_clim, set the contour levels you want, and I suspect everything will come out OK. E.g.,

pylab.contourf(x,y,z,pylab.linspace(160, 500, 18))

Eric

mycontour.set_clim(vmin=160, vmax=500)

mycbar=pylab.colorbar()

mycbar.set_clim(vmin=160, vmax=500)

pylab.xlim((17,19.6))

pylab.show()

However, the behavior is rather unexpected for me. I find that the colorbar has values rather stretched for values above the cutoff specified in clim. Also, are the values normalized between

the limits set in clim, or am I loosing a lot of dynamic range?

Thanks,

William




Crystal Reports - New Free Runtime and 30 Day Trial

Check out the new simplified licensing option that enables unlimited royalty-free distribution of the report engine for externally facing server and web deployment. http://p.sf.net/sfu/businessobjects



Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

william ratcliff wrote:

Here, I've changed the number of contours to 15 and 45 respectively--and the problem still remains. Do I need to manually set the ranges of the segments on the colorbar or something? It would seem to me that somehow the new limits are not being used in determining the boundaries of which color is used for which set of values. I should also mention that I am using a masked array for z (which is what gives rise to the white square in the bottom right corner).

I was not suggesting just changing the *number* of contours, I was suggesting explicitly setting the boundaries. This is almost always a better strategy; the signature in which a number of contours is specified is intended only for quick and dirty exploration (and Matlab compatibility, which led to the overly complex set of possible signatures for contour in mpl). When contour is called as you called it, it doesn't know or care anything about clim; it finds the range of your input data and linearly spreads the requested number of values over approximately that range. (Actually, it uses a ticker to do this, so contour values will fall on reasonably nice numbers.) I suspect there is an unmasked high value that is making the auto-detected range too large. What do you get from

print z.min(), z.max()

If you don't set the clim, it is set automatically based on the contour levels; so if you set the levels, you don't need to set the clim.

Colorbar gets its information from the ContourSet object.

Eric

···

Thanks,
William

On Mon, May 18, 2009 at 5:16 PM, Eric Firing <efiring@...202... > <mailto:efiring@…202…>> wrote:

    william ratcliff wrote:

        Hi! I have a question about contours and clim within
        matplotlib. I load in some files and do some processing and
        generate a contour plot using:

        cmap=pylab.cm.jet
        mycontour=pylab.contourf(x,y,z,95)#,

    You don't really want 95 contour levels, do you?
    Instead of using set_clim, set the contour levels you want, and I
    suspect everything will come out OK. E.g.,

    pylab.contourf(x,y,z,pylab.linspace(160, 500, 18))

    Eric

        mycontour.set_clim(vmin=160, vmax=500)
        mycbar=pylab.colorbar()
        mycbar.set_clim(vmin=160, vmax=500)
        pylab.xlim((17,19.6))
        pylab.show()

        However, the behavior is rather unexpected for me. I find that
        the colorbar has values rather stretched for values above the
        cutoff specified in clim. Also, are the values normalized between
        the limits set in clim, or am I loosing a lot of dynamic range?

        Thanks,
        William