Is there a way in which I can update the chart by simply adding more points [s] to it ...
There are several ways to animate data in matplotlib, depending on the version you have. Have you seen examples of matplotlib cookbook ? Also, check out more modern animation examples in the matplotlib documentation. Finally, the animation API defines a FuncAnimation function that animates the function over time. This function may just be the function you use to retrieve your data.
Each method basically sets the data property of the object that is being drawn, so it does not require cleaning the screen or drawing. The data property can simply be expanded so that you can save the previous points and simply add to your line (either the image or what you draw).
Given that you say that the arrival time of your data is unknown, your best bet is probably just to do something like:
import matplotlib.pyplot as plt import numpy hl, = plt.plot([], []) def update_line(hl, new_data): hl.set_xdata(numpy.append(hl.get_xdata(), new_data)) hl.set_ydata(numpy.append(hl.get_ydata(), new_data)) plt.draw()
Then, when you receive data from the serial port, just call update_line .
Chris Jun 08 2018-12-12T00: 00Z
source share