# plotting scattered data from array

I'm trying again to understand how to plot scattered data from array into
contour graph.
I looked at
http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data
and I understand I have to grid my data. However, in most samples the plot
is of a function.
Let's say I want to plot some geological data, suppose water table head, and
I have the following 3D aray
(1, 0, 13),
(2, 0, 11),
(3, 0, 12),
(1, 2, 11))
matplotlib has lot's of restrictions about how I can plot and interpolate
the data, which causes a lot of confusion in my side...
I'll be happy if someone could supply me a clue of how to plot contours of
data which comes in arrays or raster format and not an equation.
Thanks,
Oz

Try something like this:

import pylab as pl

(1, 0, 13),
(2, 0, 11),
(3, 0, 12),
(1, 2, 11))

xi, yi = pl.arange(0, 4, 0.1), pl.arange(0, 3, 0.1)
g = pl.griddata(x, y, z, xi, yi)
pl.scatter(x, y)
pl.contour(xi, yi, g)

Level values are automatically chosen in this example but you can
provide the number of values or a sequence of them.

Note that no extrapolation is done outside convex hull defined by input
data.

Goyo

···

El sáb, 20-09-2008 a las 11:13 +0200, Oz Nahum escribió:

I'm trying again to understand how to plot scattered data from array into
contour graph.
I looked at
http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data
and I understand I have to grid my data. However, in most samples the plot
is of a function.
Let's say I want to plot some geological data, suppose water table head, and
I have the following 3D aray
(1, 0, 13),
(2, 0, 11),
(3, 0, 12),
(1, 2, 11))
matplotlib has lot's of restrictions about how I can plot and interpolate
the data, which causes a lot of confusion in my side...
I'll be happy if someone could supply me a clue of how to plot contours of
data which comes in arrays or raster format and not an equation.
Thanks,
Oz

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Hi,
This indeed does the job. But after playing a little bit with the code, I have discovered a few things:
first, I’d rather work with lists not tuples so I could actually change my huge array of points.

second the array I described is kind of a pseudo 2D:
It has one big row.

``````   [1,    0,    13],

[2,    0,    11],

[3,    0,    12],

[1,    2,    11]]
``````

When I try to use a 3D array, with rows and columns

import pylab as pl

head = [[[0, 0, 10], [0, 1, 13]],
[[1, 0, 11], [1, 1, 12]],

``````       [[2,    1,    11],   [2,    2,    14]]]
``````

xi, yi = pl.arange(0, 4, 0.1), pl.arange(0, 3, 0.1)
g = pl.griddata(x, y, z, xi, yi)
pl.scatter(x, y)
pl.contour(xi, yi, g)
pl.show()

I get this error:
Traceback (most recent call last):
File “asfplot.py”, line 9, in
ValueError: need more than 2 values to unpack

···

On Sat, Sep 20, 2008 at 2:19 PM, Goyo <goyodiaz@…287…> wrote:

Try something like this:

import pylab as pl

``````    (1,    0,    13),

(2,    0,    11),

(3,    0,    12),

(1,    2,    11))
``````

xi, yi = pl.arange(0, 4, 0.1), pl.arange(0, 3, 0.1)

g = pl.griddata(x, y, z, xi, yi)

pl.scatter(x, y)

pl.contour(xi, yi, g)

Level values are automatically chosen in this example but you can

provide the number of values or a sequence of them.

Note that no extrapolation is done outside convex hull defined by input

data.

Goyo

El sáb, 20-09-2008 a las 11:13 +0200, Oz Nahum escribió:

I’m trying again to understand how to plot scattered data from array into

contour graph.

I looked at

http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data

and I understand I have to grid my data. However, in most samples the plot

is of a function.

Let’s say I want to plot some geological data, suppose water table head, and

I have the following 3D aray

``````           x     y    head
``````

``````           (1,    0,    13),
``````
``````           (2,    0,    11),
``````
``````           (3,    0,    12),
``````
``````           (1,    2,    11))
``````

matplotlib has lot’s of restrictions about how I can plot and interpolate

the data, which causes a lot of confusion in my side…

I’ll be happy if someone could supply me a clue of how to plot contours of

data which comes in arrays or raster format and not an equation.

Thanks,

Oz

This SF.Net email is sponsored by the Moblin Your Move Developer’s challenge

Build the coolest Linux based applications with Moblin SDK & win great prizes

Grand prize is a trip for two to an Open Source event anywhere in the world

http://moblin-contest.org/redirect.php?banner_id=100&url=/

Matplotlib-users mailing list

Matplotlib-users@lists.sourceforge.net

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

.’’`. : :' : We are [debian.org](http://debian.org). Lower your prices,`. `' surrender your code.`- We will add your hardware and software

distinctiveness to our own.
Resistance is futile.

Imagine there’s no countries
It isn’t hard to do
Nothing to kill or die for
And no religion too
Imagine all the people
Living life in peace

## You all must read ‘The God Delusion’http://en.wikipedia.org/wiki/The_God_Delusion

when one person suffers from a delusion it is called insanity. When many people suffer from a delusion it is called religion."

Robert Pirsig, Zen and the Art of Motorcycle Maintenance

Just give a look at zip(*head) and see that now it return two values so
you can't assign it to three variables.

¿What's the meaning of that data arrange? I can't make any sense of
plotting a 2D scatter from a 3D array.

Goyo

···

El jue, 25-09-2008 a las 15:15 +0200, Oz Nahum escribió:

Hi,
This indeed does the job. But after playing a little bit with the
code, I have discovered a few things:
first, I'd rather work with lists not tuples so I could actually
change my huge array of points.
second the array I described is kind of a pseudo 2D:
It has one big row.
[1, 0, 13],
[2, 0, 11],
[3, 0, 12],
[1, 2, 11]]

When I try to use a 3D array, with rows and columns

import pylab as pl

head = [[[0, 0, 10], [0, 1, 13]],
[[1, 0, 11], [1, 1, 12]],
[[2, 1, 11], [2, 2, 14]]]

xi, yi = pl.arange(0, 4, 0.1), pl.arange(0, 3, 0.1)
g = pl.griddata(x, y, z, xi, yi)
pl.scatter(x, y)
pl.contour(xi, yi, g)
pl.show()

I get this error:
Traceback (most recent call last):
File "asfplot.py", line 9, in <module>
ValueError: need more than 2 values to unpack

On Sat, Sep 20, 2008 at 2:19 PM, Goyo <goyodiaz@...287...> wrote:
Try something like this:

import pylab as pl

(1, 0, 13),
(2, 0, 11),
(3, 0, 12),
(1, 2, 11))

xi, yi = pl.arange(0, 4, 0.1), pl.arange(0, 3, 0.1)
g = pl.griddata(x, y, z, xi, yi)
pl.scatter(x, y)
pl.contour(xi, yi, g)

Level values are automatically chosen in this example but you
can
provide the number of values or a sequence of them.

Note that no extrapolation is done outside convex hull defined
by input
data.

Goyo

El sáb, 20-09-2008 a las 11:13 +0200, Oz Nahum escribió:

> I'm trying again to understand how to plot scattered data
from array into
> contour graph.
> I looked at
>
http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data
> and I understand I have to grid my data. However, in most
samples the plot
> is of a function.
> Let's say I want to plot some geological data, suppose
> I have the following 3D aray
> head = ((0, 0, 10),
> (1, 0, 13),
> (2, 0, 11),
> (3, 0, 12),
> (1, 2, 11))
> matplotlib has lot's of restrictions about how I can plot
and interpolate
> the data, which causes a lot of confusion in my side...
> I'll be happy if someone could supply me a clue of how to
plot contours of
> data which comes in arrays or raster format and not an
equation.
> Thanks,
> Oz
>

>
-------------------------------------------------------------------------
Developer's challenge
> Build the coolest Linux based applications with Moblin SDK &
win great prizes
> Grand prize is a trip for two to an Open Source event
anywhere in the world
> http://moblin-contest.org/redirect.php?banner_id=100&url=/
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users@lists.sourceforge.net
>
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

--
.''`.
: :' : We are debian.org. Lower your prices,
distinctiveness to our own.
Resistance is futile.

----
Imagine there's no countries
It isn't hard to do
Nothing to kill or die for
And no religion too
Imagine all the people
Living life in peace
----
You all must read 'The God Delusion'
http://en.wikipedia.org/wiki/The_God_Delusion
---
when one person suffers from a delusion it is called insanity. When
many people suffer from a delusion it is called religion."
Robert Pirsig, Zen and the Art of Motorcycle Maintenance

¿What’s the meaning of that data arrange? I can’t make any sense of

plotting a 2D scatter from a 3D array.

when I wrote:

``````        [1,    0,    13],

[2,    0,    11],

[3,    0,    12],

[1,    2,    11]]
``````

my meaning was to represent point of intereset with x, y coordinates and the 3rd number was height for example.
I felt like I couldn’t access the individual points easily, because their are located in on big list…

So I wanted to have the list broken into rows, and the each row represents a value on the y axis… like this:
[[0, 0, 10], [0, 0, 13]],

``````        [[2,    0,    11],             [3,    0,    12]],
]
``````

But that’s redundant I think now, after looking into the function zip.
Maybe I could write head in the following way:

``````      #   j = 0                             1
``````

``````        [[    0,    10],             [    1,    13]], # i =0

[[    0,    11],             [    1,    12]], # i =1

]
``````

But actually after understanding what zip does, I think I don’t need it anyway…

I did help(zip) but I could partially understand what it does. I learned more by doing:

and then printing x,y,z individually.

Thanks for your help so far.
Oz

>¿What's the meaning of that data arrange? I can't make any sense of
>plotting a 2D scatter from a 3D array.

when I wrote:
[1, 0, 13],
[2, 0, 11],
[3, 0, 12],
[1, 2, 11]]

my meaning was to represent point of intereset with x, y coordinates
and the 3rd number was height for example.
I felt like I couldn't access the individual points easily, because
their are located in on big list...
So I wanted to have the list broken into rows, and the each row
represents a value on the y axis... like this:
[[0, 0, 10], [0, 0, 13]],
[[2, 0, 11], [3, 0, 12]],
]

Mm... maybe this is better for your eyes but not for processing, I
think.

But that's redundant I think now, after looking into the function
zip.
Maybe I could write head in the following way:

# j = 0 1
[[ 0, 10], [ 1, 13]], # i =0
[[ 0, 11], [ 1, 12]], # i =1
]

The same. Parsing a data file usually yields a sequence of rows
(records), data processing functions usually expects columns of
homogeneous data and convert from records to columns and back is pretty
straightforward using zip. If you want to use a different representation
for your data you'll need to handle more complex structures and
conversions. Do it if you think it pays (sometimes it does).

But actually after understanding what zip does, I think I don't need
it anyway...

I did help(zip) but I could partially understand what it does. I
learned more by doing:
and then printing x,y,z individually.

There is no other use I can think of. If you think of the arguments
passed to zip as rows, it returns the columns. If the arguments are
columns, zip returns rows. How you name things depends on how you think
of your data. There is no other use I can think of.

zip expects each row (if they are rows) to be passed as an argument so
you usually need that * thing to unpack them. When you call zip(*x), x
being a sequence or array-like, you are actually passing each element of
x as an argument to zip.

Try this:

numbers = [1, 2, 3, 4, 5]
english = ['one', 'two', 'three', 'four', 'five']
spanish = ['uno', 'dos', 'tres', 'cuatro', 'cinco']
x = [numbers, english, spanish]
zip(numbers, english, spanish)
zip(x)
zip(*x)