0

I'm trying to plot x axis with every 60 minutes during ,and y axis with a list.

I've tried code:

import pandas as pd
import matplotlib.pyplot as plt

date_time = ['08:30', '09:30', '10:30', '11:30', '12:30', '13:30', '14:30']

date_time = pd.to_datetime(date_time)
temp = [2, 4, 6, 4, 6,9,8]

DF = pd.DataFrame()
DF['temp'] = temp
DF = DF.set_index(date_time)

fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.3)
plt.xticks(rotation=90)
plt.plot(DF)

But the out put is x axis is like this one:plot x-axis as date in matplotlib ,the x axis is not minutes but date,

my expected values on the X-axis are like :

'08:30' '09:30' '10:30' '11:30''12:30' '13:30' '14:30'

or

'08:30' '08:40' '08:50' '08:60' .... '15:00'

So how can I convert the date into the minutes data that I need,and also how can I convert the line into curve?

Any friends can hlep?

2
  • All minutes in your example equal 30. Please include expected values on the X-axis. Also, the line shown is a curve. Please explain why you are not happy with it. Commented Jun 20, 2020 at 6:12
  • Thank you so much for your reply,I have updated my question. Commented Jun 20, 2020 at 6:16

1 Answer 1

2

Update the axis formatter:

matplotlib.dates as mdates 
ax.xaxis.set_major_formatter(mdates.DateFormatter("%H:%M"))
plt.plot(DF)
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you so much for your reply,but it still not works,could you show me the whole code?Best regards!
Simply add these lines before the last line.

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.