2013-05-02 25 views
2

REC陣列我讀醃numpy的陣列,這種結構:情節numpy的帶有日期

>>> h.shape 
(256,) 
>>> h[:10] 
rec.array([(datetime.date(2011, 1, 2), 1, -3, 1014), 
     (datetime.date(2011, 1, 3), 3, -6, 1016), 
     (datetime.date(2011, 1, 4), 0, -9, 1023), 
     (datetime.date(2011, 1, 5), 1, -6, 1023), 
     (datetime.date(2011, 1, 6), 3, -2, 1026), 
     (datetime.date(2011, 1, 7), 2, -1, 1029), 
     (datetime.date(2011, 1, 8), -1, -1, 1027), 
     (datetime.date(2011, 1, 9), -1, -2, 1025), 
     (datetime.date(2011, 1, 10), -1, -2, 1025), 
     (datetime.date(2011, 1, 11), 3, 3, 1020)], 
     dtype=[('date', '|O4'), ('high', '|i1'), ('low', '|i1'), ('pres', '<i2')]) 

並不能找到如何使用matplotlib繪製。我試圖使用plt.plot_date(...),但在任何組合上我得到錯誤。有人能指出我正確的方向如何用X軸作爲日期和Y軸繪製任何其他值的簡單線圖,例如pres標記的數據?

+0

執行此工作[date_demo](http://matplotlib.org/examples/api/date_demo.html),並且還此[date_index_formatter](http://matplotlib.org/examples/api/date_index_formatter.html )? – gongzhitaao 2013-05-02 20:01:10

+0

啊,對了......我忘了關於recarray的視圖屬性。謝謝! – user2136786 2013-05-02 20:06:48

+2

那麼這是否回答你的問題?如果是這樣,你應該添加你做的答案並接受它。 – Iguananaut 2013-05-02 20:52:26

回答

0

鑑於hnumpy.recarray您可以通過使用

plt.plot_date(h.date, h.pres, linestyle='-', marker=None) 
plt.gcf().autofmt_xdate() # Optional; included to format x-axis for dates 

進一步定製可能需要的情節看你想要的方式實現了基本的繪圖。 enter image description here