I have a DataFrame named airtep_df with columns 'AIRTEP'
(Int64), 'AIRTEP_qc'
(Int64), and 'UTCTime'
. I'm trying to create a plot from this data, but the time tick labels on the x-axis are overlapping, making the plot unreadable. I attempted to rotate the tick labels using plt.xticks(rotation=45)
, but the plot disappeared. Can someone explain what went wrong and provide a solution for formatting the time tick labels with datetime
correctly?
This picture shows the details about the data frame I'm using:
This is the script I used:
import matplotlib.pyplot as plt
import pandas as pd
index = (airtep_df['AIRTEP'] != 9999) & (airtep_df['AIRTEP_qc'] == 1)
selected_y = airtep_df.loc[index,'AIRTEP']
y = selected_y.values
selected_x = time_df.loc[index,'UTCTime']
x = selected_x.values
plt.plot(x[30],y[30])
#This is the result I have, the the x-axis are overlapping:
#Then I trid to rotate the xticks
plt.xticks(rotation=45)
This is the result I have, as the picture:
How can I plot datetime
data and format it such that the labels are not overlapping?
plt.setp
as suggested in this answer?