消除python烛台日内ch中的日期时间间隔

2024-09-28 05:27:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力消除我的烛台图表中的空白。你知道吗

然而,在浏览了这里的大部分页面后,我仍然无法完全做到这一点。你知道吗

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


Tags: importdfdatetimeaspltstartlistend

热门问题