I am trying to update the matplotlib graph as follows:
import matplotlib.pyplot as plt import matplotlib.dates as mdate import numpy as np plt.ion() fig = plt.figure() ax = fig.add_subplot(111) for i,(_,_,idx) in enumerate(local_minima): dat = dst_data[idx-24:idx+25] dates,values = zip(*dat) if i == 0: assert(len(dates) == len(values)) lines2d, = ax.plot_date(mdate.date2num(dates), np.array(values), linestyle='-') else: assert(len(dates) == len(values)) lines2d.set_ydata(np.array(values)) lines2d.set_xdata(mdate.date2num(dates))
For the first time through a cycle, the graph is displayed just fine. The second time through the cycle, all the data on my graph disappears - everything works fine if I do not include the lines2d.set_xdata line (except, of course, the x-data points). I looked at the following posts:
How to update the plot in matplotlib?
and
Update rows in matplotlib
However, in both cases, the user only updates ydata , and I would also like to update xdata .
source share