Matplotlib-users Digest, Vol 102, Issue 39

@MariaLukis, I had to go through contortions to plot an arbitrary quadrilateral mesh, in 3D. I resolved it by storing every line plotted and retracing the best set to take me to the starting point of the quad I was plotting. It would have been much easier if I had the function of lifting my pen and move while not plotting. But then I did not know how to get intpo matplotlib to perform what is a simple mod.

···

On Fri, Nov 21, 2014 at 6:54 AM, <matplotlib-users-request@…1064…t> wrote:

Send Matplotlib-users mailing list submissions to

    matplotlib-users@lists.sourceforge.net

To subscribe or unsubscribe via the World Wide Web, visit

    [https://lists.sourceforge.net/lists/listinfo/matplotlib-users](https://lists.sourceforge.net/lists/listinfo/matplotlib-users)

or, via email, send a message with subject or body ‘help’ to

    matplotlib-users-request@lists.sourceforge.net

You can reach the person managing the list at

    matplotlib-users-owner@lists.sourceforge.net

When replying, please edit your Subject line so it is more specific

than “Re: Contents of Matplotlib-users digest…”

Today’s Topics:

  1. How to plot other than rectangular grid? (Maria Liukis)

  2. Re: How to plot other than rectangular grid? (Thomas Caswell)

  3. Re: How to plot other than rectangular grid?

    (Shahar Shani Kadmiel)

  4. Re: How to plot other than rectangular grid? (Oliver)

  5. Re: How to plot other than rectangular grid? (Eric Firing)


Message: 1

Date: Fri, 21 Nov 2014 00:11:31 +0000

From: Maria Liukis <liukis@…4271…>

Subject: [Matplotlib-users] How to plot other than rectangular grid?

To: “matplotlib-users@lists.sourceforge.net

    <matplotlib-users@lists.sourceforge.net>

Message-ID: <50316610-BE5C-45B1-9BD4-74438FF93662@…1887…>

Content-Type: text/plain; charset=“Windows-1252”

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…


Message: 2

Date: Fri, 21 Nov 2014 04:38:21 +0000

From: Thomas Caswell <tcaswell@…83…287…>

Subject: Re: [Matplotlib-users] How to plot other than rectangular

    grid?

To: Maria Liukis <liukis@…1887…>,

    "matplotlib-users@lists.sourceforge.net"

    <matplotlib-users@lists.sourceforge.net>

Message-ID:

    <CAA48SF86omwetH6jxKDbqo++TW=JUwt8MCnwhHuJ9RVHST14pQ@...288...>

Content-Type: text/plain; charset=“utf-8”

There are also triangular mesh plotting (I think tricolormesh is the

function name).

The really brute force solution is to use poly collection and draw what

ever shape you want.

Tom

-------------- next part --------------

An HTML attachment was scrubbed…


Message: 3

Date: Fri, 21 Nov 2014 00:15:58 -0800 (PST)

From: “Shahar Shani Kadmiel” <kadmiel@…4191…>

Subject: Re: [Matplotlib-users] How to plot other than rectangular

    grid?

To: “Maria Liukis” <liukis@…1887…>

Cc: matplotlib-users@lists.sourceforge.net

Message-ID: <1416557758097.b2298d67@…4515…>

Content-Type: text/plain; charset=“utf-8”

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

-------------- next part --------------

An HTML attachment was scrubbed…


Message: 4

Date: Fri, 21 Nov 2014 14:13:03 +0100

From: Oliver <oliver.willekens@…287…>

Subject: Re: [Matplotlib-users] How to plot other than rectangular

    grid?

To: Shahar Shani Kadmiel <kadmiel@…4191…>

Cc: “matplotlib-users@lists.sourceforge.net

    <matplotlib-users@lists.sourceforge.net>

Message-ID:

    <CAEqQaNBqU4dDxQD0PTQXh=J23A4Q1CQU_qAZKjZ3ipBJ8neMbg@...1737......>

Content-Type: text/plain; charset=“utf-8”

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@…4191…>:

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 <https://www.dropbox.com/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


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

-------------- next part --------------

An HTML attachment was scrubbed…


Message: 5

Date: Fri, 21 Nov 2014 09:54:29 -0500

From: Eric Firing <efiring@…2543…>

Subject: Re: [Matplotlib-users] How to plot other than rectangular

    grid?

To: matplotlib-users@lists.sourceforge.net

Message-ID: <546F5225.9050107@…202…>

Content-Type: text/plain; charset=windows-1252; format=flowed

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

End of Matplotlib-users Digest, Vol 102, Issue 39


First off, pcolormesh will happily plot arbitrary quadrilateral meshes, so long as you can describe the points in a regular manner. For example:

import matplotlib.pyplot as plt
import numpy as np

shape = (10, 10)
y, x = np.mgrid[:shape[0], :shape[1]]

Distort the grid so that it’s no longer regular

x = x + np.random.normal(0, 0.2, shape)
y = y + np.random.normal(0, 0.2, shape)

z = np.random.random(shape)

fig, ax = plt.subplots()
ax.pcolormesh(x, y, z)
plt.show()

figure_1.png

​Also, “lifting the pen while not plotting” is the basis of how paths are handled in matplotlib. Normally, you wouldn’t drop down to this lower-level API very often, but it underpins a lot of higher-level matplotlib artists. For example, let’s draw 4 squares with one path:

import matplotlib.pyplot as plt
from matplotlib.path import Path
from matplotlib.patches import PathPatch

codes = Path.LINETO * np.ones(5, dtype=np.uint8)
codes[0] = Path.MOVETO

x = np.array([0, 1, 1, 0, 0])
y = np.array([0, 0, 1, 1, 0])

numsquares = 4
x = np.hstack([x + 2i for i in range(numsquares)])
y = np.hstack([y + 2
i for i in range(numsquares)])
codes = np.hstack(numsquares * [codes])

path = Path(np.c_[x, y], codes)
patch = PathPatch(path, facecolor=‘red’)

fig, ax = plt.subplots()
ax.add_patch(patch)
ax.autoscale()

ax.axis(‘equal’)
ax.margins(0.05)
plt.show()

figure_1.png

​Hopefully those examples help a bit (or at least give food for thought).

Cheers,

-Joe