2017-03-17 3 views
2

날짜 별 특정 이벤트의 분포를보고 싶습니다. 그래프의 각 점 사이의 시간을 일일이 볼 필요가 있습니다. 어떻게해야합니까? 여기그래프에서 점 사이의 일 수를 계산하고 입력하십시오.

date_time=[datetime.datetime.strptime(date_string, '%Y-%m-%d') for date_string in date_time] 

dates = matplotlib.dates.date2num(date_time) 

plt.scatter(date_time, [5]*len(dates)) 

plt.gcf().autofmt_xdate() 

plt.show() 
+1

berna1111 @에 대한 답 고맙습니다 ['텍스트 '(http://matplotlib.org/api/입니다 text_api.html? highlight = text # module-matplotlib.text)를 사용하여 [이 예제들] (http://matplotlib.org/gallery.html#text_labels_and_annotations)과 같이 레이블을 배치 할 수 있습니다. – berna1111

+0

@ berna1111 고맙습니다. 그것은 작동합니다. –

답변

1

enter image description here 당신이 사용할 수있는

enter image description here

plt.scatter(date_time, [5]*len(date_time)) 
s = date_time[0] 
p=0 
for i in date_time[1:]: 
    l = (i - s).days 
    #print(i , '-', s, '=', l) 
    s=date_time[date_time.index(i)] 
    if l > 30: 
     plt.text(i,5.001,l) 
     plt.text(i,4.999-p,i.date()) 
     p+=0.001 
     if p == 0.002: 
      p = 0 
plt.gcf().autofmt_xdate() 

plt.show() 
관련 문제