删除python烛台盘中图表中的日期时间差距

时间:2019-05-08 10:52:22

标签: python python-3.x pandas matplotlib

我正在尝试消除盘中烛台图表中的差距。

但是,在浏览了这里的大多数页面之后,我仍然无法完全做到这一点。

import mpl_finance as mplf
import pandas as pd
from pandas.tseries.offsets import BDay
import matplotlib.dates as mdates
import matplotlib.pyplot as plt

def create_chart_minute(ticker,starttime=2,endtime=1,title="Missing"):
days=starttime-endtime
x = starttime
y = endtime
start = today - BDay(x)
end = today - BDay(y)
start = start.replace(hour=0, minute=0, second=0)
end = end.replace(hour=0, minute=0, second=0)

df = pd.read_csv('filefrom ticker.csv')
df['Datetime']=pd.to_datetime(df['Datetime'])
df=df[(df['Datetime'] > start) & (df['Datetime'] < end)]
daters=pd.to_datetime(df['Datetime'])
df['Datetime']= mdates.date2num(list(df['Datetime']))
dates=list(df['Datetime'])

o=list(df['open'])
c=list(df['close'])
h=list(df['high'])
l=list(df['low'])

quotes = [tuple([dates[i],o[i],c[i],h[i],l[i]]) for i in range(len(dates))]

fig, ax1 = plt.subplots()
mplf.candlestick_ochl(ax1, quotes, width=0.6/(24*60), colorup='g', colordown='r', alpha=0.8)

plt.xticks(rotation=30)
plt.grid()
plt.xlabel('Date')
plt.ylabel('Price')
plt.title('Data for ' + str(days) + ' in ' + str(ticker[1:]))
plt.tight_layout()
fig.autofmt_xdate()
plt.show()

我希望上面的代码产生一个连续的烛形图,而输出中没有缺口,如下所示。

Please see output here

0 个答案:

没有答案