Dynamic Chart in Python - 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:

Related

Use Matplotlib on django site

I am thinking of starting a new django project for plotting stock prices and displaying them onto the site. I know matplotlib pretty well and was wondering if I could plot the chart and somehow push it to the site with the usual matplotlib features like zoom etc.
I have seen this done where that images are pushed but I am wondering if I could push the chart with its functionality provided by matplotlib and I can't seem to find an answer anywhere so maybe it isn't possible?
I've never used it personally, but mpld3 appears to do what you are asking.

Pyqt5/Pyside application with Ipywidgets and Interactive figures

I’m building a GUI (pyqt or pyside) to easily create complex figures (e.g. with plotly) for users.
So far so good, I run the data processing and produce plotly figures that are exported as html and read by QwebEngineView. I even created a qt widget for layout editing by the user (see image below).
The problem with this is the long delay (few seconds) in the process of:
updating the layout -> exporting to a temp html file → open and rendering the file on GUI.
I want to make a better GUI experience with layout editing.
Following this great Jon Mease talk I discovered my plotly figures could be updated in real time using the also great ipywidgets, but only on Jupyter notebooks / lab environment. That is, exporting the widgets+figure to a html file renders all elements, but since the python backend will be lacking for the widgets (in the standalone html file), they won’t interact with the figure’s layout.
However, my application IS running on a python process, so I have the feeling this should be a solvable problem somehow...
Qtconsole won’t render ipywidgets, so I can’t use it to expose my figures in the GUI.
Voila renders Jupyter notebooks with interactive widgets, I’m not sure however if I could access it and incorporate it to the GUI. It says it can work both as a “standalone tornado application” or as a “server extension to notebook or jupyter_server”.
I’m aware there’s probably not a final solution to that, but I would appreciate any suggestions on how to approach this problem! Thanks!
I ended up creating a solution for the problem: QtVoila
It is basically an extended QWebEngineView that manages and renders a Voila process, with some extra functionalities.
Here's a blog post explaining it:
https://www.taufferconsulting.com/portfolio/qtvoila

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.

Raspberry Pi Python Graph continually updating

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.

Picking a suitable GUI framework for project

I have a project where I have to show some sort of changing bar graph with results from a function. This bar graph should be in colour and 3d. I want it to look good since it's an open source educational program where it teaches the user about different voting systems and how they effect the outcome of an election. I would like to use python but I have no idea about using GUI frameworks since all my work in python has been command line based. Your help will be appreciated.
For 3D graphics, you might want to use OpenGL with a game framework, such as PyGame or Pyglet. Use matplotlib as TJD suggested in the other answer.
As for GUI frameworks, they generally won't help much with 3D graphics:
PyQt is one choice; I see you already have it in the question tags. PySide is very similar to PyQt, but with a nicer licence.
Then there's tkinter (in the standard library), wxPython, and pyGTK – I hear all of them are good, though I don't know them personally.
Pick one and stay with it. It'll take some time to learn if you're not experienced, so don't expect results too soon.
You might want to look at matplotlib, which is probably the most widely used library for doing graphs, including 3-D.

Categories