0

I have a csv with two columns, one with week day names and one with time of login of the employee. How do I plot this using matplotlib or pyplot ? not able to get how to plot the time in Y coordinate. the time data is like "23/02/2017 at 11:30 PM".

Do I need to make changes to the data or Can I plot it as is?

1 Answer 1

1

Format the time using datetime, and then plot the formatted date directly using pyplot. An example code.

from datetime import datetime
import matplotlib.pyplot as plt
import matplotlib.dates as mdates

sampleTime = "23/02/2017 at 11:30 PM"
timeFormatted = datetime.strptime(sampleTime, "%d/%m/%Y at %I:%M %p")
print(timeFormatted)

plt.scatter(timeFormatted, 0)

# reshape X labels
plt.gcf().autofmt_xdate()
showFormat = mdates.DateFormatter('%Y-%m-%d %H:%M')
plt.gca().xaxis.set_major_formatter(showFormat)

plt.show()
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.