How to plot other than rectangular grid?

Hello,

I have a problem plotting data which is defined on a grid other than rectangular mesh, and would greatly appreciate any advise. My data is defined for 0.1degree grid for the state of California, and I don’t want to interpolate my data outside of the defined grid when plotting it. I used pcolormesh() function for rectangular area maps, but it only accepts rectangular grid and I was wondering if there is a simple solution to my problem.

The only solution I could find was to use scipy.interpolate,griddata() to “map” my grid to a bounding rectangular grid (bounding rectangle around CA state), but that would also interpolate my data to grid cells outside of CA state, which I don’t want to do.

Many thanks for any hints!
Masha

···

--
liukis@...1887...

When using scipy.interpolate.griddada, you could use ‘nearest’ if your data is sufficiently dense. This will ‘map’ your grid onto whatever rectangular grid leaving grid points outside the convex hull of the original grid empty. Well, not empty but nan.
If you do wish to interpolate your dada, you could mask the resulting rectangular grid post interpolation.

···


Sent from Mailbox

On Fri, Nov 21, 2014 at 2:12 AM, Maria Liukis <liukis@…1887…> wrote:

Hello,

I have a problem plotting data which is defined on a grid other than rectangular mesh, and would greatly appreciate any advise. My data is defined for 0.1degree grid for the state of California, and I don’t want to interpolate my data outside of the defined grid when plotting it. I used pcolormesh() function for rectangular area maps, but it only accepts rectangular grid and I was wondering if there is a simple solution to my problem.

The only solution I could find was to use scipy.interpolate,griddata() to “map” my grid to a bounding rectangular grid (bounding rectangle around CA state), but that would also interpolate my data to grid cells outside of CA state, which I don’t want to do.

Many thanks for any hints!

Masha

liukis@…1887…


Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE

http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

As Thomas Caswell said, check out the “tri…” functions. No need for interpolation. This question recently reappeared on Stackoverflow and was answered there as well: https://stackoverflow.com/questions/27004422/contour-imshow-plot-for-irregular-x-y-z-data

···

2014-11-21 9:15 GMT+01:00 Shahar Shani Kadmiel <kadmiel@…4600…>:

When using scipy.interpolate.griddada, you could use ‘nearest’ if your data is sufficiently dense. This will ‘map’ your grid onto whatever rectangular grid leaving grid points outside the convex hull of the original grid empty. Well, not empty but nan.
If you do wish to interpolate your dada, you could mask the resulting rectangular grid post interpolation.


Sent from Mailbox

On Fri, Nov 21, 2014 at 2:12 AM, Maria Liukis <liukis@…1887…> wrote:

Hello,

I have a problem plotting data which is defined on a grid other than rectangular mesh, and would greatly appreciate any advise. My data is defined for 0.1degree grid for the state of California, and I don’t want to interpolate my data outside of the defined grid when plotting it. I used pcolormesh() function for rectangular area maps, but it only accepts rectangular grid and I was wondering if there is a simple solution to my problem.

The only solution I could find was to use scipy.interpolate,griddata() to “map” my grid to a bounding rectangular grid (bounding rectangle around CA state), but that would also interpolate my data to grid cells outside of CA state, which I don’t want to do.

Many thanks for any hints!

Masha

liukis@…4601…


Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE

http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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


Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE

http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

Hello,

I have a problem plotting data which is defined on a grid other than
rectangular mesh, and would greatly appreciate any advise. My data is
defined for 0.1degree grid for the state of California, and I don�t
want to interpolate my data outside of the defined grid when plotting
it. I used pcolormesh() function for rectangular area maps, but it
only accepts rectangular grid and I was wondering if there is a
simple solution to my problem.

Masha,

When you say your data "is defined for a 0.1 degree grid", that makes it sound like it is on a quadrilateral grid, so there should be no problem with using pcolormesh. Is it on 0.1 degree lon by 0.1 degree lat points, but only for points within California? Then you can make a masked array with this grid for a rectangle in which the points outside California are masked, and the ones inside are set to your data values. Your X and Y inputs to pcolormesh should be 2-D arrays with the boundary values rather than the centers. It sounds like you would want to do all this via mpl_toolkits.basemap.Basemap so that you will end up with a properly proportioned and labeled map.

Maybe I am misinterpreting your description of your data, however.

Eric

···

On 2014/11/20, 7:11 PM, Maria Liukis wrote:

The only solution I could find was to use
scipy.interpolate,griddata() to �map� my grid to a bounding
rectangular grid (bounding rectangle around CA state), but that would
also interpolate my data to grid cells outside of CA state, which I
don�t want to do.

Many thanks for any hints! Masha -- liukis@...1887...

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Thank you for the suggestion, unfortunately “nearest” method for interpolation still does interpolation to some extra cells outside of my CA grid which fall within the convex hull.
I thought I check if there is existing functionality for that within matplotlib, but it seems that I have to manually “map” my grid to larger rectangular grid for plotting.

Many thanks for your response!
Masha

···

liukis@…1887…

On Nov 21, 2014, at 12:15 AM, Shahar Shani Kadmiel <kadmiel@…4191…> wrote:

When using scipy.interpolate.griddada, you could use ‘nearest’ if your data is sufficiently dense. This will ‘map’ your grid onto whatever rectangular grid leaving grid points outside the convex hull of
the original grid empty. Well, not empty but nan.
If you do wish to interpolate your dada, you could mask the resulting rectangular grid post interpolation.

Sent from Mailbox

On Fri, Nov 21, 2014 at 2:12 AM, Maria Liukis <liukis@…1887…> wrote:

Hello,

I have a problem plotting data which is defined on a grid other than rectangular mesh, and would greatly appreciate any advise. My data is defined for 0.1degree grid for the state of California, and I don’t want to interpolate my data outside of the defined
grid when plotting it. I used pcolormesh() function for rectangular area maps, but it only accepts rectangular grid and I was wondering if there is a simple solution to my problem.

The only solution I could find was to use scipy.interpolate,griddata() to “map” my grid to a bounding rectangular grid (bounding rectangle around CA state), but that would also interpolate my data to grid cells outside of CA state, which I don’t want to do.

Many thanks for any hints!
Masha

liukis@…1887…


Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk


Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net

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

Eric,

Yes, my data is exactly how you understood it. I thought, as you are suggesting, to create a masked array for rectangle that bounds state of CA, to be used with pcolormesh(). The only existing functionality that I could find is griddata(), but it also interpolates data to extra cells outside of my CA grid (even with method=‘nearest’ to extra cells within the convex hull). It looks like I have to “map” my CA grid to larger rectangular grid manually, I just wanted to check if such functionality already exists within matplotlib, numpy or scipy packages, and I am just not aware of it.

I also could plot each cell with ax.add_patch(), but would imagine that it would be much slower.

And thank you for mentioning basemap, I am using it for my maps :slight_smile:

Thank you very much for your response!
Masha

···

On Nov 21, 2014, at 6:54 AM, Eric Firing <efiring@...202...> wrote:

On 2014/11/20, 7:11 PM, Maria Liukis wrote:

Hello,

I have a problem plotting data which is defined on a grid other than
rectangular mesh, and would greatly appreciate any advise. My data is
defined for 0.1degree grid for the state of California, and I don’t
want to interpolate my data outside of the defined grid when plotting
it. I used pcolormesh() function for rectangular area maps, but it
only accepts rectangular grid and I was wondering if there is a
simple solution to my problem.

Masha,

When you say your data "is defined for a 0.1 degree grid", that makes it
sound like it is on a quadrilateral grid, so there should be no problem
with using pcolormesh. Is it on 0.1 degree lon by 0.1 degree lat
points, but only for points within California? Then you can make a
masked array with this grid for a rectangle in which the points outside
California are masked, and the ones inside are set to your data values.
Your X and Y inputs to pcolormesh should be 2-D arrays with the
boundary values rather than the centers. It sounds like you would want
to do all this via mpl_toolkits.basemap.Basemap so that you will end up
with a properly proportioned and labeled map.

Maybe I am misinterpreting your description of your data, however.

Eric

The only solution I could find was to use
scipy.interpolate,griddata() to “map” my grid to a bounding
rectangular grid (bounding rectangle around CA state), but that would
also interpolate my data to grid cells outside of CA state, which I
don’t want to do.

Many thanks for any hints! Masha -- liukis@...1887...

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

------------------------------------------------------------------------------
Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server
from Actuate! Instantly Supercharge Your Business Reports and Dashboards
with Interactivity, Sharing, Native Excel Exports, App Integration & more
Get technology previously reserved for billion-dollar corporations, FREE
http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

How many cells past the state boundary are you seeing? If it is never more than one cell past the boundary, it might be an offset issue.

···

On Fri, Nov 21, 2014 at 1:30 PM, Maria Liukis <liukis@…1887…> wrote:

Eric,

Yes, my data is exactly how you understood it. I thought, as you are suggesting, to create a masked array for rectangle that bounds state of CA, to be used with pcolormesh(). The only existing functionality that I could find is griddata(), but it also interpolates data to extra cells outside of my CA grid (even with method=‘nearest’ to extra cells within the convex hull). It looks like I have to “map” my CA grid to larger rectangular grid manually, I just wanted to check if such functionality already exists within matplotlib, numpy or scipy packages, and I am just not aware of it.

I also could plot each cell with ax.add_patch(), but would imagine that it would be much slower.

And thank you for mentioning basemap, I am using it for my maps :slight_smile:

Thank you very much for your response!

Masha

On Nov 21, 2014, at 6:54 AM, Eric Firing <efiring@…202…> wrote:

On 2014/11/20, 7:11 PM, Maria Liukis wrote:

Hello,

I have a problem plotting data which is defined on a grid other than

rectangular mesh, and would greatly appreciate any advise. My data is

defined for 0.1degree grid for the state of California, and I don’t

want to interpolate my data outside of the defined grid when plotting

it. I used pcolormesh() function for rectangular area maps, but it

only accepts rectangular grid and I was wondering if there is a

simple solution to my problem.

Masha,

When you say your data “is defined for a 0.1 degree grid”, that makes it

sound like it is on a quadrilateral grid, so there should be no problem

with using pcolormesh. Is it on 0.1 degree lon by 0.1 degree lat

points, but only for points within California? Then you can make a

masked array with this grid for a rectangle in which the points outside

California are masked, and the ones inside are set to your data values.

Your X and Y inputs to pcolormesh should be 2-D arrays with the

boundary values rather than the centers. It sounds like you would want

to do all this via mpl_toolkits.basemap.Basemap so that you will end up

with a properly proportioned and labeled map.

Maybe I am misinterpreting your description of your data, however.

Eric

The only solution I could find was to use

scipy.interpolate,griddata() to “map” my grid to a bounding

rectangular grid (bounding rectangle around CA state), but that would

also interpolate my data to grid cells outside of CA state, which I

don’t want to do.

Many thanks for any hints! Masha – liukis@…1887…


Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE

http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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


Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE

http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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


Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE

http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

Thank you for the note, but it is definitely many more extra cells than just one around the border. Especially bounding area on the east side of the state is affected the most.

Thanks,
Masha

···

On Fri, Nov 21, 2014 at 1:30 PM, Maria Liukis
<liukis@…4601…> wrote:

Eric,

Yes, my data is exactly how you understood it. I thought, as you are suggesting, to create a masked array for rectangle that bounds state of CA, to be used with pcolormesh(). The only existing functionality that I could find is griddata(), but it also interpolates
data to extra cells outside of my CA grid (even with method=‘nearest’ to extra cells within the convex hull). It looks like I have to “map” my CA grid to larger rectangular grid manually, I just wanted to check if such functionality already exists within matplotlib,
numpy or scipy packages, and I am just not aware of it.

I also could plot each cell with ax.add_patch(), but would imagine that it would be much slower.

And thank you for mentioning basemap, I am using it for my maps :slight_smile:

Thank you very much for your response!

Masha

On Nov 21, 2014, at 6:54 AM, Eric Firing <efiring@…202…> wrote:

On 2014/11/20, 7:11 PM, Maria Liukis wrote:

Hello,

I have a problem plotting data which is defined on a grid other than

rectangular mesh, and would greatly appreciate any advise. My data is

defined for 0.1degree grid for the state of California, and I don’t

want to interpolate my data outside of the defined grid when plotting

it. I used pcolormesh() function for rectangular area maps, but it

only accepts rectangular grid and I was wondering if there is a

simple solution to my problem.

Masha,

When you say your data “is defined for a 0.1 degree grid”, that makes it

sound like it is on a quadrilateral grid, so there should be no problem

with using pcolormesh. Is it on 0.1 degree lon by 0.1 degree lat

points, but only for points within California? Then you can make a

masked array with this grid for a rectangle in which the points outside

California are masked, and the ones inside are set to your data values.

Your X and Y inputs to pcolormesh should be 2-D arrays with the

boundary values rather than the centers. It sounds like you would want

to do all this via mpl_toolkits.basemap.Basemap so that you will end up

with a properly proportioned and labeled map.

Maybe I am misinterpreting your description of your data, however.

Eric

The only solution I could find was to use

scipy.interpolate,griddata() to “map” my grid to a bounding

rectangular grid (bounding rectangle around CA state), but that would

also interpolate my data to grid cells outside of CA state, which I

don’t want to do.

Many thanks for any hints! Masha – liukis@…1887…


Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE


http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net


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


Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE


http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net


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


Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server

from Actuate! Instantly Supercharge Your Business Reports and Dashboards

with Interactivity, Sharing, Native Excel Exports, App Integration & more

Get technology previously reserved for billion-dollar corporations, FREE

http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk


Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

Masha,

As suggested before, take a look at the triangular mesh functions. There are simple contour (http://matplotlib.org/examples/pylab_examples/tricontour_demo.html) and pcolor plots (http://matplotlib.org/examples/pylab_examples/tripcolor_demo.html), plus linear and cubic interpolation (http://matplotlib.org/examples/pylab_examples/tricontour_smooth_delaunay.html and http://matplotlib.org/examples/pylab_examples/tricontour_smooth_user.html). The API documentation is at http://matplotlib.org/dev/api/tri_api.html.

Ian