I need some help on how to plot realtime data (plt.draw()) with time on the x axis (hours minutes seconds) I have searched for two weeks and I just have been fighting bewildering errors. I finally have a partially working program but setting the xlims seems impossible. I also do not understand why the plot wont center on my data. Any advice on obtaining my goal and or solving my set_xlim error. I have tried every solution on this site and none of them have helped.
import matplotlib.pyplot as plt
import matplotlib.dates as md
import numpy as np
import datetime
import time
datenums=np.array((10), dtype = float)
n=1
duration=10
plt.ion()
plt.show()
for n in range(1,5):
now=time.mktime(time.localtime())
timestamps=np.linspace(now,now+duration,n)
dates=[datetime.datetime.fromtimestamp(ts) for ts in timestamps]
datenums=md.date2num(dates)
plt.subplots_adjust(bottom=0.2)
plt.xticks(rotation = 45)
x=datenums[n-1]
ax=plt.gca()
ax.xaxis_date()
xfmt = md.DateFormatter('%y-%m-%d %H:%M:%S')
ax.xaxis.set_major_formatter(xfmt)
print n,x
time.sleep(1)
ax.plot_date(x,n,markerfacecolor='CornflowerBlue')
#ax.scatter(x,n)
#ax.set_xlim(['2015-05-03 10:36:00', '2015-05-05 10:36:00'])
plt.draw()
plt.show()