栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Python:查找等高线matplotlib.pyplot.contour()

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Python:查找等高线matplotlib.pyplot.contour()

通过在集合和路径上循环并使用
的“iter_segments()”方法

matplotlib.path.Path
.

下面是一个函数,它将顶点作为
等高线、等高线截面和x、y顶点阵列:

import numpy as npdef get_contour_verts(cn):    contours = []    # for each contour line    for cc in cn.collections:        paths = []        # for each separate section of the contour line        for pp in cc.get_paths(): xy = [] # for each segment of that section for vv in pp.iter_segments():     xy.append(vv[0]) paths.append(np.vstack(xy))        contours.append(paths)    return contours

Edit:

也可以在不绘制任何东西的情况下使用
未记录的

matplotlib.u cntr
C模块:

from matplotlib import pyplot as pltfrom matplotlib import _cntr as cntrz = np.array([[0.350087, 0.0590954, 0.002165],   [0.144522,  0.885409, 0.378515],   [0.027956,  0.777996, 0.602663],   [0.138367,  0.182499, 0.460879],    [0.357434,  0.297271, 0.587715]])x, y = np.mgrid[:z.shape[0], :z.shape[1]]c = cntr.Cntr(x, y, z)# trace a contour at z == 0.5res = c.trace(0.5)# result is a list of arrays of vertices and path pres# (see docs for matplotlib.path.Path)nseg = len(res) // 2segments, pres = res[:nseg], res[nseg:]fig, ax = plt.subplots(1, 1)img = ax.imshow(z.T, origin='lower')plt.colorbar(img)ax.hold(True)p = plt.Polygon(segments[0], fill=False, color='w')ax.add_artist(p)plt.show()


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/385578.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号