2017-05-22 7 views
0

이 주제에 대한 많은 질문을 발견했지만 파이썬에서 날짜 정보를 표시하는 기본 단계를 이해할 수 없습니다.matplotlib의 날짜를 NaN 값으로 플로팅

내 시계열 내 데이터가

>>> data.shape 
(8736,) 
#contains np.nan values!!! 

입니다

>>> datetime_series.shape 
(8736,) 
>>> datetime_series 
array([datetime.datetime(1979, 1, 2, 0, 0), 
     datetime.datetime(1979, 1, 2, 1, 0), 
     datetime.datetime(1979, 1, 2, 2, 0), ..., 
     datetime.datetime(1979, 12, 31, 21, 0), 
     datetime.datetime(1979, 12, 31, 22, 0), 
     datetime.datetime(1979, 12, 31, 23, 0)], dtype=object) 

입니다

내 코드를 지금 (내 내가 ... 시도 무엇입니까 주석)

fig,ax1 = plt.subplots() 
plt.plot(datetime_series,data) 
#plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%d-%m')) 
#plt.gca().xaxis.set_major_locator(mdates.DayLocator()) 
#plt.gcf().autofmt_xdate() 
#ax1.set_xlim([datetime_series[0],datetime_series[-1]) 
ax1.set_ylabel('Cumulative windspeed over open water [m/s]') 
#ax1.set_xlim(### how do I do this?? 
plt.title('My title') 
fig.tight_layout() 
plt.show() 

이것은 생산 빈 음모.

누구든지 datetime을 계획하는 단계를 안내 할 수 있다면 설명서와 stackoverflow 답변에 모두 다른 방법이있는 것 같아서 어디서부터 시작해야할지 이해할 수 없습니다. (예 : plot_date와 데이터가 그래프로 표시되지 않는 이유 plt.plot()

+1

날짜를 사용하는 방법에 대한 [공식 예 (https://matplotlib.org/2.0.1/examples/api/date_demo.html)가있다. – ImportanceOfBeingErnest

답변

1

잘 모르겠어요 -. 그것은이 NaN 값으로도 작동합니다이 예제를 확인, 어떻게 볼 데이터datetime_series 볼 수 있습니다 코멘트에 명시된 바와 같이 matplotlib에서 날짜를 사용하는 방법에 대한 공식 예제가 있습니다.이 값은 확실히 볼 가치가 있습니다.

import matplotlib.pyplot as plt 
import datetime 
import numpy as np 

# Generate some dummy data 
N = 500 
year = np.random.randint(1950,2000,N) 
month = np.random.randint(1,12,N) 
day = np.random.randint(1,28,N) 

datatime_series = np.array([datetime.datetime(*(dd+(0,0))) for dd in zip(year, month, day)]) 
datatime_series.sort() 

data = np.random.random(N)*20000 + (np.linspace(1950,2000,N)/10.)**2 

# Now add some NaNs 
for i in np.random.randint(0,N-1,int(N/10)): 
    data[i]=np.nan 

fig, ax = plt.subplots(1) 
ax.plot(datatime_series, data) 
ax.set_ylim(0,1.2*ax.get_ylim()[1]) 
fig.autofmt_xdate() 
fig.show() 

enter image description here

관련 문제