I'm trying to plot a time-series data from a csv file using Matplotlib. Below are the first few lines from the csv file.
YYYY-MO-DD HH-MI-SS_SSS,X,Y,Z
2019-12-15 11:01:35.000,-0.2937,0.8477,2.2274
2019-12-15 11:01:35.005,-0.2937,0.8477,2.2274
2019-12-15 11:01:35.010,-0.2937,0.8477,2.2274
2019-12-15 11:01:35.014,0.3231,-1.7574,-4.6244
2019-12-15 11:01:35.021,0.3231,-1.7574,-4.6244
2019-12-15 11:01:35.025,0.3231,-1.7574,-4.6244
2019-12-15 11:01:35.030,0.7319,-4.9294,-4.6236
2019-12-15 11:01:35.035,0.7319,-4.9294,-4.6236
The interval is 5 milliseconds (200 Hz) and the file contains one second worth of data (200 rows). My goal is to set the major x-ticks every 100 milliseconds, that is:
35.000, 35.100, 35.200, ...., 35.800, 35.900
I tried using the dateFormatter but cannot manage. How can I do this?
#import packages
from matplotlib import pyplot as plt
from matplotlib import dates
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
import pandas as pd
import numpy as np
#import math
%matplotlib inline
df = pd.read_csv("one-second.csv",index_col="YYYY-MO-DD HH-MI-SS_SSS",parse_dates=True)
fig_1, axes = plt.subplots(3, 1, figsize=(12,12),constrained_layout=True)
axes[0].plot(df['X'],color='red')
axes[0].xaxis.set_major_formatter(dates.DateFormatter("%S.%f"))
axes[0].set_title("X Signal")
axes[0].set_xlabel('Time')
axes[0].set_ylabel('Amplitude')
axes[1].plot(df['Y'],color='green')
axes[1].set_title("Y Signal")
axes[1].set_xlabel('Time')
axes[1].set_ylabel('Amplitude')
axes[2].plot(df['Z'],color='blue')
axes[2].set_title("Z Signal")
axes[2].set_xlabel('Time')
axes[2].set_ylabel('Amplitude')
This is how I am managing so far.


