ploting a contour graph from data files

Hi,
I want to draw a contour plot which uses data from files. I know how to import the files, so it’s not the main issue.
Let’s say I want to do a profile which has the following data:
distance, depth and some oceanographic data like temp, oxygen and stuff…

so for simplicity lets say I have:

distance = [1,2,3,4,5,6,7,8,9]
depth = [1,2,3,4,5,6,7,8,9]

temp = [26.5, 26.2, 26.2, 26.0,25, 24, 22, 21, 18]

how do I produce a countour plot were distanc is X, Y is depth and the contours are for temp ?

many thanks…
Oz

Oz Nahum wrote:

Hi,
I want to draw a contour plot which uses data from files. I know how to import the files, so it's not the main issue.
Let's say I want to do a profile which has the following data:
distance, depth and some oceanographic data like temp, oxygen and stuff....

so for simplicity lets say I have:

distance = [1,2,3,4,5,6,7,8,9]
depth = [1,2,3,4,5,6,7,8,9]

temp = [26.5, 26.2, 26.2, 26.0,25, 24, 22, 21, 18]

Too simple. If your grid has 9 points in distance and 9 in depth, then you need 81 values of temperature (9 profiles of 9 depths each).

Suppose you have 10 profiles of 8 points each. Then your temperature array should have shape (8,10). Your distance and depth arrays can either have the same shape as temperature, or both can be 1-D, in which case distance.shape = (10,) and depth.shape = (8,). Either way, you then use (assuming a current release of mpl)

from matplotlib import pyplot as plt
plt.contour(distance, depth, temperature)
plt.gca().invert_yaxis() # so depth increases down the y-axis
plt.show()

Note that the shape of your temperature array is the transpose of what one might expect. This is for matlab compatibility, and goes with the idea of looking at an array as it is printed, with the column dimension (second index) increasing across the page.

See the contour_demo.py and contourf_demo.py in the mpl examples.

Eric

···

how do I produce a countour plot were distanc is X, Y is depth and the contours are for temp ?

many thanks...
Oz

Thanks for the quick answer.
So if I have a series of 18 points withe measured distance, and 18 data points with distance, it makes it almost impossible to build the graph ??? I can’t type 18^18 points… I want the computer to plot the points and extrapulate between them…

excuse me the possibly dumb question, I am new to sceintific programming and for matplotlib

Oz

···

On Wed, Jul 16, 2008 at 7:51 PM, Eric Firing <efiring@…202…> wrote:

Oz Nahum wrote:

Hi,

I want to draw a contour plot which uses data from files. I know how to import the files, so it’s not the main issue.

Let’s say I want to do a profile which has the following data:

distance, depth and some oceanographic data like temp, oxygen and stuff…

so for simplicity lets say I have:

distance = [1,2,3,4,5,6,7,8,9]

depth = [1,2,3,4,5,6,7,8,9]

temp = [26.5, 26.2, 26.2, 26.0,25, 24, 22, 21, 18]

Too simple. If your grid has 9 points in distance and 9 in depth, then you need 81 values of temperature (9 profiles of 9 depths each).

Suppose you have 10 profiles of 8 points each. Then your temperature array should have shape (8,10). Your distance and depth arrays can either have the same shape as temperature, or both can be 1-D, in which case distance.shape = (10,) and depth.shape = (8,). Either way, you then use (assuming a current release of mpl)

from matplotlib import pyplot as plt

plt.contour(distance, depth, temperature)

plt.gca().invert_yaxis() # so depth increases down the y-axis

plt.show()

Note that the shape of your temperature array is the transpose of what one might expect. This is for matlab compatibility, and goes with the idea of looking at an array as it is printed, with the column dimension (second index) increasing across the page.

See the contour_demo.py and contourf_demo.py in the mpl examples.

Eric

how do I produce a countour plot were distanc is X, Y is depth and the contours are for temp ?

many thanks…

Oz

Oz Nahum wrote:

Thanks for the quick answer.
So if I have a series of 18 points withe measured distance, and 18 data points with distance, it makes it almost impossible to build the graph ??? I can't type 18^18 points.... I want the computer to plot the points and extrapulate between them...

I'm puzzled. You said you knew how to read in your data from files, so there should be no question of having to type too many numbers.

Eric

···

excuse me the possibly dumb question, I am new to sceintific programming and for matplotlib

Oz
              
On Wed, Jul 16, 2008 at 7:51 PM, Eric Firing <efiring@…202… > <mailto:efiring@…202…>> wrote:

    Oz Nahum wrote:

        Hi,
        I want to draw a contour plot which uses data from files. I know
        how to import the files, so it's not the main issue.
        Let's say I want to do a profile which has the following data:
        distance, depth and some oceanographic data like temp, oxygen
        and stuff....

        so for simplicity lets say I have:

        distance = [1,2,3,4,5,6,7,8,9]
        depth = [1,2,3,4,5,6,7,8,9]

        temp = [26.5, 26.2, 26.2, 26.0,25, 24, 22, 21, 18]

    Too simple. If your grid has 9 points in distance and 9 in depth,
    then you need 81 values of temperature (9 profiles of 9 depths each).

    Suppose you have 10 profiles of 8 points each. Then your
    temperature array should have shape (8,10). Your distance and depth
    arrays can either have the same shape as temperature, or both can be
    1-D, in which case distance.shape = (10,) and depth.shape = (8,).
     Either way, you then use (assuming a current release of mpl)

    from matplotlib import pyplot as plt
    plt.contour(distance, depth, temperature)
    plt.gca().invert_yaxis() # so depth increases down the y-axis
    plt.show()

    Note that the shape of your temperature array is the transpose of
    what one might expect. This is for matlab compatibility, and goes
    with the idea of looking at an array as it is printed, with the
    column dimension (second index) increasing across the page.

    See the contour_demo.py and contourf_demo.py in the mpl examples.

    Eric

        how do I produce a countour plot were distanc is X, Y is depth
        and the contours are for temp ?

        many 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

Ok, I played with it a little bit.

Here is what I know:
importing the data is not a big issue, I aready wrote a tutorial about it here:
http://www.tabula0rasa.org/?p=21

here is a sample code I wrote.
from matplotlib import pyplot as plt
from pylab import *
temperature=[
[1,3,4],
[2,4,5],
[6,3,2]
]

distance = (100,200,300)

depth = (10,30,50)

plt.colorbar()
plt.contourf(distance,depth,temperature)
plt.gca().invert_yaxis()
plt.show()

Can I plot the dots as different series on top of the contours ?

many many 10x.

Oz

···

On Wed, Jul 16, 2008 at 8:58 PM, Eric Firing <efiring@…202…> wrote:

Oz Nahum wrote:

Thanks for the quick answer.

So if I have a series of 18 points withe measured distance, and 18 data points with distance, it makes it almost impossible to build the graph ??? I can’t type 18^18 points… I want the computer to plot the points and extrapulate between them…

I’m puzzled. You said you knew how to read in your data from files, so there should be no question of having to type too many numbers.

Eric

excuse me the possibly dumb question, I am new to sceintific programming and for matplotlib

Oz

On Wed, Jul 16, 2008 at 7:51 PM, Eric Firing <efiring@…202… mailto:efiring@...202...> wrote:

Oz Nahum wrote:



    Hi,

    I want to draw a contour plot which uses data from files. I know

    how to import the files, so it's not the main issue.

    Let's say I want to do a profile which has the following data:

    distance, depth and some oceanographic data like temp, oxygen

    and stuff....



    so for simplicity lets say I have:



    distance = [1,2,3,4,5,6,7,8,9]

    depth = [1,2,3,4,5,6,7,8,9]



    temp = [26.5, 26.2, 26.2, 26.0,25, 24, 22, 21, 18]





Too simple.  If your grid has 9 points in distance and 9 in depth,

then you need 81 values of temperature (9 profiles of 9 depths each).



Suppose you have 10 profiles of 8 points each.  Then your

temperature array should have shape (8,10).  Your distance and depth

arrays can either have the same shape as temperature, or both can be

1-D, in which case distance.shape = (10,) and depth.shape = (8,).

 Either way, you then use (assuming a current release of mpl)



from matplotlib import pyplot as plt

plt.contour(distance, depth, temperature)

plt.gca().invert_yaxis() # so depth increases down the y-axis

plt.show()



Note that the shape of your temperature array is the transpose of

what one might expect.  This is for matlab compatibility, and goes

with the idea of looking at an array as it is printed, with the

column dimension (second index) increasing across the page.



See the contour_demo.py and contourf_demo.py in the mpl examples.



Eric







    how do I produce a countour plot were distanc is X, Y is depth

    and the contours are for temp ?



    many 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

There are a couple of functions for loading ASCII data so you probably
don't need to role your own unless you have specialized needs. See
numpy.loadtxt and matplotlib.mlab.csv2rec (example at
http://matplotlib.sf.net/examples/pylab_examples/loadrec.py

JDH

···

On Wed, Jul 16, 2008 at 1:25 PM, Oz Nahum <nahumoz@...287...> wrote:

Ok, I played with it a little bit.

Here is what I know:
importing the data is not a big issue, I aready wrote a tutorial about it
here:
http://www.tabula0rasa.org/?p=21

Oz Nahum wrote:

Ok, I played with it a little bit.

Here is what I know:
importing the data is not a big issue, I aready wrote a tutorial about it here:
http://www.tabula0rasa.org/?p=21

here is a sample code I wrote.
from matplotlib import pyplot as plt
from pylab import *
temperature=[
            [1,3,4],
            [2,4,5],
            [6,3,2]
]

distance = (100,200,300)
depth = (10,30,50)

plt.colorbar()
plt.contourf(distance,depth,temperature)
plt.gca().invert_yaxis()
plt.show()

Can I plot the dots as different series on top of the contours ?

First you have to make your basic example work; what you posted above does not.
1) For an example like this, use a different number of points in the x and y directions, to make it clear how the arrays are oriented.
2) The colorbar command must *follow* the contourf command.
3) Make your test temperature profiles more reasonable, i.e. temperature decreasing with depth, so you can see whether your plot is doing the right thing.
4) Omit the "from pylab import *"
5) Once you start doing real work, you will need numpy. The suggested import syntax is "import numpy as np".
6) Study the examples that come with mpl.

Eric

Hi Eric,
really thanks for your help so far. I am doing a quick short course, and I’ll do the examples later.
I’ve fixed the code, here it is:

from matplotlib import pyplot as plt
temperature=[

        [10,8,6],
        [9,7,5],
        [8,7,4]

]

distance = (100,200,300)
depth = (100,300,700)

x = distance
y = depth
z = temperature

m = plt.contourf(x,y,z)
plt.gca().invert_yaxis()

plt.colorbar(m)
plt.show(m)

the trouble now that the contours seems wrong… and my question still stands. I’d like to do the plot as said: contours + series, can you show me where I’m wrong ?

thanks, Oz

···

On Wed, Jul 16, 2008 at 9:37 PM, Eric Firing <efiring@…202…> wrote:

Oz Nahum wrote:

Ok, I played with it a little bit.

Here is what I know:

importing the data is not a big issue, I aready wrote a tutorial about it here:

http://www.tabula0rasa.org/?p=21

here is a sample code I wrote.

from matplotlib import pyplot as plt

from pylab import *

temperature=[

        [1,3,4],

        [2,4,5],

        [6,3,2]

]

distance = (100,200,300)

depth = (10,30,50)

plt.colorbar()

plt.contourf(distance,depth,temperature)

plt.gca().invert_yaxis()

plt.show()

Can I plot the dots as different series on top of the contours ?

First you have to make your basic example work; what you posted above does not.

  1. For an example like this, use a different number of points in the x and y directions, to make it clear how the arrays are oriented.

  2. The colorbar command must follow the contourf command.

  3. Make your test temperature profiles more reasonable, i.e. temperature decreasing with depth, so you can see whether your plot is doing the right thing.

  4. Omit the “from pylab import *”

  5. Once you start doing real work, you will need numpy. The suggested import syntax is “import numpy as np”.

  6. Study the examples that come with mpl.

Eric

Oz Nahum wrote:

Hi Eric,
really thanks for your help so far. I am doing a quick short course, and I'll do the examples later.
I've fixed the code, here it is:

from matplotlib import pyplot as plt
temperature=[
            [10,8,6],
            [9,7,5],
            [8,7,4]
]

distance = (100,200,300)
depth = (100,300,700)

x = distance
y = depth
z = temperature

m = plt.contourf(x,y,z)
plt.gca().invert_yaxis()
plt.colorbar(m)
plt.show(m)

the trouble now that the contours seems wrong... and my question still stands. I'd like to do the plot as said: contours + series, can you show me where I'm wrong ?

The plot looks right to me--I see 4 degrees in the lower RH corner, 300 distance units and 700 depth units. Why do you say the contours seem wrong?

As for plotting the "series", what do you mean? Put circles on the data points? Then include something like this, after the call to contourf:

import numpy as np
X, Y = np.meshgrid(x,y)
plt.hold(True) # probably not necessary
plt.plot(X,Y, 'o')

Eric

···

thanks, Oz

On Wed, Jul 16, 2008 at 9:37 PM, Eric Firing <efiring@…202… > <mailto:efiring@…202…>> wrote:

    Oz Nahum wrote:

        Ok, I played with it a little bit.

        Here is what I know:
        importing the data is not a big issue, I aready wrote a tutorial
        about it here:
        http://www.tabula0rasa.org/?p=21

        here is a sample code I wrote.
        from matplotlib import pyplot as plt
        from pylab import *
        temperature=[
                   [1,3,4],
                   [2,4,5],
                   [6,3,2]
        ]

        distance = (100,200,300)
        depth = (10,30,50)

        plt.colorbar()
        plt.contourf(distance,depth,temperature)
        plt.gca().invert_yaxis()
        plt.show()

        Can I plot the dots as different series on top of the contours ?

    First you have to make your basic example work; what you posted
    above does not.
    1) For an example like this, use a different number of points in the
    x and y directions, to make it clear how the arrays are oriented.
    2) The colorbar command must *follow* the contourf command.
    3) Make your test temperature profiles more reasonable, i.e.
    temperature decreasing with depth, so you can see whether your plot
    is doing the right thing.
    4) Omit the "from pylab import *"
    5) Once you start doing real work, you will need numpy. The
    suggested import syntax is "import numpy as np".
    6) Study the examples that come with mpl.

    Eric

Here is why the contours are wrong:
they are ploted verticaly, while I think, it is more common to draw temp. contours in oceanography when the are horizontal.

Also, one more thing, I can’t find how to expand the borders of the plot, say from 350 to 400

(same for depth) I tried usig xlim and ylim(0,900) but no result.
Here is my code now, I can’t really get it, ha ?
another issue is that I’ve added anoter temp. series but it won’t show it. I still see 3 rows.

from matplotlib import pyplot as plt
from pylab import *
temperature=[
[9,8,6],
[9,7,6],
[9,7,6],
[9,6,6]
]

distance = (0,200,350)
depth = (100,250,250,700)

x = distance
y = depth
z = temperature
#m = plt.contourf(x,y,z)
m = plt.contour(x,y,z)
ylabel(‘Depth’)
xlabel(‘Distance’)
ylim(0,1200)
#plt.xlim(0,500)
plt.gca().invert_yaxis()

#plt.colorbar(m)

import numpy as np
X, Y = np.meshgrid(x,y)
#plt.hold(True) # probably not necessary
plt.plot(X,Y, ‘o’)
plt.show(m)

···

On Wed, Jul 16, 2008 at 10:28 PM, Eric Firing <efiring@…202…> wrote:

Oz Nahum wrote:

Hi Eric,

really thanks for your help so far. I am doing a quick short course, and I’ll do the examples later.

I’ve fixed the code, here it is:

from matplotlib import pyplot as plt

temperature=[

        [10,8,6],

        [9,7,5],

        [8,7,4]

]

distance = (100,200,300)

depth = (100,300,700)

x = distance

y = depth

z = temperature

m = plt.contourf(x,y,z)

plt.gca().invert_yaxis()

plt.colorbar(m)

plt.show(m)

the trouble now that the contours seems wrong… and my question still stands. I’d like to do the plot as said: contours + series, can you show me where I’m wrong ?

The plot looks right to me–I see 4 degrees in the lower RH corner, 300 distance units and 700 depth units. Why do you say the contours seem wrong?

As for plotting the “series”, what do you mean? Put circles on the data points? Then include something like this, after the call to contourf:

import numpy as np

X, Y = np.meshgrid(x,y)

plt.hold(True) # probably not necessary

plt.plot(X,Y, ‘o’)

Eric

thanks, Oz

On Wed, Jul 16, 2008 at 9:37 PM, Eric Firing <efiring@…202… mailto:efiring@...202...> wrote:

Oz Nahum wrote:



    Ok, I played with it a little bit.



    Here is what I know:

    importing the data is not a big issue, I aready wrote a tutorial

    about it here:

    [http://www.tabula0rasa.org/?p=21](http://www.tabula0rasa.org/?p=21)



    here is a sample code I wrote.

    from matplotlib import pyplot as plt

    from pylab import *

    temperature=[

               [1,3,4],

               [2,4,5],

               [6,3,2]

    ]



    distance = (100,200,300)

    depth = (10,30,50)



    plt.colorbar()

    plt.contourf(distance,depth,temperature)

    plt.gca().invert_yaxis()

    plt.show()







    Can I plot the dots as different series on top of the contours ?





First you have to make your basic example work; what you posted

above does not.

1) For an example like this, use a different number of points in the

x and y directions, to make it clear how the arrays are oriented.

2) The colorbar command must *follow* the contourf command.

3) Make your test temperature profiles more reasonable, i.e.

temperature decreasing with depth, so you can see whether your plot

is doing the right thing.

4) Omit the "from pylab import *"

5) Once you start doing real work, you will need numpy.  The

suggested import syntax is "import numpy as np".

6) Study the examples that come with mpl.



Eric

Here is why the contours are wrong:
they are ploted verticaly, while I think, it is more common to draw temp.
contours in oceanography when the are horizontal.

You can transpose your inputs. For numpy arrays: x = x.transpose()

Also, one more thing, I can't find how to expand the borders of the plot,
say from 350 to 400
(same for depth) I tried usig xlim and ylim(0,900) but no result.

Subsequent calls to plot will call the autoscaler, so either you need
to set the xlim *after* all the plotting commands or turn off
autoscaling entirely by passing the autoscale_on=False property to the
axes, eg

plt.gca().set_autoscale_on(False)

···

On Wed, Jul 16, 2008 at 2:58 PM, Oz Nahum <nahumoz@...287...> wrote:

You can transpose your inputs. For numpy arrays: x = x.transpose()

i wrote:
for np arrays: x = x.transpose()

but I still get a syntax error.

Also, one more thing, I can’t find how to expand the borders of the plot,

say from 350 to 400

(same for depth) I tried usig xlim and ylim(0,900) but no result.

Subsequent calls to plot will call the autoscaler, so either you need

to set the xlim after all the plotting commands or turn off

autoscaling entirely by passing the autoscale_on=False property to the

axes, eg

plt.gca().set_autoscale_on(False)

That does for the one of the problems.

And I still haven’t manage to plot the 4th series.

still many thanks…
hope I can figure this out…

Oz Nahum schrieb:

Hi,
I want to draw a contour plot which uses data from files. I know how to import the files, so it's not the main issue.

I was discussion a similar issue with Jeff this week.

Take a look at the thread:
http://news.gmane.org/gmane.comp.python.matplotlib.general

Unfortunately, I had to focus on other things and had to postpone the development of my script...

umm.... that was english, not python. They python is

   x = x.transpose()

I know you are anxious to get results fast, but I suggest taking a
deep breath and doing a little reading on the numpy and matplotlib
tutorials linked on theor respective websites....

JDH

···

On Wed, Jul 16, 2008 at 3:18 PM, Oz Nahum <nahumoz@...287...> wrote:

You can transpose your inputs. For numpy arrays: x = x.transpose()

i wrote:
for np arrays: x = x.transpose()

but I still get a syntax error.

I still get this error
Traceback (most recent call last):
File “yael.py”, line 24, in
x = x.transpose()
AttributeError: ‘tuple’ object has no attribute ‘transpose’

and one more thing I discovered. the Data points that are ploted are not temperature… this are the depth:distance coordinates.

I am a lost case about reading tutorial at the moment.
I am in a middle of a very intense course, and they expect us to do crazy stuff with matlab. so it’s either that or solving with python. I’ll do read it when I have time…

I am mostly frustrated with documentation writers who write very nice tutorials describing how to plot completely unusfull graphs of spheres inside loops and a dolphin swimming in the middle.
Come on, this is not what users need. I am talking about what many students feel. We need real tutorials, this why I wrote my own little tutorial here http://www.tabula0rasa.org/?p=21

but that’s not enough.

sorry about making so much fuss in the mailing list and crying my hearts out, but I thought since I know python it’s worth trying this and not mathlab

Oz

···

On Wed, Jul 16, 2008 at 11:20 PM, John Hunter <jdh2358@…287…> wrote:

On Wed, Jul 16, 2008 at 3:18 PM, Oz Nahum <nahumoz@…287…> wrote:

You can transpose your inputs. For numpy arrays: x = x.transpose()

i wrote:

for np arrays: x = x.transpose()

but I still get a syntax error.

umm… that was english, not python. They python is

x = x.transpose()

I know you are anxious to get results fast, but I suggest taking a

deep breath and doing a little reading on the numpy and matplotlib

tutorials linked on theor respective websites…

JDH

Oz Nahum wrote:

I am mostly frustrated with documentation writers who write very nice tutorials describing how to plot completely unusfull graphs of spheres inside loops and a dolphin swimming in the middle.

I'm sorry. I just couldn't resist writing a tutorial example for this. Please take it in the spirit of fun it was intended.

Mike

dolphin.py (3.22 KB)

···

--
Michael Droettboom
Science Software Branch
Operations and Engineering Division
Space Telescope Science Institute
Operated by AURA for NASA

Dear Mike,
I really laughed. Many thanks. It’s almost to late for me to really understand the code now.
But some how you managed to throw in some stuff that can help:
you’ve made what I’ve wanted except for the dolphin.

I am sorry about the exagerating, but everybody here keep talking about this young dolphin that keeps swimming around the reef here (I am in Eilat, northren tip of Gulf of Aqaba).
Anyways, many thanks for you people trying to help.

Oz.

···

On Thu, Jul 17, 2008 at 12:12 AM, Michael Droettboom <mdroe@…86…> wrote:

Oz Nahum wrote:

I am mostly frustrated with documentation writers who write very nice tutorials describing how to plot completely unusfull graphs of spheres inside loops and a dolphin swimming in the middle.

I’m sorry. I just couldn’t resist writing a tutorial example for this. Please take it in the spirit of fun it was intended.

Mike

Michael Droettboom

Science Software Branch

Operations and Engineering Division

Space Telescope Science Institute

Operated by AURA for NASA

import matplotlib.pyplot as plt

from matplotlib.patches import Circle, PathPatch

from matplotlib.path import Path

from matplotlib.transforms import Affine2D

import numpy as np

r = np.random.rand(50)

t = np.random.rand(50) * np.pi * 2.0

x = r * np.cos(t)

y = r * np.sin(t)

fig = plt.figure(figsize=(6,6))

ax = plt.subplot(111)

circle = Circle((0, 0), 1, facecolor=(0,0,0.8),

            edgecolor=(0,0.8,0.8), linewidth=3, alpha=0.5)

ax.add_patch(circle)

plt.plot(x, y, ‘o’, color=(0.9, 0.9, 1.0), alpha=0.8)

Dolphin from OpenClipart library by Andy Fitzsimon

<cc:License rdf:about=“http://web.resource.org/cc/PublicDomain”>

<cc:permits rdf:resource=“http://web.resource.org/cc/Reproduction”/>

<cc:permits rdf:resource=“http://web.resource.org/cc/Distribution”/>

<cc:permits rdf:resource=“http://web.resource.org/cc/DerivativeWorks”/>

</cc:License>

dolphin = “”"

M -0.59739425,160.18173 C -0.62740401,160.18885 -0.57867129,160.11183

-0.57867129,160.11183 C -0.57867129,160.11183 -0.5438361,159.89315

-0.39514638,159.81496 C -0.24645668,159.73678 -0.18316813,159.71981

-0.18316813,159.71981 C -0.18316813,159.71981 -0.10322971,159.58124

-0.057804323,159.58725 C -0.029723983,159.58913 -0.061841603,159.60356

-0.071265813,159.62815 C -0.080250183,159.65325 -0.082918513,159.70554

-0.061841203,159.71248 C -0.040763903,159.7194 -0.0066711426,159.71091

0.077336307,159.73612 C 0.16879567,159.76377 0.28380306,159.86448

0.31516668,159.91533 C 0.3465303,159.96618 0.5011127,160.1771

0.5011127,160.1771 C 0.63668998,160.19238 0.67763022,160.31259

0.66556395,160.32668 C 0.65339985,160.34212 0.66350443,160.33642

0.64907098,160.33088 C 0.63463742,160.32533 0.61309688,160.297

0.5789627,160.29339 C 0.54348657,160.28968 0.52329693,160.27674

0.50728856,160.27737 C 0.49060916,160.27795 0.48965803,160.31565

0.46114204,160.33673 C 0.43329696,160.35786 0.4570711,160.39871

0.43309565,160.40685 C 0.4105108,160.41442 0.39416631,160.33027

0.3954995,160.2935 C 0.39683269,160.25672 0.43807996,160.21522

0.44567915,160.19734 C 0.45327833,160.17946 0.27946869,159.9424

-0.061852613,159.99845 C -0.083965233,160.0427 -0.26176109,160.06683

-0.26176109,160.06683 C -0.30127962,160.07028 -0.21167141,160.09731

-0.24649368,160.1011 C -0.32642366,160.11569 -0.34521187,160.06895

-0.40622293,160.0819 C -0.467234,160.09485 -0.56738444,160.17461

-0.59739425,160.18173

“”"

vertices = []

codes = []

parts = dolphin.split()

i = 0

code_map = {

'M': (Path.MOVETO, 1),

'C': (Path.CURVE4, 3),

'L': (Path.LINETO, 1)

}

while i < len(parts):

code = parts[i]

path_code, npoints = code_map[code]

codes.extend([path_code] * npoints)

vertices.extend([[float(x) for x in y.split(',')] for y in parts[i+1:i+npoints+1]])

i += npoints + 1

vertices = np.array(vertices, np.float)

vertices[:,1] -= 160

dolphin_path = Path(vertices, codes)

dolphin_patch = PathPatch(dolphin_path, facecolor=(0.6, 0.6, 0.6),

                      edgecolor=(0.0, 0.0, 0.0))

ax.add_patch(dolphin_patch)

vertices = Affine2D().rotate_deg(60).transform(vertices)

dolphin_path2 = Path(vertices, codes)

dolphin_patch2 = PathPatch(dolphin_path2, facecolor=(0.5, 0.5, 0.5),

                       edgecolor=(0.0, 0.0, 0.0))

ax.add_patch(dolphin_patch2)

plt.show()

Oz Nahum wrote:

I still get this error
Traceback (most recent call last):
  File "yael.py", line 24, in <module>
    x = x.transpose()
AttributeError: 'tuple' object has no attribute 'transpose'

as someone suggested, you really want to read up on numpy -- the transpose method is a method of numpy arrays. numpy arrays are kind of like Matlab matrixes, only more powerful and flexible. MPL is using numpy arrays inside anyway.

and one more thing I discovered. the Data points that are ploted are not temperature... this are the depth:distance coordinates.

if you have a contour plot, you have depth,distance as your x,y coordinates, with the temp value shown by the contours How did you expect to plot temp on top of that?

I am a lost case about reading tutorial at the moment.
I am in a middle of a very intense course, and they expect us to do crazy stuff with matlab. so it's either that or solving with python.

Either way, there is not choice but to learn a bit first! As hard as this is, you're right trying to do all your computation and plotting with with a spreadsheet is a nightmare -- you'll be glad you've learned it!

Have you read the MPL docs -- there's a lot of good, simple examples in there:

http://matplotlib.sourceforge.net/users_guide_0.98.1.pdf

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...

I have to say, I was completely unaware of the path.Path
capability of Matplotlib, but even if I had known of it,
I would not have thought of how to exploit it this way.
Even though this was intended to be just for fun,
I hope it will be added to the examples.

Thanks!
Alan Isaac

···

On Wed, 16 Jul 2008, Michael Droettboom apparently wrote:

[Attachment: dolphin.py : TEXT/PLAIN, 62 lines]

Michael Droettboom wrote:

Oz Nahum wrote:

I am mostly frustrated with documentation writers who write very nice tutorials describing how to plot completely unusfull graphs of spheres inside loops and a dolphin swimming in the middle.

I'm sorry. I just couldn't resist writing a tutorial example for this. Please take it in the spirit of fun it was intended.

That's freaking hilarious. Someone clearly has too much time on their hands. (Yeah right.) Goes to show the power of matplotlib though. Nice one.

Ryan

···

--
Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma