如何在X轴上显示日期和时间

时间:2019-03-29 20:18:55

标签: python matplotlib

我有以下代码绘制了预期的输出:

import matplotlib.pyplot as plt
import csv
import datetime
import matplotlib.dates as mdates
import re

Time = []
station12SRV = []
station18SRV = []

with open('Book2.csv','r') as csvfile:
    plots = csv.reader(csvfile, delimiter=',')
    for row in plots:

        datetime_format = '%d/%m/%Y %H:%M'
        date_time_data = datetime.datetime.strptime(row[0],datetime_format)
        Time.append(date_time_data)
        station12SRV.append(float(row[1]))
        station18SRV.append(float(row[2]))

plt.plot(Time,station12SRV, label='Tracker Station 12')
plt.plot(Time,station18SRV, label='Tracker Station 18')

plt.xlabel('Date & Time')
plt.ylabel('Pressure (Torr)')
plt.yscale('log')
#plt.title('SRV Plot vs Time')
plt.legend()
plt.savefig('trackers_srv.pdf')
#plt.show()

但是,在绘图中,x轴不显示日期和时间,而仅显示时间:

The Plot

如何在x轴上同时显示日期和时间?谢谢。

0 个答案:

没有答案