How to format in Matplotlib the x axis ticks to the only hours and minutes and define regular intervals?

Viewed 140

enter image description hereI would like to have in the x axis the following ticks numbers and intervals: [6:00; 8:00; 10:00: 12:00; 14:00, 16:00, 18:00]. The point at '12:00' should also be in the center of the figure, now it is shifted to the right

I tried to convert the column 'time' to a datetime format, but I get an error:

  TypeError: <class 'datetime.time'> is not convertible to datetime

My code looks like this:

import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

df3 = pd.read_excel(r'results.xlsx')

# failed attempt

df3["time"] = pd.to_datetime(df3["time"]).dt.date

# plotting
color = 'black'
ax1 = sns.lineplot(x = 'time', y = 'parabolic', data = df3, color = color, 
label='Light intensity')

ax2 = ax1.twinx()  

ax2 = sns.scatterplot(x = 'time', y = 'Gas-exchange_p', hue= 'Sampling', 
 marker='v', s=200, data = df3, label= 'Measurement time points')


plt.legend()
plt.show()

My dataframe in excel looks like this:

time           y
12:00:00 AM    0
12:01:00 AM    0
12:02:00 AM    0
...
2:00:40 PM    416
...
0 Answers
Related