Skip to content

Instantly share code, notes, and snippets.

@dcbark01
Created June 26, 2019 19:16
Show Gist options
  • Save dcbark01/9102e9618aad63eeadaa3bbf43019f2c to your computer and use it in GitHub Desktop.
Save dcbark01/9102e9618aad63eeadaa3bbf43019f2c to your computer and use it in GitHub Desktop.
plot_dates function in Matplotlib for Python - super useful
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# if your dates are strings you need this step
df.Date = pd.to_datetime(df.Date)
fig,ax = plt.subplots()
ax.plot_date(df.Date,df.A)
ax.plot_date(df.Date,df.B)
ax.xaxis.set_major_locator(mdates.YearLocator())
ax.xaxis.set_major_formatter(mdates.DateFormatter('%b\n%Y'))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment