Created
July 31, 2020 13:59
-
-
Save finiteautomata/fbbccbce1d82d79849b7104729d7f156 to your computer and use it in GitHub Desktop.
Seaborn distplot for dates
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 datetime | |
| import seaborn as sns | |
| import matplotlib.pyplot as plt | |
| # Generate dates -- change by your actual dates! | |
| dates = [datetime.datetime.fromordinal(int(d)) for d in (43 * np.random.randn(200) + 737555)] | |
| # Go back to ordinal numbers... | |
| ordinal_dates = np.array([d.toordinal() for d in dates]) | |
| sns.distplot(ordinal_dates, kde=True) | |
| # Now, get the positions of the xticks | |
| ticks_locations, _ = plt.xticks(); | |
| # Get the labels for those positions | |
| labels = [datetime.datetime.fromordinal(int(t)).date() for t in ticks_locations] | |
| plt.xticks(ticks_locations, labels, rotation=90) | |
| plt.title("Date distribution"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment