Hello everyone!
I am currently writing a program using pyqtgraph that displays strain gauge
readings sent over serial from an Arduino. My goal is to visualize the flex
in the fuselage of a carbon fibre rocket our university team is building.
Modifying some of the 3d graph example code listed here
<https://pyqtgraph.readthedocs.io/en/latest/3dgraphics.html>, I was able to
plot a line. Next I wanted to test that I could update the line live and at
an acceptable frame rate. So I created a 3d numpy array, passed it to a
GLLinePlotItem via setData() and iteratively updated the numpy array while
calling setData() each time. Unfortunately the graph does not seem to
update. I've done quite a bit of digging in the documentation, and from
what I've read, setData() should automatically update the line on the
graph.
My code is below. Let me know if you have any ideas, or can point me to
documentation that will help learn how to do this properly. Also it needs
to be run with "python3 -i <filename.py>" right now. Thanks!
--
You received this message because you are subscribed to the Google Groups
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/pyqtgraph/c8f4963f-b29c-4276-9bda-69ba930575fen%40googlegroups.com.
## build a QApplication before building other widgets
import pyqtgraph as pg
pg.mkQApp()
## make a widget for displaying 3D objects
import pyqtgraph.opengl as gl
view = gl.GLViewWidget()
view.show()
import numpy as np
import time
from pyqtgraph.Qt import QtGui, QtCore
## create three grids, add each to the view
xgrid = gl.GLGridItem()
ygrid = gl.GLGridItem()
zgrid = gl.GLGridItem()
view.addItem(xgrid)
view.addItem(ygrid)
view.addItem(zgrid)
## rotate x and y grids to face the correct direction
xgrid.rotate(90, 0, 1, 0)
ygrid.rotate(90, 1, 0, 0)
## scale each grid differently
xgrid.scale(1, 1, 0.1)
ygrid.scale(1, 1, 0.1)
zgrid.scale(1, 1, 0.1)
## Create a 1D array of numbers from 0-63
array = np.arange(64)
## Convert those to a 4x4x4 array
array3d = array.reshape((4,4,4))
## Create a new line object using our 3D array
myline = gl.GLLinePlotItem(pos=array3d, width=10)
## Add the line object to the GLViewWidget
view.addItem(myline)
## Update the line using setData
def update():
global array3d
array3d = np.multiply(array3d, 1.01)
print(array3d)
myline.setData(pos=array3d)
timer = pg.QtCore.QTimer()
timer.timeout.connect(update)
timer.start(500)