4

I have a file with a list of dates, formatted as "YYYY-MM-DD". The data is well-structured, so I don't need to be concerned with outliers. I'm using a defaultdict to get the count of occurrences of each date. For example, the dictionary may look like:

2015-01-01 : 5
2015-01-15 : 3
2015-02-03 : 4
2015-02-04 : 2

I'd like to plot the counts as a histogram, where the spacing along the x-axis is commensurate with the dates. If there is a large gap between dates, I would like the bars to be spaced accordingly. Is this possible?

I've found a very similar question, How to plot data against specific dates on the x-axis using matplotlib, but this uses a line graph instead of bars, like a histogram.

Community
  • 1
  • 1
Adam_G
  • 7,337
  • 20
  • 86
  • 148
  • Do you mean *histogram* or *barplot* they're two different things. – Leb Nov 10 '15 at 16:27
  • Histogram. Sorry for the confusion – Adam_G Nov 10 '15 at 16:29
  • 1
    Possible duplicate of [python pandas: plot histogram of dates?](http://stackoverflow.com/questions/27365467/python-pandas-plot-histogram-of-dates) – jrjc Nov 10 '15 at 16:37
  • That's similar, but it uses equal spacing. I found a very similar answer, but it uses a line graph, not a histogram http://stackoverflow.com/questions/3486121/how-to-plot-data-against-specific-dates-on-the-x-axis-using-matplotlib?rq=1 – Adam_G Nov 10 '15 at 16:41
  • 1
    if you change the `graph.plot(x,y,'r-o')` to `graph.bar(x,y)` in that answer, is that close to what you want? – tmdavison Nov 10 '15 at 16:58
  • Yup, that'll do it. Close enough. Thank you – Adam_G Nov 10 '15 at 17:02
  • Does this answer your question? [Histogram in matplotlib, time on x-Axis](https://stackoverflow.com/questions/29672375/histogram-in-matplotlib-time-on-x-axis) – iacob Mar 21 '20 at 14:40
  • https://stackoverflow.com/questions/51321575/simplest-histogram-with-dates-as-x-axis-in-matplotlib – iacob Mar 21 '20 at 14:41

0 Answers0