how to set date axes limits in matplotlib plot

The solution for “how to set date axes limits in matplotlib plot” can be found here. The following code will assist you in solving the problem.

import datetime
import matplotlib.pyplot as plt
plt.rcParams[“figure.figsize”] = [7.00, 3.50]
plt.rcParams[“figure.autolayout”] = True
x = [datetime.date(2021, 1, 1), datetime.date(2021, 1, 3), datetime.date(2021, 1,
5), datetime.date(2021, 1, 7)]
y = [1, 3, 5, 7]
fig, ax = plt.subplots()
ax.plot_date(x, y, markerfacecolor=’green’, markeredgecolor=’red’, ms=7)
fig.autofmt_xdate()
ax.set_xlim([datetime.date(2020, 12, 31), datetime.date(2021, 1, 8)])
ax.set_ylim([0, 8])
plt.show()

Thank you for using DeclareCode; We hope you were able to resolve the issue.

More questions on [categories-list]

0
inline scripts encapsulated in