3D Scatter Plot

2,594 views
Skip to first unread message

Aaron Hoover

unread,
Oct 24, 2012, 4:32:15 PM10/24/12
to pyqt...@googlegroups.com
I have heightmap data in an array that I'd like to visualize in 3D as a surface, a wireframe, or even just a 3D scatter plot (with the eventual goal of animating the evolution of that surface). I saw the "Scatter Plot" example under the "3D Graphics" header in the examples, but I can't seem to find any documentation on pyqtgraph.opengl.GLScatterPlotItem. I could follow the example directly, but I have all my data in numpy arrays, and it seems kind of silly (and potentially very slow) to iterate over the array to create a list of dicts containing the points. 

Is there alternative way to call GLScatterPlotItem with x,y,z data for the points?

Thanks,
Aaron

Luke Campagnola

unread,
Oct 24, 2012, 5:25:20 PM10/24/12
to pyqt...@googlegroups.com
On Wed, Oct 24, 2012 at 4:32 PM, Aaron Hoover <amh...@gmail.com> wrote:
I have heightmap data in an array that I'd like to visualize in 3D as a surface, a wireframe, or even just a 3D scatter plot (with the eventual goal of animating the evolution of that surface). I saw the "Scatter Plot" example under the "3D Graphics" header in the examples, but I can't seem to find any documentation on pyqtgraph.opengl.GLScatterPlotItem. I could follow the example directly, but I have all my data in numpy arrays, and it seems kind of silly (and potentially very slow) to iterate over the array to create a list of dicts containing the points. 

You're right--it is silly and slow. For scatter plots, there's no simple solution in pyqtgraph, although I'd love to have the features you're describing eventually..
You can avoid some of the silliness by using a numpy record array instead of list-of-dicts, but this probably will not avoid the slowness.

Another possibility (provided the entire data set fits in memory) is to create a separate mesh item for each 'frame' in your data, then show/hide each item in sequence to animate. This would result in slow initialization, but optimal animation speed since GLMeshItem stores its entire mesh as a pre-compiled GL list (GLScatterPlotItem currently can not do this since it resizes its points based on their distance from the camera). 

Ultimately I'd like to speed up the initialization time--my understanding is that it is possible to directly feed arrays of vertex data to opengl, but I haven't had time to explore this very much. 

If you're interested in modifying pyqtgraph, I'd be happy to discuss the internals of the opengl system in more detail  :)


Luke










Luke Campagnola

unread,
Oct 26, 2012, 12:27:39 AM10/26/12
to pyqt...@googlegroups.com
On Wed, Oct 24, 2012 at 4:32 PM, Aaron Hoover <amh...@gmail.com> wrote:
I have heightmap data in an array that I'd like to visualize in 3D as a surface, a wireframe, or even just a 3D scatter plot (with the eventual goal of animating the evolution of that surface). I saw the "Scatter Plot" example under the "3D Graphics" header in the examples, but I can't seem to find any documentation on pyqtgraph.opengl.GLScatterPlotItem. I could follow the example directly, but I have all my data in numpy arrays, and it seems kind of silly (and potentially very slow) to iterate over the array to create a list of dicts containing the points. 

Is there alternative way to call GLScatterPlotItem with x,y,z data for the points?

 
Have a look at the latest revision (217). GLScatterPlotItem can now comfortably update 100k points in realtime  (with modest hardware acceleration). The API is a bit different (accepts arrays, as you suggest).

I hope to do the same for GLMeshItem soon..

Luke

Aaron Hoover

unread,
Oct 26, 2012, 2:07:42 PM10/26/12
to pyqt...@googlegroups.com
Have a look at the latest revision (217). GLScatterPlotItem can now comfortably update 100k points in realtime  (with modest hardware acceleration). The API is a bit different (accepts arrays, as you suggest).

I hope to do the same for GLMeshItem soon..

Luke


I just grabbed R218 and the 3D scatter plot example looks great! I think this should help quite a bit.

A little more about our application for reference: we are grabbing grayscale frames from a high speed camera (250 FPS) at 832x832 resolution and want to represent the data with a 3D visualization that's close to realtime (but even 30 FPS would be awesome). We will subsample the data since I think there's no point in trying to plot all 700K points. I'll take a crack at using the latest improvements in R218. 

In the future, I would be interested in contributing to this package, though, since realtime data visualization is something I'm very interested and has a lot of uses around my research lab.

Cheers,
Aaron

Luke Campagnola

unread,
Oct 27, 2012, 12:10:18 PM10/27/12
to pyqt...@googlegroups.com
On Fri, Oct 26, 2012 at 2:07 PM, Aaron Hoover <amh...@gmail.com> wrote:
A little more about our application for reference: we are grabbing grayscale frames from a high speed camera (250 FPS) at 832x832 resolution and want to represent the data with a 3D visualization that's close to realtime (but even 30 FPS would be awesome). We will subsample the data since I think there's no point in trying to plot all 700K points. I'll take a crack at using the latest improvements in R218. 

Sounds really cool. You mentioned compliant surface displacement; is this interferometry? Post a video when it's running! 
I suspect you'll be able to get much better performance rendering triangles instead of points.. I'll let you know when that's done.
 
In the future, I would be interested in contributing to this package, though, since realtime data visualization is something I'm very interested and has a lot of uses around my research lab.

That'd be awesome! I'm happy to discuss approaches for adding new features--I know what a pain it can be wading through someone else's code.

Luke


Luke Campagnola

unread,
Nov 23, 2012, 7:30:03 PM11/23/12
to pyqt...@googlegroups.com
On Wed, Oct 24, 2012 at 4:32 PM, Aaron Hoover <amh...@gmail.com> wrote:
I have heightmap data in an array that I'd like to visualize in 3D as a surface, a wireframe, or even just a 3D scatter plot (with the eventual goal of animating the evolution of that surface).

More toys in the latest release--have a look at the GLSurfacePlot example.

Luke



Matthew Krenik

unread,
Mar 24, 2014, 6:10:57 PM3/24/14
to pyqt...@googlegroups.com
Hello, I am new to pyqtgraph. I am trying to take a PySerial input from a microcontroller and plot the (x,y,z) coordinates into a scatter plot with this tool. Unfortunately, I can't find the "3D Graphics" header in the examples folder in the Python27 directory. Can you direct me to some examples for where 3D plotting is used with this tool? It would be great to see code that takes data from a serial input or from a .txt file. 

Best,
Matthew

Luke Campagnola

unread,
Mar 24, 2014, 6:43:30 PM3/24/14
to pyqt...@googlegroups.com
On Mon, Mar 24, 2014 at 6:10 PM, Matthew Krenik <mwkr...@gmail.com> wrote:
Hello, I am new to pyqtgraph. I am trying to take a PySerial input from a microcontroller and plot the (x,y,z) coordinates into a scatter plot with this tool. Unfortunately, I can't find the "3D Graphics" header in the examples folder in the Python27 directory. Can you direct me to some examples for where 3D plotting is used with this tool? It would be great to see code that takes data from a serial input or from a .txt file. 

I think the example you'll want to look at first is at pyqtgraph/examples/GLScatterPlotItem.py. Depending on your OS and how you downloaded / installed the package, that file might be in a variety of places.. easier just to look online: 


 

Peter Rehani

unread,
Sep 24, 2016, 12:15:11 AM9/24/16
to pyqtgraph
Hey Luke, 

Is there a definitive fix for this? Just found this thread and viewed the progression.

Let me know!
Peter
Reply all
Reply to author
Forward
0 new messages