python - How do I plot a histogram of months with dates in matplotlib -


so here problem, need solve matplotlib. have found variants of online have new wrinkle cannot seem figure out based on those.

i have list of dates in format

  1. 20160522
  2. 20160527
  3. 20160626
  4. 20160725...

and need make histogram of relative frequencies of months. histogram have actual month labels on there x-axis has labels "jan", "feb", etc...

how do matplotlib dates routines? seems though don't play nicely histograms in manner looking @ monthly distribution , not days or years....

an easy solution might following:
don't need use datetime objects @ all, convert list of datestrings list of month numbers, e.g. "20150419" maps 4. list can plotted histogram. in order months' names, may write them down or obtain them list of datetime objects.

import numpy np import matplotlib.pyplot plt import datetime  dates = ["20150204", "20150404","20151004","20151005", "20151007","20150704",          "20160404", "20160522","20160527","20160626", "20160725","20170223"] dtm = lambda x: int(x[4:6]) months = list(map(dtm, dates))  fig, ax = plt.subplots() bins = np.arange(1,14) ax.hist(months, bins = bins, edgecolor="k", align='left') ax.set_xticks(bins[:-1]) ax.set_xticklabels([datetime.date(1900,i,1).strftime('%b') in bins[:-1]] )  plt.show() 

enter image description here


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -