Re: [Matplotlib-users] Inner boundaries in tricontourf

2011-08-31 Thread Ian Thomas
On 30 August 2011 18:23, Tijs de Kler tijs.dek...@sara.nl wrote:

 Im trying to use the tricontourf function in matplotlib to reduce the
 complexity of an unstructured dataset into contours.
 The resulting contours are retrieved from the path by the to_polygon()
 function, but i have some trouble distinguishing inner boundaries on the
 polygons, while plot.show() clearly doesn't

 Using Matplotlib 1.01, and the attached code, I get one level, consisting
 of 2 polygons, where the first is the outer boundary, and the second should
 be the inner boundary.
 The figure shown by show() correctly displays a square with a inner square
 cut-out. However i cannot distinguish between inner and outer boundaries in
 the list of polygons that to_polygon() returns.

 Is there a trick how the plot functions distinguish inner boundaries?
 Calculating for each polygon if it is contained in other polygons will
 become complicated with a large number of polygons: As far as i can tell
 this would be checking if the starting point of each polygon is contained in
 any of the other polygons. Is there a simpler method i missed?


Matplotlib includes a function to determine if a set of points is within a
polygon, called points_inside_poly.  For an example see
http://matplotlib.sourceforge.net/faq/howto_faq.html#test-whether-a-point-is-inside-a-polygon
That is about as simple as it gets from a user's perspective!

Since you ask about tricks in plot functions, no there aren't any.
Rendering functions don't explicitly determine if a contour polygon is an
inner or outer boundary.  Usually a sweep algorithm is performed across all
points to construct the triangulation of the polygons as it progresses.  You
could extract the inner/outer-ness of each boundary from such an algorithm
but it would be overkill for what you want to do.

Ian Thomas
--
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free Love Thy Logs t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


Re: [Matplotlib-users] Inner boundaries in tricontourf

2011-08-31 Thread Ian Thomas
I forgot to mention the obvious solution!  Outer boundaries are ordered
anticlockwise, inner boundaries clockwise.  Calculate the area of each
boundary assuming it is ordered anticlockwise, and if the area is positive
it is an outer boundary, if negative it is an inner boundary.  I've attached
a modified version of your debug.py to show this.

This may be simpler to use than points_inside_poly, but if you have multiple
nested boundaries it could get confusing unless you know which boundary
encloses which others.

Ian Thomas
import matplotlib
import matplotlib.pyplot as plot
import numpy as np


def get_polygon_area(vertices):
v2 = np.roll(vertices, -1, axis=0)
return np.cross(vertices, v2).sum() / 2.0

def is_polygon_inner_boundary(vertices):
return get_polygon_area(vertices)  0.0


x_array = []
y_array = []
for i in range(1,5) :
for j in range(1,5) :
x_array.append(i)
y_array.append(j)

triang = [ [0,4,5],[0,5,1], [1,5,6],[1,6,2], [2,6,7], [2,7,3],[4,8,9], [4,9,5], [6,10,11],[6,11,7], [8,12,13], [8,13,9],[9,13,14], [9,14,10], [10,14,15],[10,15,11]]

triangle_poly =matplotlib.tri.Triangulation(x_array, y_array, triang)

data=[1]*16
level_list  = [0,2]
contourplot = plot.tricontourf(triangle_poly, data, level_list)

for level in contourplot.collections:
polys = level.get_paths()[0].to_polygons()
for poly in polys:
print 'polygon:', poly
print 'inner boundary:', is_polygon_inner_boundary(poly)

plot.show()
--
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free Love Thy Logs t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users


[Matplotlib-users] Inner boundaries in tricontourf

2011-08-30 Thread Tijs de Kler

Hey Matplotlib users,

Im trying to use the tricontourf function in matplotlib to reduce the 
complexity of an unstructured dataset into contours.
The resulting contours are retrieved from the path by the to_polygon() function, but i have some trouble distinguishing inner boundaries on the 
polygons, while plot.show() clearly doesn't


Using Matplotlib 1.01, and the attached code, I get one level, consisting of 2 polygons, where the first is the outer boundary, and the second should 
be the inner boundary.
The figure shown by show() correctly displays a square with a inner square cut-out. However i cannot distinguish between inner and outer boundaries in 
the list of polygons that to_polygon() returns.


Is there a trick how the plot functions distinguish inner boundaries? Calculating for each polygon if it is contained in other polygons will become 
complicated with a large number of polygons: As far as i can tell this would be checking if the starting point of each polygon is contained in any of 
the other polygons. Is there a simpler method i missed?


Thanks in advance,
Tijs de Kler




import matplotlib
import matplotlib.pyplot as plot

x_array = []
y_array = []
for i in range(1,5) :
for j in range(1,5) :
x_array.append(i)
y_array.append(j)

triang = [ [0,4,5],[0,5,1], [1,5,6],[1,6,2], [2,6,7], [2,7,3],[4,8,9], [4,9,5], [6,10,11],[6,11,7], [8,12,13], [8,13,9],[9,13,14], [9,14,10], [10,14,15],[10,15,11]]

triangle_poly =matplotlib.tri.Triangulation(x_array, y_array, triang)

data=[1]*16
level_list  = [0,2]
contourplot = plot.tricontourf(triangle_poly, data, level_list)

for level in contourplot.collections:
print level.get_paths()[0].to_polygons()

plot.show()
--
Special Offer -- Download ArcSight Logger for FREE!
Finally, a world-class log management solution at an even better 
price-free! And you'll get a free Love Thy Logs t-shirt when you
download Logger. Secure your free ArcSight Logger TODAY!
http://p.sf.net/sfu/arcsisghtdev2dev___
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users