Daniel,

Following on from Eric's comments, attached is the simplest example I could
come up with to do what you want.  For non-filled contours, the 'segs' (last
few lines of the file) should be fairly self-explanatory, and this is
hopefully what you want.  If you are after filled contours, you will need to
understand both the 'segs' and the 'kinds' - essentially the segs comprise
one or more discontinuous closed line loops and the corresponding kinds
indicate how the loops are split up, a 1 being a LINETO and a 2 being a
MOVETO.  This can get a little awkward, and I think that sometimes you need
to deal with arrays of arrays but I can't completely remember all the
details.

You should bear in mind that this code delves into matplotlib internals and
you need to be careful as
1) it bypasses various sanity checks,
2) the underlying code could change at any point in the future (it has quite
a lot in the last year for example).

Otherwise, I hope it helps!

Ian
import matplotlib._cntr as cntr
import numpy as np
import numpy.ma as ma


# Make your choice of filled contours or contour lines here.
wantFilledContours = True


# Test data.
x = np.arange(0, 10, 1)
y = np.arange(0, 10, 1)
x, y = np.meshgrid(x, y)
z = np.sin(x) + np.cos(y)

z = ma.asarray(z, dtype=np.float64)  # Import if want filled contours.

if wantFilledContours:
    lower_level = 0.5
    upper_level = 0.8
    c = cntr.Cntr(x, y, z.filled())
    nlist = c.trace(lower_level, upper_level, 0)
    nseg = len(nlist)//2
    segs = nlist[:nseg]
    kinds = nlist[nseg:]
    print segs    # x,y coords of contour points.
    print kinds   # kind codes: 1 = LINETO, 2 = MOVETO, etc.
                  # See lib/matplotlib/path.py for details.
else:
    # Non-filled contours (lines only).
    level = 0.5
    c = cntr.Cntr(x, y, z)
    nlist = c.trace(level, level, 0)
    segs = nlist[:len(nlist)//2]
    print segs    # x,y coords of contour points.
------------------------------------------------------------------------------
Special Offer-- Download ArcSight Logger for FREE (a $49 USD value)!
Finally, a world-class log management solution at an even better price-free!
Download using promo code Free_Logger_4_Dev2Dev. Offer expires 
February 28th, so secure your free ArcSight Logger TODAY! 
http://p.sf.net/sfu/arcsight-sfd2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to