1
我是matplotlib的新手,現在我很困惑。 的代碼如下:對於以下格式數據,我應該如何繪製matplotlib.finance的「K」圖?
import matplotlib.finance as mpf
import matplotlib.pyplot as plt
import tushare as ts
start = '2016-09-01'
end = '2016-09-30'
quotes = ts.get_hist_data('sh', start=start, end=end)
quote = quotes[['open', 'close', 'high', 'low']]
fig, ax = plt.subplots(figsize=(8, 5))
fig.subplots_adjust(bottom=0.2)
mpf.candlestick2_ochl(ax, opens, closes, highs, lows, width=0.6, colorup='k', colordown='r', alpha=0.75)
plt.grid(True)
ax.xaxis_date()
ax.autoscale_view()
plt.setp(plt.gca().get_xticklabels(), rotation=30)
plt.show()
的 「引用」 的的數據都是:
open close high low
date
2016-09-30 2994.25 3004.70 3009.20 2993.06
2016-09-29 2992.17 2998.48 3009.20 2991.91
2016-09-28 3000.70 2987.86 3000.70 2984.32
2016-09-27 2974.59 2998.17 2998.23 2969.13
2016-09-26 3028.24 2980.43 3028.24 2980.12
2016-09-23 3044.79 3033.90 3046.80 3032.80
2016-09-22 3038.42 3042.31 3054.44 3035.07
2016-09-21 3021.58 3025.87 3032.45 3017.54
2016-09-20 3027.17 3023.00 3027.82 3015.88
2016-09-19 3005.32 3026.05 3026.65 3005.32
2016-09-14 3008.90 3002.85 3017.94 2995.42
2016-09-13 3025.03 3023.51 3029.72 3008.74
2016-09-12 3037.51 3021.98 3040.95 2999.93
2016-09-09 3095.43 3078.85 3101.79 3078.22
2016-09-08 3089.95 3095.95 3096.78 3083.90
2016-09-07 3091.33 3091.93 3105.68 3087.88
2016-09-06 3071.06 3090.71 3095.51 3053.19
2016-09-05 3070.71 3072.10 3085.49 3065.33
2016-09-02 3057.49 3067.35 3072.53 3050.49
2016-09-01 3083.96 3063.31 3088.70 3062.88
而且我得到這個錯誤:
ValueError: ordinal must be >= 1
如何將我解決呢?
額外的代碼是在這裏:'''=打開引號[ '開放' ] \ closes = quotes ['close'] \ highs = quotes ['high'] \ lows = quotes ['low']''' – ipreacher