'Plotting minute data for a year, but only showing beginning of the month on x axis

I have three datasets, each with a year's worth of data points with '%Y-%m-%d %H:%M:%S' format timestamps.

The number of values per day and month vary within the dataset and between the datasets. Example:

  • dataset 1: 2021-01-01 17:38:00, 200.45

    2021-01-01 20:24:00, 202.59

    2021-01-02 00:03:00, 204.62

  • dataset 2: 2021-01-01 17:49:00, 208.99

    2021-01-01 18:39:00, 203.87

    2021-01-01 21:01:00, 206.47

    2021-01-01 21:35:00, 209.96

    2021-01-02 03:31:00, 204.76

I want to plot the data for each datatset such that on x axis it only shows the beginning of the month. I want to overlay the three graphs to see if they start showing the same upward/downward trend at the same time.

So far I have issue getting pyplot to correctly plot monthly ticks only:

locator = md.MonthLocator() 
fmt = md.DateFormatter('%b')
plt.plot(times,data)
X = plt.gca().xaxis
X.set_major_locator(locator)
X.set_major_formatter(fmt)
plt.show()

enter image description here



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source