sns datetime histogram

Solutions on MaxInterview for sns datetime histogram by the best coders in the world

showing results for - "sns datetime histogram"
Erik
24 May 2017
1import datetime
2import seaborn as sns
3import matplotlib.pyplot as plt
4# Generate dates -- change by your actual dates!
5dates = [datetime.datetime.fromordinal(int(d)) for d in (43 * np.random.randn(200) + 737555)]
6# Go back to ordinal numbers...
7ordinal_dates = np.array([d.toordinal() for d in dates])
8sns.distplot(ordinal_dates, kde=True)
9# Now, get the positions of the xticks
10ticks_locations, _ = plt.xticks();
11# Get the labels for those positions
12labels = [datetime.datetime.fromordinal(int(t)).date() for t in ticks_locations]
13plt.xticks(ticks_locations, labels, rotation=90)
14plt.title("Date distribution");