Python: Creating a real-time 3D plot

Real-time 3D plot in python

Python: Creating a real-time 3D plot

updated: 31-01-2019

To create a real-time 3D plot from any source, where data is coming one point at a time and may have not consistent time in data retrieval.

Python along with matplotlib allows the creation of 3D plots, which is easy to create in case if data is all available at a time of plotting.

But in case of data is coming in chunks and you want to see a real-time plot of data then here is a sample code for python.

 

Real-time 3D plot in python Real-time 3D plot in python

hl, = map_ax.plot3D([0], [0], [0]) contains initial points x=0, y=0, and z=0. You may change initial points if you want.

When you receive new data, just call:

This will plot new data on the graph.

plt.show(block=False)  block=False, will not block the code, it will keep the code running so that it can receive new data.

But at the end of the code, you will need to call  plt.show(block=True)  which will block the code, so that you could analyse or save your data.

Here, we have used  plt.pause(1)  to create a manual delay of 1 second, which is not needed in case of real-time data processing.

Instead of (2,2,1) in  update_line(hl, (2,2, 1)) , you need to replace with your new data.

You don’t need to keep previous data in the record for plotting, just add new data point and it will add that new point with all previous data points and update your graph.

 

Related Links:

Leave a Reply