[Matplotlib-users] exporting tricontour function results

Benjamin Root ben.v.root at gmail.com
Mon Nov 30 13:37:26 EST 2015


Francis,

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.

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.

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.

Cheers!
Ben Root


On Mon, Nov 30, 2015 at 12:46 PM, Francis Chabouis <fchabouis at gmail.com>
wrote:

> Hello,
> 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).
>
> I wrote this :
>
> cs = plt.tricontourf(t, v, levels)
>
> for i,collection in enumerate(cs.collections):
>     for path in collection.get_paths():
>
>
> Now I have this path object.
>
> My first problem : when I check the number of vertices (via
> len(path.vertices)) I get 732 vertices.
> If I try to access those vertices with iter_segments as recommended in the
> doc, I get only 125 vertices.
> seg = path.iter_segments()
> print len(list(seg))
> ==> 125
>
> Am I doing something wrong, or is it possibly a bug ?
>
> 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 !
>
> Any hints on how I should proceed ?
> Let me know if you need additional information.
>
> Thanks
>
> ps : I got some of my infos from this thread :
> http://matplotlib.1069221.n5.nabble.com/Structure-of-contour-object-returned-from-tricontourf-td44203.html
>
> ps2 : If I can write this function I would be happy to integrate it in the
> lib if you're interested.
>
> _______________________________________________
> Matplotlib-users mailing list
> Matplotlib-users at python.org
> https://mail.python.org/mailman/listinfo/matplotlib-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151130/115bee23/attachment.html>


More information about the Matplotlib-users mailing list