【发布时间】:2011-08-05 16:21:33
【问题描述】:
我想从均匀分布的二维数据(类似图像的数据)的单个轮廓中获取数据。
基于在类似问题中找到的示例:How can I get the (x,y) values of the line that is ploted by a contour plot (matplotlib)?
>>> import matplotlib.pyplot as plt
>>> x = [1,2,3,4]
>>> y = [1,2,3,4]
>>> m = [[15,14,13,12],[14,12,10,8],[13,10,7,4],[12,8,4,0]]
>>> cs = plt.contour(x,y,m, [9.5])
>>> cs.collections[0].get_paths()
调用cs.collections[0].get_paths()的结果是:
[Path([[ 4. 1.625 ]
[ 3.25 2. ]
[ 3. 2.16666667]
[ 2.16666667 3. ]
[ 2. 3.25 ]
[ 1.625 4. ]], None)]
根据绘图,这个结果是有意义的,并且似乎是等高线的 (y,x) 对的集合。
除了手动循环这个返回值、提取坐标并为线组装数组之外,还有更好的方法从matplotlib.path 对象中获取数据吗?从matplotlib.path 提取数据时是否需要注意一些陷阱?
或者,在matplotlib 或更好的numpy/scipy 中是否有替代方案来做类似的事情?理想的做法是获得描述线的 (x,y) 对的高分辨率向量,可用于进一步分析,因为通常我的数据集并不像上面的示例那样小或简单。
【问题讨论】:
标签: python numpy matplotlib scipy contour