import matplotlib.pyplot as plt
import matplotlib.finance as mpf
with open('SH#600004.txt') as obj:
text=obj.readlines()
baseinfo=text[0]
dayinfo=text[2:-1]
date_list =[dayinfo[i].split(',')[0] for i in range(len(dayinfo))]
open_list =[dayinfo[i].split(',')[1] for i in range(len(dayinfo))]
high_list =[dayinfo[i].split(',')[2] for i in range(len(dayinfo))]
low_list =[dayinfo[i].split(',')[3] for i in range(len(dayinfo))]
close_list=[dayinfo[i].split(',')[4] for i in range(len(dayinfo))]
quotes=zip(date_list,open_list,high_list,low_list,close_list)
#N=100
#open_list[:N],high_list[:N],low_list[:N],close_list[:N]
fig,ax=plt.subplots()
mpf.candlestick_ohlc(ax,quotes,width=0.6,colorup='r',colordown='green')
plt.title(baseinfo)
plt.xlabel(date_list)
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
plt.show()
#以下是报错信息
C:\ProgramData\Anaconda3\python.exe G:/python/test/test.py
C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\cbook\deprecation.py:106: MatplotlibDeprecationWarning: The finance module has been deprecated in mpl 2.0 and will be removed in mpl 2.2. Please use the module mpl_finance instead.
warnings.warn(message, mplDeprecation, stacklevel=1)
Traceback (most recent call last):
File "G:/python/test/test.py", line 18, in
mpf.candlestick_ohlc(ax,quotes,width=0.6,colorup='r',colordown='green')
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\finance.py", line 737, in candlestick_ohlc
alpha=alpha, ochl=False)
File "C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\finance.py", line 794, in _candlestick
height = open - close
TypeError: unsupported operand type(s) for -: 'str' and 'str'
我搜了下知道日期格式转换需要用到date2num这个函数 我的文本里面日期格式是XXXX/XX/XX的形式 请问quotes一项里日期需求的格式是什么?