1

I am using matplotlib to chart data with datetime.date as the x-axis.

Currently the graph has tick marks of the month and year in a certain range. As this range is too wide, the actual point for the price can't even be seen.

I want my matplotlib chart to plot x tick marks either:

  • for every date that is retrieved from the table, or
  • within a small enough range (e.g. 30 days within a month) so the price of the ticket on each of the days can be seen.

How can this be done?

I tried solutions from SO questions like this but they aren't working, probably because the dates from the table aren't of type float.

Here's an image of the chart:

enter image description here

Community
  • 1
  • 1
loremIpsum1771
  • 2,497
  • 5
  • 40
  • 87
  • 4
    The answer to [this](http://stackoverflow.com/questions/3486121/how-to-plot-data-against-specific-dates-on-the-x-axis-using-matplotlib?rq=1) should work for you. – cphlewis Aug 31 '15 at 00:52
  • @cphlewis The solution posted there enabled me to plot points for each date on the x-axis, but the problem is that I only have points for the entire year of 2015. For some reason, the `datetime.date` type can't be parsed and converted into a float that can be plotted. Should I convert the table column or is there another solution? I have the statement `import matplotlib.dates as dateToNum` and have `xs = [dateToNum.datestr2num(x[0]) for x in coordinateList]` to parse the query results. – loremIpsum1771 Aug 31 '15 at 22:22
  • I don't get your difficulty. If you made a complete runnable example like the linked one -- with the input data in the format you have, and an explanation of how the output plot differs from what you want -- it might be clearer. – cphlewis Sep 02 '15 at 03:06
  • @cphlewis nevermind I fixed the problem – loremIpsum1771 Sep 02 '15 at 04:03

0 Answers0