1

I am trying to change my x axis time data format. Currently the x-axis shows 'month-day hour' and I just want it to report the hours, preferable not in military time.

Here is the graph for reference:

https://i.stack.imgur.com/7xOwT.jpg

and the code for the graph:

import datetime
import matplotlib.dates as md
plt.style.use('default')
from scipy.ndimage.filters import gaussian_filter1d  

fig = plt.figure(figsize=(15, 4))  
x = df1['Time']
y = df1['BG']
plt.xlabel('Time (hours/minutes)', fontsize = 'large')
plt.ylabel('Blood Glucose (mg/dL)', fontsize = 'large')
plt.title('Personal Metabolic Map - Day 1', fontsize = 'large')


ysmoothed = gaussian_filter1d(y, sigma=2)
plt.plot(x, ysmoothed, linewidth = 2.0)


axes = plt.gca() 
axes.set_ylim([70,200]) 

plt.grid(color = 'k', linestyle = '--', linewidth = 1.0) 
plt.grid(b=True, which = 'minor', color = 'k', linestyle = ':') 
axes.xaxis.set_minor_locator(md.MinuteLocator(interval=15)) 
fig.autofmt_xdate() 

I have tried adding major locator to 60 minutes:

axes.xaxis.set_major_locator(md.MinuteLocator(interval=60))

But this is the result I get....

https://i.stack.imgur.com/n3zYm.jpg

It's worth mentioning that the time data I am pulling from my dataframe ('Time') is in datetime64[ns].

Any help would be greatly appreciated as I am not really a programmer and have just started to try and learn python for data processing and visualization purposes.

Thank you!

I expected the x-axis to be 'HH', but the actual output is 'Year'.

0 Answers0