Real time plotting osciloscope/captured data - python

My hardware for capturing waves creates an 2D array with 500 traces of length 5000 (points). I would like to see how the data/traces look like during the computation of this array, since I move my device around and capture different waves from different edges. Im using jupyter+python for the capturing work and tried matplotlib to plot the data, although the plotting can be only (or I can only) done after the traces are gathered, but I would need to see the traces changing in real time. I read about the holoviews library, although the same problem occurs.
How can I plot real time data, when I get 1 trace per computation?
For example: I capture 1 trace of 5000 points (x-axis length) and would like to plot that one trace, then another trace is captured and it would have to adjust to the old plot. This should work like an audio recording plotting, where you record voice and whenever you speak you can instantly see the waves as they move

Related

updating plots with large points number in a cycle to visualize progress using matplotlib and python

I am using Python for processing large datasets.
Each part of the data in the dataset is processed step by step in a cycle.
I need to add some visualization during processing.
Now I do plotting using matplotlib for current portion of data. For each step of the cycle I am executing function plot which plots new figure for each step..
The problem is I have a lot of data and plots... E.g. 1000000 plots, and if I will output it in Jupyter it just crashes. I want to use one figure and update data on it through a cycle and show it to see processing?
I want to create a ONE plot but the data on that figure will be changed on each step of processing - for current portion of data.
How to do that - to see that image during processing (e.g. using jupyter notebook)?
(So running through a cycle in one cell will show only one figure with one plot but the scatter on that plot will change cycle by cycle updating the existing figure)
something like:
update_plot(plot_name: str, datax: np.array, datay: np.array)
that will CHANGE the existing plot (important - I need to see it on the screen on each step - to understand that there is progress and it works correctly) It's like animation where each step - is a frame that needs to be changed. E.g. I am adding a special point on a plot for each step.

How to animate a matrix changing with time?

I am solving the Cahn hilliard equation, and it's already working. If i plot the figures at different iterations I obtain the correct result at the end. However, I need to show the change in concentration over the course of time in a video and not in multiple plots. I have tried using FuncAnimation but I can't figure out how to do it. I can't create a function that includes the frames. My concentration matrix is already updating after each iteration so how can I just tell the code to plot every update on the video?

Accelerating matplotlib figure update

I am using Python 2.7.9 with matplotlib to display live data taken from a microcontroller in a FigureCanvasTKAgg. The figure itself must always display the last 100 points and resize the Y axis to display and 'snug fit' all points. X axis is updated as well to show the correct time stamp of each point.
This figure update involves redrawing all artists (as all of them change) at every figure update which is called using an after method every 100ms. I am using line.set_data(x,y) to update the actual data points and the required methods for updating the Y and X axes limits, followed by canvas.draw(). This works OK, at almost 5fps(the drawing itself takes ~100ms).
My question is: is there a faster way of doing this? From what I understand the draw method redraws the whole canvas including the subplots. Is there a way to update only the lines displayed and the splines and hence increase the fps?
I tried implementing a solution using ax.draw_artist(lines) and the rest, however this adds new artists and do not delete the previous ones.

matplotlib, draw multiple graphs / points in figure

I am trying to develop a telemetry system which sends sensor data from an Arduino, plotted in realtime. For this I'm using Python and the matplotlib-library. My problem is that every time a new data point arrives, I want to add that data point by plotting it into the same figure as the other data points. So far I could not find a solution to this.
You can stream data from an Arduino into a Plotly graph with the Arduino API in Plotly. You have two options: continuously transmit data (which it sounds like you'll want to do), or transmit a single chunk.
It will update the graph every few seconds if you refresh the page.
The Arduino API is available here. And, if you're already using Python, you can use the extend option to update data into another plot. The Python API is here.
Here's an example of how it looks to transmit from an Arduino, and you can see the interactive version here
Full disclosure: I work at Plotly.
as far as I can see, you have a few different ways of doing this (i'll list them in what I consider increasing difficulty
Making a bitmap file, eg .png, which has to be regenerated each time a new datapoint arrives. To do this you need to have your old data stored somewhere in a file or in a database.
Using svg in a browser. Then you can add on points or lines using javascript (e.g. http://sickel.net/blogg/?p=1506 )
Make a bitmap, store it and edit it to add in new points - this really gets tricky if you either wants to "roll old points off" at one end, or rescale the image when more data arrives.
Make a series of bitmaps, and have the total graph as a combination of a lot of slices. - here you can easily "roll off" old points, but you are out of luck if you want to rescale.

How to visualize IP addresses as they change in python?

I've written a little script that collects my external IP address every time I open a new terminal window and appends it, at well as the current time, to a text file. I'm looking for ideas on a way to visualize when/how often my IP address changes. I bounce between home and campus and could separate them using the script, but it would be nice to visualize them separately.
I frequently use matplotlib. Any ideas?
Plot your IP as a point on the xkcd internet map (or some zoomed in subset of the map, to better show different but closely neighboring IPs).
Plot each point "stacked" proportional to how often you've had that IP, and color the IPs to make more recent points brighter, less recent points proportionally darker.
"When" is one dimensional temporal data, which is well shown by a timeline. At larger timescales, you'd probably lose the details, but most any plot of "when" would have this defect.
For "How often", a standard 2d (bar) plot of time vs frequency, divided into buckets for each day/week/month, would be a standard way to go. A moving average might also be informational.
You could combine the timeline & bar plot, with the timeline visible when you're zoomed in & the frequency display when zoomed out.
How about a bar plot with time on the horizontal axis where the width of each bar is the length of time your computer held a particular IP address and the height of each bar is inversely proportional to the width? That would also give a plot of when vs how often plot.
You could also interpret the data as a pulse density modulated signal, like what you get on a SuperAudio CD. You could graph this or even listen to the data. As there's no obvious time length for an IP change event, the length of a pulse would be a tunable parameter. Along similar lines, you could view the data as a square wave (triangular wave, sawtooth &c), where each IP change event is a level transition. Sounds like a fun Pure Data project.
There's a section in the matplotlib user guide about drawing bars on a chart to represent ranges. I've never done that myself but it seems appropriate for what you're looking for.
Assuming you specified terminal, i'll assume you are on a UNIX variant system. Using the -f switch along with the command line utility tail can allow you to constantly monitor the end of a file. You could also use something like IBM's inotify, which can monitor file changes or dnotify (and place the file in it's own directory) which usually comes standard on most distributions (you can then call tail -n 1 to get the last line). Once the line changes, you can grab the current system time since epoch using Python's time.time() and subtract it from the time of the last change, then plot this difference using matplotlib. I assume you could categorize the times
into ranges to make the graphing easier on yourself. 1 Bar for less than 1 hour change intervals, another for changes between 1 - 5 hours, and so on.
There is a Python implementation of tail -f located here if you don't want to use it directly. Upon a detection of a change in the file, you could perform the above.

Categories