[Matplotlib-users] exporting tricontour function results

Francis Chabouis fchabouis at gmail.com
Mon Nov 30 12:46:32 EST 2015


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20151130/62327bc8/attachment.html>


More information about the Matplotlib-users mailing list