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

后端 未结 4 1819
慢半拍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 00:55

    The vertices of an all paths can be returned as a numpy array of float64 simply via:

    cn.allsegs[i][j]  # for element j, in level i
    

    More detailed:

    Going through the collections and extracting the paths and vertices is not the most straight forward or fastest thing to do. The returned Contour object actually has attributes for the segments via cs.allsegs, which returns a nested list of shape [level][element][vertex_coord]:

    num_levels = len(cn.allsegs)
    num_element = len(cn.allsegs[0])  # in level 0
    num_vertices = len(cn.allsegs[0][0])  # of element 0, in level 0
    num_coord = len(cn.allsegs[0][0][0])  # of vertex 0, in element 0, in level 0
    

    See reference: https://matplotlib.org/3.1.1/api/contour_api.html

提交回复
热议问题