2

I have the following dataset:

pressuredfjan1[['Unit','Time1']].head()
Out[53]: 
       Unit               Time1
0  321.3599 1970-01-01 00:00:40
1  321.3599 1970-01-01 00:04:40
2  321.6651 1970-01-01 00:06:40
3  320.7496 1970-01-01 00:10:40
4  322.2755 1970-01-01 00:14:40

I am trying to plot Unit against Time1 in an HH:MM:SS format. I've tried the following code:

dates = dates.date2num(list(pressuredfjan1['Time1']))
fig = plt.figure(figsize=(20,10))
ax1 = fig.add_subplot(111)
ax1.plot(dates,pressuredfjan1['Unit'])
plt.show()

This gives me the plot, but I am not getting HH:MM:SS format in the x-axis. Instead, I'm getting 3.1, 3.2, 3.4...Le14 etc. Can somebody help me out here please? Thanks.

1 Answer 1

1

You can use:

import matplotlib as mpl

pressuredfjan1['dates'] = pd.to_datetime(pressuredfjan1['Time1']).dt.strftime('%H:%M:%S')
fig = plt.figure(figsize=(20,10))
ax1 = fig.add_subplot(111)
majorFormatter = mpl.dates.DateFormatter('%H:%M:%S')
ax1.xaxis.set_major_formatter(majorFormatter)
plt.plot_date(pressuredfjan1['dates'], pressuredfjan1['Unit'])
plt.show()

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.