<div dir="ltr"><div><div>Francis,<br><br></div>I bet you that the inconsistency in the number of vertexes is due to path simplification. The list of Path objects you get when you call get_paths() on the collection object each have an attribute "should_simplify" and that defaults to True. Set it to False, and you will have all of the vertexes. Also, what you want to call is to_polygons() on the Path object after setting "should_simplify" to False. That will return a list of lists. The first element of that list is the external vertexes, and the rest of the elements are all vertex lists of the internal holes.<br><br></div><div>I hope this description helps. I can't really give you more detailed description due to the fact that I have developed software that does this very thing for my employer, but what you want is certainly possible.<br><br></div><div>Also, as for whether or not we would want a geojson export function available for matplotlib, it isn't really correct to have it in matplotlib because we are a graphing library. However, it would make sense to make the process of extracting the polygon information a bit easier, which would make it easier for another package to be made that would export that information into various data formats, not just geojson.<br><br></div><div>Cheers!<br></div><div>Ben Root<br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 30, 2015 at 12:46 PM, Francis Chabouis <span dir="ltr"><<a href="mailto:fchabouis@gmail.com" target="_blank">fchabouis@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div>Hello,<br></div>I'm having some difficulties with the results of the tricontour function. What I'm trying to achieve is fairly simple : I'd like to export the results of the tricontour function as a geoJson. (I think a function doing exactly this job would be nice to have in the library).<br><br></div><div>I wrote this :<br><br>cs = plt.tricontourf(t, v, levels)<br><br>for i,collection in enumerate(cs.collections):<br>    for path in collection.get_paths():<br><br><br></div><div>Now I have this path object.<br></div><div><br>My first problem : when I check the number of vertices (via len(path.vertices)) I get 732 vertices.<br></div><div>If I try to access those vertices with iter_segments as recommended in the doc, I get only 125 vertices.<br></div><div>seg = path.iter_segments()<br></div><div>print len(list(seg))<br>==> 125<br><br></div><div>Am I doing something wrong, or is it possibly a bug ? <br><br></div><div>My second problem : geoJson works with interior and exterior rings. To describe a polygon with a hole in it, we first declare a closed line (that will be the exterior) and all the subsequent lines will be the "holes" (interiors). It seems that what I get from iter_segments and to_polygons is a bunch of lines, but there is no way to know which is an interior, which is an exterior. But I guess this must be stored somewhere as MPL is able to draw a graph from this information !<br><br></div><div>Any hints on how I should proceed ?<br></div><div>Let me know if you need additional information. <br><br></div><div>Thanks<br><br></div><div>ps : I got some of my infos from this thread : <a href="http://matplotlib.1069221.n5.nabble.com/Structure-of-contour-object-returned-from-tricontourf-td44203.html" target="_blank">http://matplotlib.1069221.n5.nabble.com/Structure-of-contour-object-returned-from-tricontourf-td44203.html</a><br><br></div><div>ps2 : If I can write this function I would be happy to integrate it in the lib if you're interested.<br></div></div>
<br>_______________________________________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/matplotlib-users</a><br>
<br></blockquote></div><br></div>