Basemap contourf question

Hello,

I am trying to create a color map that maps 18 colors across 50 levels. As an example let say I have three colors [r,g,b] and want everything between 1 an 2 to be r, 3 through 10 to be g, and 11 through 50 to be b. From what I can tell it does not seem to be possible. Currently this is what I have, but it does not seem to work as I assumed.

colorList = [[0.,0.,102./255.],[0,42./255.,217./255.],[0,110./255.,217./255.],[0,178./255.,217./255.],
            [0,212./255.,212./255.],[0,217./255.,166./255.],[0,217./255.,0],[149./255.,217./255.,0],
            [217./255.,217./255.,0],[217./255.,174./255.,0],[217./255.,131./255.,0],[217./255.,87./255.,0],
            [217./255.,0,0],[174./255.,0,0],[140./255.,0,0],[135./255.,0,0],
            [105./255.,0,0],[65./255.,0,0]]

levels = [1,2,3,4,5,6,7,8,9,10,12,15,20,25,30,35,40,50]
cmap = matplotlib.colors.ListedColormap(colorList, name = 'theColorMap', N = len(colorList))
...
m.contourf(x,y,z,cmap=cmap, levels=levels, extend='both')

If the levels array is continuous then it works as expected. With the above settings I get unexpected results, which includes 'ghost contour lines'. The data I am rendering is from a GRIB file from NOAA.

Is this possible?

Thanks,
Steve

Steve,

Could you please attach an example image of what you are seeing?

Ben Root

···

On Wed, Jul 14, 2010 at 5:52 PM, Steve McFarlin <steve@…3196…> wrote:

Hello,

I am trying to create a color map that maps 18 colors across 50 levels. As an example let say I have three colors [r,g,b] and want everything between 1 an 2 to be r, 3 through 10 to be g, and 11 through 50 to be b. From what I can tell it does not seem to be possible. Currently this is what I have, but it does not seem to work as I assumed.

colorList = [[0.,0.,102./255.],[0,42./255.,217./255.],[0,110./255.,217./255.],[0,178./255.,217./255.],

        [0,212./255.,212./255.],[0,217./255.,166./255.],[0,217./255.,0],[149./255.,217./255.,0],

        [217./255.,217./255.,0],[217./255.,174./255.,0],[217./255.,131./255.,0],[217./255.,87./255.,0],

        [217./255.,0,0],[174./255.,0,0],[140./255.,0,0],[135./255.,0,0],

        [105./255.,0,0],[65./255.,0,0]]

levels = [1,2,3,4,5,6,7,8,9,10,12,15,20,25,30,35,40,50]

cmap = matplotlib.colors.ListedColormap(colorList, name = ‘theColorMap’, N = len(colorList))

m.contourf(x,y,z,cmap=cmap, levels=levels, extend=‘both’)

If the levels array is continuous then it works as expected. With the above settings I get unexpected results, which includes ‘ghost contour lines’. The data I am rendering is from a GRIB file from NOAA.

Is this possible?

Thanks,

Steve


This SF.net email is sponsored by Sprint

What will you do first with EVO, the first 4G phone?

Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

Ben -

You can see the image at http://www.surfguru.com/smc/TestRender.png . With a continuous level array [1 … 18] the image looks like http://www.surfguru.com/smc/TestRender2.png

Thanks,

Steve

···

On Jul 14, 2010, at 4:12 PM, Benjamin Root wrote:

Steve,

Could you please attach an example image of what you are seeing?

Ben Root

On Wed, Jul 14, 2010 at 5:52 PM, Steve McFarlin <steve@…3196…> wrote:

Hello,

I am trying to create a color map that maps 18 colors across 50 levels. As an example let say I have three colors [r,g,b] and want everything between 1 an 2 to be r, 3 through 10 to be g, and 11 through 50 to be b. From what I can tell it does not seem to be possible. Currently this is what I have, but it does not seem to work as I assumed.

colorList = [[0.,0.,102./255.],[0,42./255.,217./255.],[0,110./255.,217./255.],[0,178./255.,217./255.],

        [0,212./255.,212./255.],[0,217./255.,166./255.],[0,217./255.,0],[149./255.,217./255.,0],

        [217./255.,217./255.,0],[217./255.,174./255.,0],[217./255.,131./255.,0],[217./255.,87./255.,0],

        [217./255.,0,0],[174./255.,0,0],[140./255.,0,0],[135./255.,0,0],

        [105./255.,0,0],[65./255.,0,0]]

levels = [1,2,3,4,5,6,7,8,9,10,12,15,20,25,30,35,40,50]

cmap = matplotlib.colors.ListedColormap(colorList, name = ‘theColorMap’, N = len(colorList))

m.contourf(x,y,z,cmap=cmap, levels=levels, extend=‘both’)

If the levels array is continuous then it works as expected. With the above settings I get unexpected results, which includes ‘ghost contour lines’. The data I am rendering is from a GRIB file from NOAA.

Is this possible?

Thanks,

Steve


This SF.net email is sponsored by Sprint

What will you do first with EVO, the first 4G phone?

Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

Steve,

The ghost lines appear to be an artifact of the anti-aliasing. In my tests, setting antialiased=False eliminates those lines.

The colormap looks fine to me. If you doubt it, try turning on the colorbar to see if the values are correctly associated with the proper colors.

Ben Root

···

On Wed, Jul 14, 2010 at 6:24 PM, Steve McFarlin <steve@…3196…> wrote:

Ben -

You can see the image at http://www.surfguru.com/smc/TestRender.png . With a continuous level array [1 … 18] the image looks like http://www.surfguru.com/smc/TestRender2.png

Thanks,

Steve

On Jul 14, 2010, at 4:12 PM, Benjamin Root wrote:

Steve,

Could you please attach an example image of what you are seeing?

Ben Root

On Wed, Jul 14, 2010 at 5:52 PM, Steve McFarlin <steve@…3196…> wrote:

Hello,

I am trying to create a color map that maps 18 colors across 50 levels. As an example let say I have three colors [r,g,b] and want everything between 1 an 2 to be r, 3 through 10 to be g, and 11 through 50 to be b. From what I can tell it does not seem to be possible. Currently this is what I have, but it does not seem to work as I assumed.

colorList = [[0.,0.,102./255.],[0,42./255.,217./255.],[0,110./255.,217./255.],[0,178./255.,217./255.],

        [0,212./255.,212./255.],[0,217./255.,166./255.],[0,217./255.,0],[149./255.,217./255.,0],

        [217./255.,217./255.,0],[217./255.,174./255.,0],[217./255.,131./255.,0],[217./255.,87./255.,0],

        [217./255.,0,0],[174./255.,0,0],[140./255.,0,0],[135./255.,0,0],

        [105./255.,0,0],[65./255.,0,0]]

levels = [1,2,3,4,5,6,7,8,9,10,12,15,20,25,30,35,40,50]

cmap = matplotlib.colors.ListedColormap(colorList, name = ‘theColorMap’, N = len(colorList))

m.contourf(x,y,z,cmap=cmap, levels=levels, extend=‘both’)

If the levels array is continuous then it works as expected. With the above settings I get unexpected results, which includes ‘ghost contour lines’. The data I am rendering is from a GRIB file from NOAA.

Is this possible?

Thanks,

Steve


This SF.net email is sponsored by Sprint

What will you do first with EVO, the first 4G phone?

Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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


This SF.net email is sponsored by Sprint

What will you do first with EVO, the first 4G phone?

Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

Ben -

I got ahead of myself my cropping the image. The color mapping is correct. It is just different then what I expected. I thought it would partition the height field data based on the levels array and index into the color array. Turning off antialiasing did not solve the ‘ghost lines’. I will play around with some of the arguments. It looks to me as if contour is being called with a line width of 1 and a color of white. Setting these line width to 0 did not make a difference.

Thanks,

Steve

···

On Jul 14, 2010, at 5:24 PM, Benjamin Root wrote:

Steve,

The ghost lines appear to be an artifact of the anti-aliasing. In my tests, setting antialiased=False eliminates those lines.

The colormap looks fine to me. If you doubt it, try turning on the colorbar to see if the values are correctly associated with the proper colors.

Ben Root

On Wed, Jul 14, 2010 at 6:24 PM, Steve McFarlin <steve@…3196…> wrote:

Ben -

You can see the image at http://www.surfguru.com/smc/TestRender.png . With a continuous level array [1 … 18] the image looks like http://www.surfguru.com/smc/TestRender2.png

Thanks,

Steve

On Jul 14, 2010, at 4:12 PM, Benjamin Root wrote:

Steve,

Could you please attach an example image of what you are seeing?

Ben Root

On Wed, Jul 14, 2010 at 5:52 PM, Steve McFarlin <steve@…3196…> wrote:

Hello,

I am trying to create a color map that maps 18 colors across 50 levels. As an example let say I have three colors [r,g,b] and want everything between 1 an 2 to be r, 3 through 10 to be g, and 11 through 50 to be b. From what I can tell it does not seem to be possible. Currently this is what I have, but it does not seem to work as I assumed.

colorList = [[0.,0.,102./255.],[0,42./255.,217./255.],[0,110./255.,217./255.],[0,178./255.,217./255.],

        [0,212./255.,212./255.],[0,217./255.,166./255.],[0,217./255.,0],[149./255.,217./255.,0],

        [217./255.,217./255.,0],[217./255.,174./255.,0],[217./255.,131./255.,0],[217./255.,87./255.,0],

        [217./255.,0,0],[174./255.,0,0],[140./255.,0,0],[135./255.,0,0],

        [105./255.,0,0],[65./255.,0,0]]

levels = [1,2,3,4,5,6,7,8,9,10,12,15,20,25,30,35,40,50]

cmap = matplotlib.colors.ListedColormap(colorList, name = ‘theColorMap’, N = len(colorList))

m.contourf(x,y,z,cmap=cmap, levels=levels, extend=‘both’)

If the levels array is continuous then it works as expected. With the above settings I get unexpected results, which includes ‘ghost contour lines’. The data I am rendering is from a GRIB file from NOAA.

Is this possible?

Thanks,

Steve


This SF.net email is sponsored by Sprint

What will you do first with EVO, the first 4G phone?

Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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


This SF.net email is sponsored by Sprint

What will you do first with EVO, the first 4G phone?

Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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


This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Steve,

Which backend are you using? For TkAgg, this works:

m.contourf(x, y, z, levels=levels, cmap=cmap, antialiased=False)

Ben Root

···

On Wed, Jul 14, 2010 at 8:00 PM, Steve McFarlin <steve@…3196…> wrote:

Ben -

I got ahead of myself my cropping the image. The color mapping is correct. It is just different then what I expected. I thought it would partition the height field data based on the levels array and index into the color array. Turning off antialiasing did not solve the ‘ghost lines’. I will play around with some of the arguments. It looks to me as if contour is being called with a line width of 1 and a color of white. Setting these line width to 0 did not make a difference.

Thanks,

Steve

On Jul 14, 2010, at 5:24 PM, Benjamin Root wrote:

Steve,

The ghost lines appear to be an artifact of the anti-aliasing. In my tests, setting antialiased=False eliminates those lines.

The colormap looks fine to me. If you doubt it, try turning on the colorbar to see if the values are correctly associated with the proper colors.

Ben Root

On Wed, Jul 14, 2010 at 6:24 PM, Steve McFarlin <steve@…3196…> wrote:

Ben -

You can see the image at http://www.surfguru.com/smc/TestRender.png . With a continuous level array [1 … 18] the image looks like http://www.surfguru.com/smc/TestRender2.png

Thanks,

Steve

On Jul 14, 2010, at 4:12 PM, Benjamin Root wrote:

Steve,

Could you please attach an example image of what you are seeing?

Ben Root

On Wed, Jul 14, 2010 at 5:52 PM, Steve McFarlin <steve@…3196…> wrote:

Hello,

I am trying to create a color map that maps 18 colors across 50 levels. As an example let say I have three colors [r,g,b] and want everything between 1 an 2 to be r, 3 through 10 to be g, and 11 through 50 to be b. From what I can tell it does not seem to be possible. Currently this is what I have, but it does not seem to work as I assumed.

colorList = [[0.,0.,102./255.],[0,42./255.,217./255.],[0,110./255.,217./255.],[0,178./255.,217./255.],

        [0,212./255.,212./255.],[0,217./255.,166./255.],[0,217./255.,0],[149./255.,217./255.,0],

        [217./255.,217./255.,0],[217./255.,174./255.,0],[217./255.,131./255.,0],[217./255.,87./255.,0],

        [217./255.,0,0],[174./255.,0,0],[140./255.,0,0],[135./255.,0,0],

        [105./255.,0,0],[65./255.,0,0]]

levels = [1,2,3,4,5,6,7,8,9,10,12,15,20,25,30,35,40,50]

cmap = matplotlib.colors.ListedColormap(colorList, name = ‘theColorMap’, N = len(colorList))

m.contourf(x,y,z,cmap=cmap, levels=levels, extend=‘both’)

If the levels array is continuous then it works as expected. With the above settings I get unexpected results, which includes ‘ghost contour lines’. The data I am rendering is from a GRIB file from NOAA.

Is this possible?

Thanks,

Steve


This SF.net email is sponsored by Sprint

What will you do first with EVO, the first 4G phone?

Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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


This SF.net email is sponsored by Sprint

What will you do first with EVO, the first 4G phone?

Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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


This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?

Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first_______________________________________________

Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hello,

I am trying to create a color map that maps 18 colors across 50 levels. As an example let say I have three colors [r,g,b] and want everything between 1 an 2 to be r, 3 through 10 to be g, and 11 through 50 to be b. From what I can tell it does not seem to be possible. Currently this is what I have, but it does not seem to work as I assumed.

colorList = [[0.,0.,102./255.],[0,42./255.,217./255.],[0,110./255.,217./255.],[0,178./255.,217./255.],
             [0,212./255.,212./255.],[0,217./255.,166./255.],[0,217./255.,0],[149./255.,217./255.,0],
             [217./255.,217./255.,0],[217./255.,174./255.,0],[217./255.,131./255.,0],[217./255.,87./255.,0],
             [217./255.,0,0],[174./255.,0,0],[140./255.,0,0],[135./255.,0,0],
             [105./255.,0,0],[65./255.,0,0]]

levels = [1,2,3,4,5,6,7,8,9,10,12,15,20,25,30,35,40,50]
cmap = matplotlib.colors.ListedColormap(colorList, name = 'theColorMap', N = len(colorList))
...
m.contourf(x,y,z,cmap=cmap, levels=levels, extend='both')

If the levels array is continuous then it works as expected. With the above settings I get unexpected results, which includes 'ghost contour lines'. The data I am rendering is from a GRIB file from NOAA.

I think there is some confusion of terminology here, and the "ghost contour lines" are the least of your problems.

The contourf "levels" are giving boundaries of regions, so with 18 levels, you have 17 regions.

I suspect that what you want is illustrated by the attached extremely simple example. (You may or may not want to use the spacing kwarg to colorbar.)

Eric

contourf_boundary_norm.py (428 Bytes)

···

On 07/14/2010 12:52 PM, Steve McFarlin wrote:

Is this possible?

Thanks,
Steve
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

Ben -

The problem is occurring on os-x. I am a version behind on the libraries on this machine. With the latest libraries (installed a few days ago on debian) this problem does not occur with the agg backend. I think it is time to sit down and learn the library rather then hack at it. Thanks for your help.

Steve

···

On Jul 14, 2010, at 6:17 PM, Benjamin Root wrote:

Steve,

Which backend are you using? For TkAgg, this works:

m.contourf(x, y, z, levels=levels, cmap=cmap, antialiased=False)

Ben Root

On Wed, Jul 14, 2010 at 8:00 PM, Steve McFarlin <steve@…3196…> wrote:

Ben -

I got ahead of myself my cropping the image. The color mapping is correct. It is just different then what I expected. I thought it would partition the height field data based on the levels array and index into the color array. Turning off antialiasing did not solve the ‘ghost lines’. I will play around with some of the arguments. It looks to me as if contour is being called with a line width of 1 and a color of white. Setting these line width to 0 did not make a difference.

Thanks,

Steve

On Jul 14, 2010, at 5:24 PM, Benjamin Root wrote:

Steve,

The ghost lines appear to be an artifact of the anti-aliasing. In my tests, setting antialiased=False eliminates those lines.

The colormap looks fine to me. If you doubt it, try turning on the colorbar to see if the values are correctly associated with the proper colors.

Ben Root

On Wed, Jul 14, 2010 at 6:24 PM, Steve McFarlin <steve@…3196…> wrote:

Ben -

You can see the image at http://www.surfguru.com/smc/TestRender.png . With a continuous level array [1 … 18] the image looks like http://www.surfguru.com/smc/TestRender2.png

Thanks,

Steve

On Jul 14, 2010, at 4:12 PM, Benjamin Root wrote:

Steve,

Could you please attach an example image of what you are seeing?

Ben Root

On Wed, Jul 14, 2010 at 5:52 PM, Steve McFarlin <steve@…3196…> wrote:

Hello,

I am trying to create a color map that maps 18 colors across 50 levels. As an example let say I have three colors [r,g,b] and want everything between 1 an 2 to be r, 3 through 10 to be g, and 11 through 50 to be b. From what I can tell it does not seem to be possible. Currently this is what I have, but it does not seem to work as I assumed.

colorList = [[0.,0.,102./255.],[0,42./255.,217./255.],[0,110./255.,217./255.],[0,178./255.,217./255.],

        [0,212./255.,212./255.],[0,217./255.,166./255.],[0,217./255.,0],[149./255.,217./255.,0],

        [217./255.,217./255.,0],[217./255.,174./255.,0],[217./255.,131./255.,0],[217./255.,87./255.,0],

        [217./255.,0,0],[174./255.,0,0],[140./255.,0,0],[135./255.,0,0],

        [105./255.,0,0],[65./255.,0,0]]

levels = [1,2,3,4,5,6,7,8,9,10,12,15,20,25,30,35,40,50]

cmap = matplotlib.colors.ListedColormap(colorList, name = ‘theColorMap’, N = len(colorList))

m.contourf(x,y,z,cmap=cmap, levels=levels, extend=‘both’)

If the levels array is continuous then it works as expected. With the above settings I get unexpected results, which includes ‘ghost contour lines’. The data I am rendering is from a GRIB file from NOAA.

Is this possible?

Thanks,

Steve


This SF.net email is sponsored by Sprint

What will you do first with EVO, the first 4G phone?

Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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


This SF.net email is sponsored by Sprint

What will you do first with EVO, the first 4G phone?

Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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


This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?

Visit sprint.com/firsthttp://p.sf.net/sfu/sprint-com-first_______________________________________________

Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Eric -

Thank you very much. This is exactly what I was looking to do. I should have realized the levels are boundaries, and my color array was not matched to the number of regions. The need for BoundaryNorm makes total sense. Time to stop blindly hacking. Thanks for your example script.

- steve

···

On Jul 14, 2010, at 6:18 PM, Eric Firing wrote:

On 07/14/2010 12:52 PM, Steve McFarlin wrote:

Hello,

I am trying to create a color map that maps 18 colors across 50 levels. As an example let say I have three colors [r,g,b] and want everything between 1 an 2 to be r, 3 through 10 to be g, and 11 through 50 to be b. From what I can tell it does not seem to be possible. Currently this is what I have, but it does not seem to work as I assumed.

colorList = [[0.,0.,102./255.],[0,42./255.,217./255.],[0,110./255.,217./255.],[0,178./255.,217./255.],
            [0,212./255.,212./255.],[0,217./255.,166./255.],[0,217./255.,0],[149./255.,217./255.,0],
            [217./255.,217./255.,0],[217./255.,174./255.,0],[217./255.,131./255.,0],[217./255.,87./255.,0],
            [217./255.,0,0],[174./255.,0,0],[140./255.,0,0],[135./255.,0,0],
            [105./255.,0,0],[65./255.,0,0]]

levels = [1,2,3,4,5,6,7,8,9,10,12,15,20,25,30,35,40,50]
cmap = matplotlib.colors.ListedColormap(colorList, name = 'theColorMap', N = len(colorList))
...
m.contourf(x,y,z,cmap=cmap, levels=levels, extend='both')

If the levels array is continuous then it works as expected. With the above settings I get unexpected results, which includes 'ghost contour lines'. The data I am rendering is from a GRIB file from NOAA.

I think there is some confusion of terminology here, and the "ghost contour lines" are the least of your problems.

The contourf "levels" are giving boundaries of regions, so with 18 levels, you have 17 regions.

I suspect that what you want is illustrated by the attached extremely simple example. (You may or may not want to use the spacing kwarg to colorbar.)

Eric

Is this possible?

Thanks,
Steve
------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options

<contourf_boundary_norm.py>------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options