0

I want to plot time series data with dates on the X axis. The data was collected on different days with unequal distance between the dates. This is not the same thing as asked here matplotlib string to dates because they were asking how to convert date strings to plot. I'm not asking how to convert date strings to plot. My question is specifically about how to plot date data with unequal distance between dates.

Here's an example:

import matplotlib
import matplotlib.pyplot as plt
y = [1, 2, 3, 4, 5]
dates = ['2020-DEC-01', '2020-DEC-02', '2020-DEC-09', '2020-DEC-19', '2021-DEC-01']
days = [0, 1, 8, 18, 365]
%matplotlib notebook
fig,ax = plt.subplots(figsize=(10, 10))
ax.plot_date(dates, y, 'k', xdate=True)
ax.plot(days, y, 'k')`

When I plot the dates, the data points are equally spaced which is not what I want:

Data looks equally spaced even though the dates have different number of days between each date

What it should look like is something like this (except with dates on the x-axis labels):

Data with uneven spaced days between dates

How do I plot data with uneven amount of time between data points so that the x-axis accurately portrays the time duration scaled appropriately?

aguazul
  • 143
  • 2
  • 9
  • Please re-open this question. I think many people have a similar issue with data points unevenly spaced in time. – aguazul Dec 15 '20 at 22:30
  • And the duplicate provides you an answer for this problem. That is the point of the duplicate flag - that answers are concentrated in one question and not scattered all over the place. You are welcome to add a better answer to the duplicate question. – Mr. T Dec 15 '20 at 23:20
  • The "duplicate" does not provide an answer for this problem. The duplicate question has evenly spaced dates and only answers how to get the date labels to show on the x-axis. That is easy to do. This question is about how to get the x-axis to scale to show the relative time difference between different data points. I understand and support merging questions when they are the same question, that just makes sense. But when the questions are different they should not be merged. If the answer to this question is obvious in the duplicate, why not answer this question in those obvious terms? – aguazul Dec 15 '20 at 23:36
  • Also, the search terms someone might use to find the question may be different so having a similar question asked in different terms is helpful for discoverability and searching for solutions. – aguazul Dec 15 '20 at 23:37
  • 2
    @aguazul have you tried the code in the duplicate using discontinuous dates? It works exactly as you want. The whole point is that you need to convert your date strings to actual date objects so matplotlib knows how to space them. – MattDMo Dec 16 '20 at 01:45

0 Answers0