Skip to content Skip to sidebar Skip to footer

How To Plot Time Series In Python

I have been trying to plot a time series graph from a CSV file. I have managed to read the file and converted the data from string to date using strptime and stored in a list. When

Solution 1:

Convert your x-axis data from text to datetime.datetime, use datetime.strptime:

>>>from datetime import datetime>>>datetime.strptime("2012-may-31 19:00", "%Y-%b-%d %H:%M")
 datetime.datetime(2012, 5, 31, 19, 0)

This is an example of how to plot data once you have an array of datetimes:

import matplotlib.pyplot as plt
import datetime
import numpy as np

x = np.array([datetime.datetime(2013, 9, 28, i, 0) for i inrange(24)])
y = np.random.randint(100, size=x.shape)

plt.plot(x,y)
plt.show()

enter image description here

Post a Comment for "How To Plot Time Series In Python"