Python: find contour lines from matplotlib.pyplot.contour()

后端 未结 4 1820
慢半拍i
慢半拍i 2020-11-29 00:21

I\'m trying to find (but not draw!) contour lines for some data:

from pprint import pprint 
import matplotlib.pyplot 
z = [[0.350087, 0.0590954, 0.002165],          


        
4条回答
  •  时光说笑
    2020-11-29 01:16

    It seems that the contour data is in the .allsegs attribute of the QuadContourSet object returned by the plt.contour() function.

    The .allseg attribute is a list of all the levels (which can be specified when calling plt.contour(X,Y,Z,V). For each level you get a list of n x 2 NumPy arrays.

    plt.figure()
    C = plt.contour(X, Y, Z, [0], colors='r')
    
    plt.figure()
    for ii, seg in enumerate(C.allsegs[0]):
        plt.plot(seg[:,0], seg[:,1], '.-', label=ii)
    plt.legend(fontsize=9, loc='best')
    

    In the above example, only one level is given, so len(C.allsegs) = 1. You get:

    contour plot

    the extracted curves

提交回复
热议问题