调用轮廓而无需绘制轮廓,python,pylab内联 [英] calling contour without plotting it, python, pylab inline

查看:112
本文介绍了调用轮廓而无需绘制轮廓,python,pylab内联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于一种算法,我正在使用轮廓,但是我只对它的路径集合感兴趣。由于我已经致电

For an algorithm I am using contour, but I'm only interested in its collection of paths. Since I have called

pylab inline

从一开始,现在不使用内联代码重写代码就太痛苦了(必须更仔细地声明许多函数,例如np.something()而不是something()等)。 ..),我想知道是否可以在不绘制轮廓图的情况下调用轮廓?

from the start, and it is now too painful to rewrite the code without the inline (many functions have to be declared more carefully, like np.something() instead of something(), etc...), I was wondering if there is a way to call contour without it plotting the contour map ? Something like

contour(image_matrix, 'No Show')? 

致谢

推荐答案

以下是修改后的代码,用于在声明的网格中获取单位圆上的点。

The following is a modified code i used to get the points on a unit circle within in a declared meshgrid. It gives the contour points faster than plt.contour and doesn't plot the points.

matplotlib._cntr是plt.contour调用的核心函数,它试图获取轮廓点,而不是绘制点。轮廓点。

The matplotlib._cntr is the core function called by plt.contour which tries to get the contour points.

import matplotlib._cntr as cntr
import numpy as np

# Test data.
x = np.linspace(-1, 1, 20)
y = np.linspace(-1, 1, 20)

x, y = np.meshgrid(x, y)
z = x**2 + y**2 - 1            # Function to get points from
# the above function can be replaced with any curve equation
# conics like ellipse or hyperbola: ((x**2)/a)+((y**2)/b)-1,etc. 


level = 0
c = cntr.Cntr(x, y, z)
nlist = c.trace(level, level, 0)
segs = nlist[:len(nlist)//2]
print segs[0][0]    # x,y coords of contour points.

很抱歉,我的python经验不足。有关详细说明,请参见下面的链接。

Sorry for the poor explaination, I am not experienced enough with python. For a detailed explanation so you can refer to the link below.

与讨论的链接:
http://matplotlib.1069221.n5.nabble.com/ pyplot-Extract-contourset-without-plotting-td15868.html

link to discussion: http://matplotlib.1069221.n5.nabble.com/pyplot-Extract-contourset-without-plotting-td15868.html

在讨论结束时,Ian Thomas先生附加了代码

At the end of discussion Mr.Ian Thomas has attached a code 'contour_test.py' which may be of help to you.

链接到示例代码:
http://matplotlib.1069221.n5.nabble.com/attachment/15872/ 0 / contour_test.py

link to sample code: http://matplotlib.1069221.n5.nabble.com/attachment/15872/0/contour_test.py

这篇关于调用轮廓而无需绘制轮廓,python,pylab内联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆