Вы можете попробовать установить set_major_formatter
формат:
Подход 1
Путем изменения формата оси x напрямую. Но по умолчанию matplotlib будет показывать только время в формате hh: 00: 00.
import datetime
import matplotlib.pyplot as plt
from matplotlib import dates
x = [datetime.datetime.now() + datetime.timedelta(hours=i) for i in range(10)]
fig, ax = plt.subplots()
y = ['54.2', '54.8', '54.2', '54.8', '55.3', '55.3', '55.3', '55.3', '54.8', '54.8']
# plot
plt.plot(x,y)
# beautify the x-labels
plt.gcf().autofmt_xdate()
## create x-axis hour format
ax.xaxis.set_major_formatter(dates.DateFormatter("%H:%M"))
plt.show()
Подход 2
Вы можете изменить значение метки оси x напрямую, используя метод set_xticklabels
. Просто добавьте приведенный ниже код
plt.plot(x,y)
# beautify the x-labels
plt.gcf().autofmt_xdate()
## create x-axis hour format
ax.xaxis.set_major_formatter(dates.DateFormatter("%H:%M"))
x_hours = [date_str.strftime("%H:%M:%S") for date_str in x]
ax.set_xticklabels(x_hours)
plt.show