您需要将日期转换为mdates.date2num
,因为
时间必须是浮动日格式 - 请参阅date2num
然后我尝试实现这个解决方案:
import pandas as pd import matplotlib.pyplot as plt from matplotlib.finance import candlestick_ohlc import matplotlib.dates as mdates #if necessary convert to datetime df.date = pd.to_datetime(df.date) df = df[['date', 'open', 'high', 'low', 'close', 'volume']] df["date"] = df["date"].apply(mdates.date2num) f1 = plt.subplot2grid((6, 4), (1, 0), rowspan=6, colspan=4, axisbg='#07000d') candlestick_ohlc(f1, df.values, #53c156', colordown='#ff1717') f1.xaxis_date() f1.xaxis.set_major_formatter(mdates.DateFormatter('%y-%m-%d %H:%M:%S')) plt.xticks(rotation=45) plt.ylabel('Stock Price') plt.xlabel('Date Hours:Minutes') plt.show()