I have data in a file (.dat) in the format of
%dd %mm %yyyy %HH %MM %SS value
separated by spaces. I would like to plot the day, month, year and time on the x-axis, and the value on the y-axis. It should always be reading it from the file, as I have many files that are very large to analyze.
My latest attempt:
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from time import gmtime, strftime
date, time, level = np.loadtxt('my_file.txt', unpack=True, usecols = (0,1,2,3), converters={ 0,1: mdates.strpdate2num('%dd/%mm/%YY %HH:%MM')}) #read format of file
# then to plot
plt.plot_date(x=date, y=level, fmt='%dd/%mm/%YY %HH:%MM') # fmt is changed from r-
plt.title('title')
plt.ylabel('Waterlevel (m)')
plt.grid(True)
plt.show()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…