Plotting difference between contourf and pcolor

When plotting the same ocean data with contourf or pcolor I noticed a
difference at the edge between ocean area and the land where there is no
data. Basically, contourf is trimming from the edge and when using basemap
you can see the underlying fill color. Is this normal behaviour or am I
doing something wrong?

I've attached 2 images to show exactly what is happening.

Thanks,
Anton

http://www.nabble.com/file/p21397184/img_contourf.png img_contourf.png
http://www.nabble.com/file/p21397184/img_pcolor.png img_pcolor.png

···

--
View this message in context: http://www.nabble.com/Plotting-difference-between-contourf-and-pcolor-tp21397184p21397184.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

antonv wrote:

When plotting the same ocean data with contourf or pcolor I noticed a
difference at the edge between ocean area and the land where there is no
data. Basically, contourf is trimming from the edge and when using basemap
you can see the underlying fill color. Is this normal behaviour or am I
doing something wrong?

I've attached 2 images to show exactly what is happening.

Thanks,
Anton

http://www.nabble.com/file/p21397184/img_contourf.png img_contourf.png http://www.nabble.com/file/p21397184/img_pcolor.png img_pcolor.png
  

Anton: Contourf and pcolor deal with missing values in masked arrays differently, so yes - I think this is normal behavior.

-Jeff

Ok. Then what do you think would be the best way to have a smooth graph like
the contourf but with the data shown by pcolor? The best of both worlds in
other words :slight_smile:

Thanks,
Anton

Jeff Whitaker wrote:

···

antonv wrote:

When plotting the same ocean data with contourf or pcolor I noticed a
difference at the edge between ocean area and the land where there is no
data. Basically, contourf is trimming from the edge and when using
basemap
you can see the underlying fill color. Is this normal behaviour or am I
doing something wrong?

I've attached 2 images to show exactly what is happening.

Thanks,
Anton

http://www.nabble.com/file/p21397184/img_contourf.png img_contourf.png
http://www.nabble.com/file/p21397184/img_pcolor.png img_pcolor.png
  

Anton: Contourf and pcolor deal with missing values in masked arrays
differently, so yes - I think this is normal behavior.

-Jeff

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
View this message in context: http://www.nabble.com/Plotting-difference-between-contourf-and-pcolor-tp21397184p21400596.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

antonv wrote:

Ok. Then what do you think would be the best way to have a smooth graph like
the contourf but with the data shown by pcolor? The best of both worlds in
other words :slight_smile:

Thanks,
Anton

Anton,

The other thing to bear in mind is that with contourf, you are specifying the data values at grid points, and the algorithm is essentially interpolating to calculate the boundaries of polygons for which the data are between two adjacent contour levels; with pcolor you are specifying the boundaries of a grid, and your data values determine the colors of those rectangles (or more generally, quadrilaterals). That is, with pcolor your data value, Zij, determines the color of the box with corners at Xij,Yij and Xi+1 j+1, Yi+1 j+1.

Eric

···

Jeff Whitaker wrote:

antonv wrote:

When plotting the same ocean data with contourf or pcolor I noticed a
difference at the edge between ocean area and the land where there is no
data. Basically, contourf is trimming from the edge and when using
basemap
you can see the underlying fill color. Is this normal behaviour or am I
doing something wrong?

I've attached 2 images to show exactly what is happening.

Thanks,
Anton

http://www.nabble.com/file/p21397184/img_contourf.png img_contourf.png http://www.nabble.com/file/p21397184/img_pcolor.png img_pcolor.png
  

Anton: Contourf and pcolor deal with missing values in masked arrays differently, so yes - I think this is normal behavior.

-Jeff

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Thanks for the explanation Eric. Now it makes sense. As pcolor does not allow
interpolation, my last chance is to use imshow but that creates another
issue as it allows only one argument (z) not 3 (x,y,z) as pcolor or contourf
and it will display the whole dataset instead of the zoomed area. Is there a
way to have it display just a region?

Another way that I could be able to solve my issue is by overlapping the
contourf ovet the pcolor graph. Is there a way to do that when I have the
commands one after the other, the last one clears the previous?

Thanks,
Anton

efiring wrote:

···

antonv wrote:

Ok. Then what do you think would be the best way to have a smooth graph
like
the contourf but with the data shown by pcolor? The best of both worlds
in
other words :slight_smile:

Thanks,
Anton

Anton,

The other thing to bear in mind is that with contourf, you are
specifying the data values at grid points, and the algorithm is
essentially interpolating to calculate the boundaries of polygons for
which the data are between two adjacent contour levels; with pcolor you
are specifying the boundaries of a grid, and your data values determine
the colors of those rectangles (or more generally, quadrilaterals).
That is, with pcolor your data value, Zij, determines the color of the
box with corners at Xij,Yij and Xi+1 j+1, Yi+1 j+1.

Eric

Jeff Whitaker wrote:

antonv wrote:

When plotting the same ocean data with contourf or pcolor I noticed a
difference at the edge between ocean area and the land where there is
no
data. Basically, contourf is trimming from the edge and when using
basemap
you can see the underlying fill color. Is this normal behaviour or am I
doing something wrong?

I've attached 2 images to show exactly what is happening.

Thanks,
Anton

http://www.nabble.com/file/p21397184/img_contourf.png img_contourf.png
http://www.nabble.com/file/p21397184/img_pcolor.png img_pcolor.png
  

Anton: Contourf and pcolor deal with missing values in masked arrays
differently, so yes - I think this is normal behavior.

-Jeff

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
View this message in context: http://www.nabble.com/Plotting-difference-between-contourf-and-pcolor-tp21397184p21403657.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

antonv wrote:

Thanks for the explanation Eric. Now it makes sense. As pcolor does not allow
interpolation, my last chance is to use imshow but that creates another
issue as it allows only one argument (z) not 3 (x,y,z) as pcolor or contourf
and it will display the whole dataset instead of the zoomed area. Is there a
way to have it display just a region?

Yes, just set the view limits, the same as for contourf or pcolor. You use the extent kwarg to effectively define the x and y grid, but that grid must be uniform and rectangular. See http://matplotlib.sourceforge.net/examples/pylab_examples/image_masked.html

Another way that I could be able to solve my issue is by overlapping the
contourf ovet the pcolor graph. Is there a way to do that when I have the
commands one after the other, the last one clears the previous?

Yes, with matplotlib you can plot just about anything on top of anything else--but why would you want to in this case? It doesn't make sense to me. What is wrong with your original contourf version? (It looks to me like there is something odd about the combination of color map and contour levels--are you using a normal color map with 256 values? And, it looks like maybe you want something other than the lowest colormap value for the no-data regions; the image_masked example above shows how you can get that using the set_bad method of the colormap.)

Eric

···

Thanks,
Anton

efiring wrote:

antonv wrote:

Ok. Then what do you think would be the best way to have a smooth graph
like
the contourf but with the data shown by pcolor? The best of both worlds
in
other words :slight_smile:

Thanks,
Anton

Anton,

The other thing to bear in mind is that with contourf, you are specifying the data values at grid points, and the algorithm is essentially interpolating to calculate the boundaries of polygons for which the data are between two adjacent contour levels; with pcolor you are specifying the boundaries of a grid, and your data values determine the colors of those rectangles (or more generally, quadrilaterals). That is, with pcolor your data value, Zij, determines the color of the box with corners at Xij,Yij and Xi+1 j+1, Yi+1 j+1.

Eric

Jeff Whitaker wrote:

antonv wrote:

When plotting the same ocean data with contourf or pcolor I noticed a
difference at the edge between ocean area and the land where there is
no
data. Basically, contourf is trimming from the edge and when using
basemap
you can see the underlying fill color. Is this normal behaviour or am I
doing something wrong?

I've attached 2 images to show exactly what is happening.

Thanks,
Anton

http://www.nabble.com/file/p21397184/img_contourf.png img_contourf.png http://www.nabble.com/file/p21397184/img_pcolor.png img_pcolor.png
  

Anton: Contourf and pcolor deal with missing values in masked arrays differently, so yes - I think this is normal behavior.

-Jeff

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

------------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It is the best place to buy or sell services for
just about anything Open Source.
http://p.sf.net/sfu/Xq1LFB
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users