I try to plot a Pandas Dataframe
with the matplotlib.pyplot
package mpl_finance
for a proper Candlestick chart. The plotting works but the date range of the x-axis is wrong. The header of the Dataframe
is the following:
The mpl_finance
method candlestick_ohlc
needs the time in the float date format so I convert the dates with the folowing method df_ohlc['Datum'] = df['Datum'].map(mdates.date2num)
.
After the conversion i plot the chart
fig = plt.figure()
ax1 = fig.add_subplot(111)
candlestick_ohlc(ax1, df_ohlc.values, colorup='g', width=0.6)
ax1.xaxis_date()
ax1.xaxis.set_major_formatter(mdates.DateFormatter('%d-%b'))
fig.autofmt_xdate()
plt.show()
But the plot differs from the Dataframe. In the Dataframe the period 2017-12-23 - 2017-12-26 is missing but the plot creates this date range.
Comment the date formatting lines doesn't help. When I plot the float values, I get the same plot.
Edit: I've added my sample code for the Dataframe creation.
df = pd.read_csv('wkn_766403_historic.csv', sep=';', thousands='.', decimal=',',
usecols=['Datum', 'Erster', 'Hoch', 'Tief', 'Schlusskurs'], parse_dates=True, index_col='Datum')
df.index = df.index.tz_localize('Europe/Berlin')
df = df.sort_index()
df = df.loc['2017-12-20':'2017-12-29']
df = df.reset_index()
df_ohlc = df.copy()
df_ohlc['Datum'] = df['Datum'].map(mdates.date2num)