使用matplotlib进行等高线计算。
contours的Python项目详细描述
等高线-使用matplotlib进行等高线计算
contours包向用户公开matplotlib的轮廓生成器 提供与Matlab的contourc函数等价的函数。这是为了 网格(包括曲线)以及通过Delaunay的非结构化数据 三角剖分(future)。
规则等高线可以作为NumPy数组或Shapely数组返回 线串和线边。填充轮廓可以返回为NumPy 数组或作为Shapely多边形。
不绘制等高线计算目前是 MatplotLib。在那次讨论中,这个库中的黑客类型是 被matplotlib开发人员劝阻。在写这篇文章之前 决定曝光轮廓计算是否是 是否包含在matplotlib中。如果matplotlib中的这种重构 发生时,将重构此库以避免使用matplotlib的 内部组件。
功能
- 填充轮廓和非填充轮廓。
- 规则网格上的等高线。
- todo非结构化数据上的等高线。
示例
使用QuadContourGenerator计算面积和 圆和环的周长。
>>> from contours.core import shapely_formatter as shapely_fmt >>> from contours.quad import QuadContourGenerator >>> import numpy as np >>> x = np.arange(-1, 1+0.01, 0.01) >>> y = np.arange(-1, 1+0.01, 0.01) >>> z = np.sqrt(x[:, np.newaxis]**2 + y[np.newaxis, :]**2) >>> c = QuadContourGenerator.from_rectilinear(x, y, z, shapely_fmt) >>> contour = c.filled_contour(max=1.0) >>> print('Area: {:0.2f}'.format(contour[0].area)) Area: 3.14 >>> print('Length: {:0.2f}'.format(contour[0].length)) Length: 6.28 >>> contour = c.filled_contour(min=0.5, max=1.0) >>> print('Area: {:0.2f}'.format(contour[0].area)) Area: 2.36 >>> print('Length: {:0.2f}'.format(contour[0].exterior.length)) Length: 6.28 >>> print('Length: {:0.2f}'.format(contour[0].interiors[0].length)) Length: 3.14
测试
todo