Raspberry Pi Python Graph continually updating - python

I'm using a raspberry pi currently for a engineering project, and am collecting data using the GPIO pins from various sensors. Id like to display this data on a graph. I've used matplotlib to get a graph to show, but for the program to continue you need to close the graph window. I've researched, but can't seem to find a way to make the graph stay open, and have it continually updated with the program running in the background. Is there a way to do this? Or should I try creating a HTML file with a graph in it and have the program open that?
Thanks for any help!

You can use the Plotly Python API to log and stream data to a graph in your browser from your RasPi. You can fork the code from GitHub to setup an online graph like this. The example here is temperature.
Once you've generated your graph, you can embed it as an iframe with this snippet:
<iframe id="igraph" src="https://plot.ly/~abhishek.mitra.963/1/400/250/"
width="400" height="250" seamless="seamless" scrolling="no"></iframe>
You'll want to swap in your URL in the snippet. You can edit the width and height in the URL string and fields to change how it looks. Here's how it looks:
(Full disclosure: I'm on team Plotly).

You could show the Graph in another Thread by using the module thread or the module threading (which is an object oriented and more powerful alternative). For more infos on these module have a look the python documentation for thread or threading.

Related

Embedding RViz2 within a custom PyQt5 GUI

I am trying to make a GUI application to control my robot. The purpose of the GUI is to be able to call appropriate services/publish some data when the button is pressed. I have been able to do these by connecting the callbacks of the button elements to the ROS2 service callbacks/publisher callbacks. I am currently using RViz to visualise my robot and the environment. I would like to embed the RViz GUI within my PyQt5 GUI, so that I can see the robot and interact(rotate, zoom, etc.) with the robot, but inside my GUI.
I attach an example of what it should look like in the image below:
I know that I can publish the camera feed as images using TextLabels, but this would defeat my purpose of being able to interact with the environment within RViz. Does anybody know how to do that, or have a minimal example of how I can embed RViz inside my PyQt5 app? I am completely new to GUI development, which is why I am facing some issues with understanding what sort of QWidget I would need to use.
Thanks in advance for your help!
At the moment rviz2 doesn't seem to have Python bindings. It's been requested as a feature though. Check the following issue for updates on its implementation:
https://github.com/ros2/rviz/issues/640
Rviz for ROS 1 does have Python bindings. See the following tutorial for how to integrate rviz visualization frames into your pyqt5 application:
http://docs.ros.org/en/melodic/api/rviz_python_tutorial/html/index.html
You could possibly use the ros1_bridge to interface an rviz1 application to ROS 2:
https://github.com/ros2/ros1_bridge

Is there any way to embed MongoDB charts in my kivy program using PyMongo?

I have been working on a tracker. It takes the date of each entry and the time elapsed on said date and feeds it to a MongoDB database. I made a line graph using the data in MongoDB Charts but I can't seem to find any documentation on how to embed it in Python.
Is there a way to do it?
(I'm not including code since there is nothing to reproduce. I just want to know if there is any function available to achieve this)
My output screen looks like this right now:
I want to add the chart in the blank space below but can't find a way to embed it. I tried AsyncImage but that doesn't work (understandably so, since AsyncImage has no provisions for chartId).
This video will teach you how to use mongodb with python using PyMongo
https://pypi.org/project/kivy-garden.graph/
and i think you can get the data as text not as graph and visualize the data in kivy using graph visualization in kivy garden using this module:
https://pypi.org/project/kivy-garden.graph/
you can try other way to use mongodb like installing the graph from the DB as an img and then use the image in kivy

Camera trace recording in Paraview

I use Paraview 5.8.1 but my question holds for older versions.
I want to generate a Python script to automate my visualizations. I use the "trace recorder" tool which records the actions I do in the GUI and translate them into
the Python script that would lead to the same result.
However this tool does not record everything : for instance camera position or orientation axes size modications are not translated whereas the Python functions to hold this do exist.
Is there any way to get the trace recorder to record everything ?
Simple answer: nope.
ParaView use a property mechanism. Lot of things are properties (filter parameters, color setting, ...) and are available for record. But camera are not. When the trace stops, an internal hook adds the last camera in the trace.
You can use this as a Macro to add the current Camera in the trace:
from paraview import simple
from paraview import smtrace
smtrace.Trace.get_accessor(simple.GetActiveView())
camera_trace = smtrace.SaveCameras.get_trace(None)
if camera_trace:
a = smtrace.Trace.Output.append_separated(
"#### saving camera placements for all active views")
a = smtrace.Trace.Output.append_separated(camera_trace)
That said, I'm not sure to see a use case ... If you want to see an animation of your scene, you cannot use the Trace mechanism but you should use the Animation View instead.

A dynamically updating graph for PyQt GUI

I have developed a Qt GUI using Qt4 and PyQt. I am trying to implement a graph that will dynamically "live update" the graph to represent the rate at which the data is being transmitted in a (data/sec format). However, the problem lies within implementing a graph that can cleanly live update, not finding the speed. For the record, I want this to be built in as a widget within the GUI not a separate pop-up window.
I suggest you to use two threads: One for acquiring data from somewhere, the other for representing it's graphics. You can take a look on A “live” data monitor with Python, PyQt and PySerial or to pyQt Matplotlib widget live data updates.
I've used qCustomPlot (website here) with pretty good success. I can live-update several thousand data points and it's all very straightforward to use.

Dynamic Chart in Python

I am essentially trying to replicate the google finance chart, but for sensor data. I would like to embed the chart in a GUI and have it update on a timer (which samples the sensor for it's value). I would like to incorporate panning, resizing, and adding moving averages, much like the google finance charts, all of which is updated at some steady interval.
Much of my code base is already in python, so I would like to stick with it. Can this be done with Python?
I have checked out matplotlib, but I am not sure if it can do dynamic charts. I am using wxPython to create the GUI.
I recently came across Chaco from Enthought.
http://code.enthought.com/projects/chaco/
It is an open source framework written in Python that binds with wx, Qt etc and more usable than matplotlib for building full applications. Very usable and easily customizable. You can use the packaged panning, zooming tools or build your own.
I would suggest downloading the epd-free package to ensure you get all dependencies if you choose to move ahead with it.
http://www.enthought.com/products/epd_free.php/
I just implement a method to draw dynamic charts in ipython notebook, you can check my blog post here : http://litaotao.github.io/dynamic-charts-matplotlib-alternative-ipython-notebook-python-drawing-js
and bellow is a screenshot:

Categories