How do I plot only weekdays using Python’s matplotlib candlestick?

After your ‘quotes’ line:

weekday_quotes = [tuple([i]+list(quote[1:])) for i,quote in enumerate(quotes)]

then

candlestick(ax, weekday_quotes, width=0.6)

This will plot the data without the gaps between weekdays, now you have to change the xticks back to dates, preferably mondays. Assuming your first quote was a monday:

import matplotlib.dates as mdates

ax.set_xticks(range(0,len(weekday_quotes),5))
ax.set_xticklabels([mdates.num2date(quotes[index][0]).strftime('%b-%d') for index in ax.get_xticks()])

This is pretty gross but seems to get the job done – good luck!

Leave a Comment