2013-08-29 3 views
1

기본적으로 몇 가지 2d 히스토그램을 함께 추가해야하지만이 작업을 수행하는 방법이 확실하지 않습니다. 전에 내가 단일 히스토그램을 위해 그것을했을 때 나는 이것을 좋아했다. ...2 차원 히스토그램을 그리는 방법은 무엇입니까?

enter for i in range(0,BMI[ind_2008].shape[0]): 

id_temp=ID[ind_2008[i]]  
ind_2009_temp=np.where(ID[ind_2009] == id_temp) 
actual_diff=BMI[ind_2008[i]]-BMI[ind_2009[ind_2009_temp]] 
diff=np.abs(BMI[ind_2008][i]-BMI_p1) 
pdf_t, bins_t=np.histogram(diff,bins=range_v-1,range=(0,range_v)) 
if i == 0: 
    pdf=pdf_t 
    pdf[:]=0.0 
pdf=pdf+pdf_t 

bincenters = 0.5*(bins_t[1:]+bins_t[:-1]) 
fig3=plt.figure() 
plt.plot(bincenters,pdf) 

Heres는 2d 히스토그램에 대해 가지고있는 코드이다. 코드 내가 '튜플 개체 항목 할당을 지원하지 않습니다'라는 오류 메시지가 순간이기 때문에

for i in range(0,BMI[ind_2008].shape[0]): 
    diff_BMI=np.abs(BMI[ind_2008][i]-BMI_p1) 
    diff_DOB=np.abs(dob_j[ind_2008][i]-dob_jwp1) 
    hist=np.histogram2d(diff_BMI,diff_DOB,bins=(35,1000)) 
    if i == 0: 
     pdf=hist 
     pdf[:]=0.0 
     pdf=pdf+hist 
fig3=plt.figure() 
plt.plot(pdf) 

나는 오류 메시지가 있지만 그것을 해결하는 방법을 확실하지 메신저 무엇을 의미하는지 이해합니다. 어떤 도움을

+0

당신은 [여기를보세요] (http://stackoverflow.com/a/16496996/832621) 어쩌면 그것은 당신에게 더 많은 통찰력을 줄 수 있습니다 ... –

답변

1

histogram2d 함수는 트리플 반환합니다 ... 감사합니다 :

H : ndarray, shape(nx, ny) 
    The bi-dimensional histogram of samples `x` and `y`. Values in `x` 
    are histogrammed along the first dimension and values in `y` are 
    histogrammed along the second dimension. 
xedges : ndarray, shape(nx,) 
    The bin edges along the first dimension. 
yedges : ndarray, shape(ny,) 
    The bin edges along the second dimension. 

그래서 함수 호출은 다음과 같은 모양입니다 :

H, xedges, yedges = np.histogram2d(diff_BMI, diff_DOB, bins=(35,1000)) 

그리고 당신은 히스토그램을 사용하여 조작을 수행 할 수 있습니다 H. 그러나 np.histogram 함수의 경우와 같이 1 차원 배열이 아니라 2 차원 배열임을 명심하십시오.

+0

Im 'H , xedges, yedges = '실제로 않습니다. 설명해 주시겠습니까? – blablabla

+1

@blablabla'np.histogram '과 같은 일을합니다. 코드를 살펴보면'pdf_t, bins_t = np.histogram (...)'이라는 줄이있다. 이것은'histogram' 함수가'pdf_t'와'bins_t'에 저장 한 두 개의 값을 반환한다는 것을 의미한다. 변수. 'np.histogram2d'는 3 개의 값을 반환하는데,이 경우에는'H','xedges'와'yedges' 변수에 저장됩니다. 그러나 원하는대로 변수를 호출 할 수 있습니다. –

+0

아, 완벽하게 이해할 수 있습니다. 도움을 주셔서 감사합니다. – blablabla

관련 문제