Re: [Matplotlib-users] contour's polygons

2010-07-29 Thread Ian Thomas
On 28 July 2010 01:31, Phil Rosenfield philr...@astro.washington.eduwrote:

 I'd like to use the polygons contour makes but I can't figure out how
 to get them from ContourSet. Any examples or links to helpful
 information would be excellent.


Attached is an example of how to extract the polygons from a ContourSet.
import matplotlib.pyplot as plt
import numpy as np

# Dummy x,y,z data.
x = np.linspace(0, 1, 10)
y = np.linspace(0, 1, 10)
x,y = np.meshgrid(x,y)
z = np.sin(7*x)*np.sin(7*y)

# Contours levels.
levels = [0, 0.4, 0.8]
nlevels = len(levels)

# Use either one of the following two lines:
contourset = plt.contour(x, y, z, levels)# Line contours
#contourset = plt.contourf(x, y, z, levels)   # Filled contours

# contourset.collections is a list of nlevels LineCollections if using contour
# and a list of (nlevels-1) PathCollections if using contourf.
print contourset.collections

# Look at a single level index.  If you want all of the contour levels, you
# will need to loop through them.
level = 1
print 'level is', levels[level]

paths = contourset.collections[level].get_paths()
npaths = len(paths)
print 'number of paths', npaths

for i in range(npaths):
path = paths[i]
print 'path', i, 'of', npaths
# Each path has vertices, it may also have codes.  If codes is None, the
# vertices are a single continuous path of line segments and should be easy
# to deal with.  If codes is not None then vertices is probably 2 or more
# discontinuous line segments; you will need to understand the codes for
# MOVETO and LINETO at least - see lib/matplotlib/path.py for details.
print '  codes', path.codes
print '  vertices', path.vertices

# Show the contour plot to help explanation.
plt.colorbar()
plt.show()
--
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] contour's polygons

2010-07-28 Thread Phil Rosenfield
Hi,

I'm 6 months into learning python and haven't been able to find a way
to do this, so I hope you don't mind a basic question.

I'd like to use the polygons contour makes but I can't figure out how
to get them from ContourSet. Any examples or links to helpful
information would be excellent.

Thanks,
Phil

-- 
Phil Rosenfield
Graduate Student: UW Astronomy
Additional contact info:
http://www.astro.washington.edu/philrose

--
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share 
of $1 Million in cash or HP Products. Visit us here for more details:
http://ad.doubleclick.net/clk;226879339;13503038;l?
http://clk.atdmt.com/CRS/go/247765532/direct/01/
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] contour's polygons

2010-07-28 Thread Eric Firing
On 07/27/2010 02:31 PM, Phil Rosenfield wrote:
 Hi,

 I'm 6 months into learning python and haven't been able to find a way
 to do this, so I hope you don't mind a basic question.

 I'd like to use the polygons contour makes but I can't figure out how
 to get them from ContourSet. Any examples or links to helpful
 information would be excellent.

They are buried.  Each contour set has a list of collections, and
each of those collections has a set of paths, and each of those paths 
has a vertices attribute for its corresponding polygon.  In the 
following we will pick out the first path of the first collection.

cs = contour(rand(6,6))
c = cs.collections[0]
p = c.get_paths()[0]
v = p.vertices

lev = cs.levels[0]

The levels attribute is a list of levels corresponding to the list of 
collections: one collection per level.

Eric

 Thanks,
 Phil



--
The Palm PDK Hot Apps Program offers developers who use the
Plug-In Development Kit to bring their C/C++ apps to Palm for a share
of $1 Million in cash or HP Products. Visit us here for more details:
http://p.sf.net/sfu/dev2dev-palm
___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users