this might be really a simple question for most of you guys using matplotlib. Please help me out. I want to plot two array like [1,2,3,4] and [4,5,6,7] versus time in a same
To use plot date with multiple trends, it's easiest to call it multiple times. For example:
import datetime
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# Generate Data
time = mdates.drange(datetime.datetime(2010, 1, 1),
datetime.datetime(2011, 1, 1),
datetime.timedelta(days=10))
y1 = np.cumsum(np.random.random(time.size) - 0.5)
y2 = np.cumsum(np.random.random(time.size) - 0.5)
# Plot things...
fig = plt.figure()
plt.plot_date(time, y1, 'b-')
plt.plot_date(time, y2, 'g-')
fig.autofmt_xdate()
plt.show()
Alternately you can use a single plot
(rather than plot_date
) call and then call plt.gca().xaxis_date()
, if you'd prefer. plot_date
just calls plot
and then ax.xaxis_date()
.