'How to replace existing x-axis(numbers) with new x-axis(dates) in python, matplot

My code is fallowing:

import matploblib.pyplot as plt
dates_for_x = ['2020','2021','2022']
#Because of numerical process, I changed 'dates_for_x' to 'x'
x = [1,2,3]
y = [4,5,6]
plt.plot(x,y)

All elements in x correspond to specific dates as the given list, 'dates_for_x'.

How to replace x with dates_for_x when I plot?



Sources

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

Source: Stack Overflow

Solution Source