Created
June 26, 2019 19:16
-
-
Save dcbark01/9102e9618aad63eeadaa3bbf43019f2c to your computer and use it in GitHub Desktop.
plot_dates function in Matplotlib for Python - super useful
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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