I am trying to plot a large dataset using a CSV file I had gathered previously. When I plot the data using plt.step
every xtick is marked making it unreadable. How do I reduce the number of displayed xticks but keep the same graph?
I have tried using plt.xticks
with np.arrange
but I keep getting errors as I am using a Dataframe rather than an array. Additionally the x values I'm working with is time in the following format (%H:%M:%S).
import pandas as pd
import numpy as np
import datetime
import matplotlib
matplotlib.use("TkAgg")
from matplotlib import pyplot as plt
df = pd.read_csv(thisFile)
plt.figure(figsize=(16,6))
plt.step(df.Time, df.HR)
print(df.Time)
Output
0 13:40:34
1 13:40:44
2 14:18:29
3 14:19:15
4 14:20:58
5 14:21:17
plt.ylabel('Heart Rate (BPM)')
plt.xlabel('Time')
plt.show()
Displaying the plot is mostly correct except for the xtick frequency. It appears too often and collides with each other as shown in my graph output.
Ideally I would like for the xticks to display from 12AM to 12PM with a xtick frequency of an hour.