2013-10-17 5 views
6

배경

the documentation example here에서 코드 스 니펫으로 다음 등고선 플롯을 쉽게 생성 할 수 있습니다.matplotlib의 윤곽선에서 좌표를 가져 옵니까?

import matplotlib 
import numpy as np 
import matplotlib.cm as cm 
import matplotlib.mlab as mlab 
import matplotlib.pyplot as plt 

matplotlib.rcParams['xtick.direction'] = 'out' 
matplotlib.rcParams['ytick.direction'] = 'out' 

delta = 0.025 
x = np.arange(-3.0, 3.0, delta) 
y = np.arange(-2.0, 2.0, delta) 
X, Y = np.meshgrid(x, y) 
Z1 = mlab.bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0) 
Z2 = mlab.bivariate_normal(X, Y, 1.5, 0.5, 1, 1) 
# difference of Gaussians 
Z = 10.0 * (Z2 - Z1) 

# Create a simple contour plot with labels using default colors. The 
# inline argument to clabel will control whether the labels are draw 
# over the line segments of the contour, removing the lines beneath 
# the label 
plt.figure() 
CS = plt.contour(X, Y, Z) 
plt.clabel(CS, inline=1, fontsize=10) 
plt.title('Simplest default with labels') 

enter image description here

내 목표

내 윤곽 플롯을 얻은 한편 matplotlib.contour.QuadContourSet 예를 CS을 가지고있다. 예제 스 니펫에서 CSclabel()에만 사용됩니다. 그러나 제 경우에는 등고선의 방정식이나 차후 계산을위한 좌표 세트 중 하나를 얻어야합니다.

CS 인스턴스에서 등고선 좌표를 추출하려면 어떻게해야합니까? 또는 다른 방법으로 어떻게 구현할 수 있습니까?

내가 그렇게 할 방법이 틀림 없음. 그렇지 않으면 윤곽선은 "시각화를위한 화병"일뿐입니다.

+1

http://scikit-image.org/docs/dev/auto_examples/plot_contours.html – tacaswell

답변

10

CS.allsegs 목록에서 윤곽선의 좌표를 가져올 수 있습니다.

보십시오

dat0= CS.allsegs[0][0] 
plt.plot(dat0[:,0],dat0[:,1]) 

가 제 (-1) 형상 레벨 음모.

+0

동일한 값으로 여러 등고선 레벨이있는 ​​경우 여러 개의 등고선 레벨을 말합니다 ... 어떻게 추출 할 수 있습니까? 이 모든 값들의 집합의 좌표? – max29

+0

명확히하기 : 동일한 윤곽선 레벨 값, 즉 여러 개의 (-1) 윤곽선 영역에 여러 개의 영역이있는 경우 어떻게해야합니까? 이러한 모든 영역 세트의 좌표를 어떻게 추출 할 수 있습니까? – max29

+0

모든 개별 등고선은 2 차원 배열 (CS.allsegs)에 배치됩니다. 이 배열을 검사하면 동일한 등고선 값에 해당하는 선이 동일한 첫 번째 색인에 배치됩니다. – Jakob

관련 문제