Need to plot z at given x, y...contour? or something!

Hi, everybody:

I don't have experience with images or contours and need some help plotting
a 'z' quantity for given x,y coordinates.

What are the choices?

Here is a small sample of the data:

The first row has the i-th x-coordinate at which the field starts to have
the value [i,j].
The first column has the j-th y-coordinate at which the field starts to
have the value [i,j].

The coordinate steps are not constant, nor the same for both dimensions;
they can be anything because they come from some odd finite difference
program.

My first shot at this is getting combersome, I am hoping for a better way.

So far, because the second decimal place in the x,y coordinate is alwasy
zero, I simply turned those coordinates into integers by multiplying by ten
and truncating; then by subtracting the first value from the rest, they look
very much like matrix indeces (except for the missing ones):

Then, because I don't know any better, I broadcast the values onto another
matrix, to fill in the in-between values:

Now, I have a matrix where every i,j has its own z-value and I am supposed
to be able to plot it with ax.contourf(mymatrix)...which I can, up until
about mymatrix[:,:1900] or so, afte that, I get the following error:

Traceback (most recent call last):
  File "C:\findiff\t1.py", line 73, in <module>
    ax.contourf(full[:,:2000])
  File "C:\Python26\lib\site-packages\matplotlib\axes.py", line 7322, in
contourf
    return mcontour.QuadContourSet(self, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\contour.py", line 1106, in
__init__
    ContourSet.__init__(self, ax, *args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\contour.py", line 700, in
__init__
    self._process_args(*args, **kwargs)
  File "C:\Python26\lib\site-packages\matplotlib\contour.py", line 1130, in
_process_args
    C = _cntr.Cntr(x, y, z.filled(), _mask)
ValueError: Arguments x, y, z, mask (if present) must be 2D arrays.
x, y, z must be castable to double.

My current matrix is about 12000x5000.

Any asistance would be greatly appreciated.

Thanks,

Germán

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Need-to-plot-z-at-given-x-y-contour-or-something-tp38926.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

tricontourf() might be more what you are looking for. Another possibility is pcolor() (note that for irregularly spaced grids, pcolormesh() would not work).

Cheers!
Ben Root

···

On Fri, Sep 14, 2012 at 2:51 PM, gsal <salgerman@…287…> wrote:

Hi, everybody:

I don’t have experience with images or contours and need some help plotting

a ‘z’ quantity for given x,y coordinates.

What are the choices?

Here is a small sample of the data:

The first row has the i-th x-coordinate at which the field starts to have

the value [i,j].

The first column has the j-th y-coordinate at which the field starts to

have the value [i,j].

The coordinate steps are not constant, nor the same for both dimensions;

they can be anything because they come from some odd finite difference

program.

My first shot at this is getting combersome, I am hoping for a better way.

So far, because the second decimal place in the x,y coordinate is alwasy

zero, I simply turned those coordinates into integers by multiplying by ten

and truncating; then by subtracting the first value from the rest, they look

very much like matrix indeces (except for the missing ones):

Then, because I don’t know any better, I broadcast the values onto another

matrix, to fill in the in-between values:

Now, I have a matrix where every i,j has its own z-value and I am supposed

to be able to plot it with ax.contourf(mymatrix)…which I can, up until

about mymatrix[:,:1900] or so, afte that, I get the following error:

Traceback (most recent call last):

File “C:\findiff\t1.py”, line 73, in

ax.contourf(full[:,:2000])

File “C:\Python26\lib\site-packages\matplotlib\axes.py”, line 7322, in

contourf

return mcontour.QuadContourSet(self, *args, **kwargs)

File “C:\Python26\lib\site-packages\matplotlib\contour.py”, line 1106, in

init

ContourSet.__init__(self, ax, *args, **kwargs)

File “C:\Python26\lib\site-packages\matplotlib\contour.py”, line 700, in

init

self._process_args(*args, **kwargs)

File “C:\Python26\lib\site-packages\matplotlib\contour.py”, line 1130, in

_process_args

C = _cntr.Cntr(x, y, z.filled(), _mask)

ValueError: Arguments x, y, z, mask (if present) must be 2D arrays.

x, y, z must be castable to double.

My current matrix is about 12000x5000.

Any asistance would be greatly appreciated.

Thanks,

Germán

Huh? I don't think there is anything pcolor can handle that pcolormesh can't handle faster. In both cases, the grids must be quadrilateral, but that's all.

Eric

···

On 2012/09/14 9:00 AM, Benjamin Root wrote:

tricontourf() might be more what you are looking for. Another
possibility is pcolor() (note that for irregularly spaced grids,
pcolormesh() would not work).

Wonderful...pcolor is doing the job without processing, it takes exactly what
I already have...the n+1 values for x and y coordinates defining the
boundaries of the cells and the nxn matix itself.

pcolormesh and pcolorfast also work.

Thank you very much.

···

--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Need-to-plot-z-at-given-x-y-contour-or-something-tp38926p38930.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Clarification: pcolormesh() must have a grid of coordinates (not necessarially equally spaced).

As for pcolormesh() being able to handle anything that pcolor() can handle, I have run into situations where that was not the case. I don’t remember the details, though. I think pcolorfast() operates like that (falling back to pcolor() as a last resort).

Ben Root

···

On Fri, Sep 14, 2012 at 3:50 PM, Eric Firing <efiring@…202…> wrote:

On 2012/09/14 9:00 AM, Benjamin Root wrote:

tricontourf() might be more what you are looking for. Another

possibility is pcolor() (note that for irregularly spaced grids,

pcolormesh() would not work).

Huh? I don’t think there is anything pcolor can handle that pcolormesh

can’t handle faster. In both cases, the grids must be quadrilateral,

but that’s all.

Eric

     > tricontourf() might be more what you are looking for. Another
     > possibility is pcolor() (note that for irregularly spaced grids,
     > pcolormesh() would not work).

    Huh? I don't think there is anything pcolor can handle that pcolormesh
    can't handle faster. In both cases, the grids must be quadrilateral,
    but that's all.

    Eric

Clarification: pcolormesh() must have a grid of coordinates (not
necessarially equally spaced).

As for pcolormesh() being able to handle anything that pcolor() can
handle, I have run into situations where that was not the case. I don't
remember the details, though. I think pcolorfast() operates like that
(falling back to pcolor() as a last resort).

No, pcolorfast never falls back to pcolor. In order of fastest to slowest, it tries to use image rendering, then a variant of nonuniform image rendering, and then a quadmesh. It is a bit fussier about inputs than pcolor and pcolormesh, and does not draw lines. pcolor and pcolormesh differ in the mechanism they use (pcolor uses a PolyCollection) and in the way masked data are handled (pcolor draws nothing in masked regions).

Eric

···

On 2012/09/14 10:15 AM, Benjamin Root wrote:

On Fri, Sep 14, 2012 at 3:50 PM, Eric Firing <efiring@…202… > <mailto:efiring@…202…>> wrote:
    On 2012/09/14 9:00 AM, Benjamin Root wrote:

Ben Root