I have a data frame containing several columns for which I have continuous (annual) data since 1971 up to 2012. After that I have some say "predicted" values for 2020, 2025, 2030 and 2035. The index to the data frame is in integer format (each date), and I've tried converting it to a date time format using the appropriate module, but this still doesn't correctly space out the dates on the x-axis (to show the actual time-gaps) Here's the code I've been experimenting with:
fig, ax = plt.subplots()
# Set title
ttl = "India's fuel mix (1971-2012)"
# Set color transparency (0: transparent; 1: solid)
a = 0.7
# Convert the index integer dates into actual date objects
new_fmt.index = [datetime.datetime(year=date, month=1, day=1) for date in new_fmt.index]
new_fmt.ix[:,['Coal', 'Oil', 'Gas', 'Biofuels', 'Nuclear', 'Hydro','Wind']].plot(ax=ax,kind='bar', stacked=True, title = ttl)
ax.grid(False)
xlab = 'Date (Fiscal Year)'
ylab = 'Electricity Generation (GWh)'
ax.set_title(ax.get_title(), fontsize=20, alpha=a)
ax.set_xlabel(xlab, fontsize=16, alpha=a)
ax.set_ylabel(ylab, fontsize=16, alpha=a)
# Tell matplotlib to interpret the x-axis values as dates
ax.xaxis_date()
# Make space for and rotate the x-axis tick labels
fig.autofmt_xdate()