2016-08-17 1 views
0

파이썬에서 살펴본 일부 배열 데이터의 표준 편차를 표시하려고합니다. 그러나 데이터는 경도와 위도 (축의 2/3)에서 평균을 구합니다. 내가 지금까지 가지고있는 것은 월간 계획이며, 표준 편차를 구할 수는 없다. Monthly plot2 축에서 오류 막대를 그릴 것

나는이 문제를 해결하는 방법을 알고 있는지 궁금했다. 지금까지 내가 사용한 코드는 다음과 같습니다. 도움을 주시면 감사하겠습니다.

# import things 
import matplotlib.pyplot as plt 
import numpy as np 
import netCDF4 

# [ date, hour, 0, lon, lat ] 
temp = (f.variables['TEMP2'][:, 14:24, 0, :, :]) # temp at 2m 
temp2 = (f.variables['TEMP2'][:, 0:14, 0, :, :]) 

# concatenate back to 24 hour period 
tercon = np.concatenate((temp, temp2), axis=1) 

ter1 = tercon.mean(axis=(2, 3)) 

rtemp = np.reshape(ter1, 672)-273 

# X axis dates instead of times 
date = np.arange(rtemp.shape[0]) # assume that delta time between data is 1 
date21 = (date/24.) # use days instead of hours 

# change plot size for monthly 
rcParams['figure.figsize'] = 15, 5 

plt.plot(date21, rtemp , linestyle='-', linewidth=3.0, c='orange') 

답변

0

당신해야 대신 ploterrorbar 및 통과 미리 계산 된 표준 편차. 다음의 수정 된 예제는 무작위 데이터를 사용하여 시간별 해상도로 온도 데이터를 에뮬레이션하고 데이터와 표준 편차를 누적합니다.

# import things 
import matplotlib.pyplot as plt 
import numpy as np 

# x-axis: day-of-month 
date21 = np.arange(1, 31) 
# generate random "hourly" data 
hourly_temp = np.random.random(30*24)*10 + 20 
# mean "temperature" 
dayly_mean_temp = hourly_temp.reshape(24,30).mean(axis=0) 
# standard deviation per day 
dayly_std_temp = hourly_temp.reshape(24,30).std(axis=0) 

# create a figure 
figure = plt.figure(figsize = (15, 5)) 
#add an axes to the figure 
ax = figure.add_subplot(111) 
ax.grid() 

ax.errorbar(date21, dayly_mean_temp , yerr=dayly_std_temp, fmt="--o", capsize=15, capthick=3, linestyle='-', linewidth=3.0, c='orange') 

plt.show() 
+0

안녕하세요. 방금 배열을 바꿀 방법을 알아 내야했습니다. :) –

관련 문제