I used pyqtgraph to create real-time bar displays which show positive and negative accelerometer data real-time:
I'm displaying x,y,z accelerometer data from a 3 axis accelerometer. he bottom bar shows the overall amplitude, which is √(x2+y2+z2). The circuit I am using to collect the sensor data is shown below - an MPU6050 3-axis accelerometer/gyrsocope board connected to a pyboard v1.0 using the I2C interface.
Now pyqtgraph does have a bar chart class, BarGraphItem. I would like to link to the documentation for this class, but there is not any pyqtgraph documentation here at the time of writing! There is an example program bundled with the pyqtgraph library though, which is how I learned about the class. Search on 'pyqtgraph bargraphitem' and you will find the listing. However I could not see how to animate it. I tried. I failed. So I did it a different way. I used the pyside QProgressBar class to create my own display widget, which I named Gui_Pbar and call pbars. Please find the listing for Gui_Pbar below.
As the acceleration data can be negative as well as positive, each pbar has two QProgressBar widgets, which are created in lines 8 and 9, one each for the negative and positive values. I create a LayoutWidget in line 7 to hold the two progress bar widgets and in lines 19 and 20 these progress bar widgets are added to the LayoutWidget side by side. The bar for negative values is set to fill from the right to get the correct visual appearance, this is set in line 10. There is a little gap in between the negative and positive bars, which I would like to get rid of. I played around for a while to try and figure out how to do this, then put it on my 'to do one day maybe' list as the result I have is 'good enough'. Make it work, make it right, make it fast. It works, it is fast enough - maybe getting rid of the gap constitutes the 'make it right' bit?
The change_color method which starts in line 22 is used to set the colour of the pbar. The pbar value is set in update_bar which starts in line 36. This method tests if the value is positive or negative in line 39, then sets the positive or negative progress bar accordingly. return_pbar returns the layout widget containing the pbar.
change_text allows text to be superimposed on to the displays. In my application, I set this to show the value of acceleration being displayed by the pbar.
The following code snippet shows how I use the Gui_Pbar class to add pbars to my real-time accelerometer display.
Lines 1-4 instigate the pbars. Line 6 sets up a LayoutWidget to hold them and each pbar is added to this holder in lines 7-9. Line 11 shows the layout_bars layout being added to the dock in the user interface. Holders within holders within holders! This is how user interfaces can be built up in a modular fashion.
So I created a bar display which shows real-time accelerometer data, positive and negative values with out too much coding trauma.