GLScatterPlotItem color alpha

582 views
Skip to first unread message

Jeffery McGehee

unread,
May 8, 2014, 1:55:13 PM5/8/14
to pyqt...@googlegroups.com
I am just beginning to experiment with pyqtgraph after seeing that matplotlib's 3d plots are unbearable for my newest task...

I am plotting >5000 datapoints using GLScatterPlotItem.  I have it plotting my data, and the performance is great, but I cannot seem to change the alpha value of the points.

I am passing in an Nx4(RGBA) numpy array for the color kwarg, and the color of my points are what I want, but the alpha is not. I want my alpha to be 1.0, but no matter what I change it to, it doesn't seem to have any effect.

The color array I'm passing looks like:


[[ 0.14117647  0.14117647  0.14117647  1.        ]

 [ 0.14901961  0.1372549   0.14117647  1.        ]

 [ 0.13333333  0.14117647  0.13333333  1.        ]

 ..., 

 [ 0.94509804  0.89019608  0.28235294  1.        ]

 [ 0.87843137  0.90980392  0.29411765  1.        ]

 [ 0.87843137  0.91372549  0.2         1.        ]]


A screen shot of my results is attached.



Screen Shot 2014-05-08 at 1.52.49 PM.png

Luke Campagnola

unread,
May 8, 2014, 3:38:07 PM5/8/14
to pyqt...@googlegroups.com
On Thu, May 8, 2014 at 1:55 PM, Jeffery McGehee <jlmcg...@gmail.com> wrote:
I am just beginning to experiment with pyqtgraph after seeing that matplotlib's 3d plots are unbearable for my newest task...

I am plotting >5000 datapoints using GLScatterPlotItem.  I have it plotting my data, and the performance is great, but I cannot seem to change the alpha value of the points.

I am passing in an Nx4(RGBA) numpy array for the color kwarg, and the color of my points are what I want, but the alpha is not. I want my alpha to be 1.0, but no matter what I change it to, it doesn't seem to have any effect.

Hi Jeffery,

The default GL mode for GLScatterPlotItem is 'additive', which will make points appear transparent even with full opacity. You can change this by adding `scatterItem.setGLOptions('translucent')`.

The main reason for this default is that it makes the visual result order-independent (it does not matter in what order the points are drawn). Otherwise, it is usually necessary to sort the points from back to front in order to get good results. If you're curious, a quick search will turn up many articles that describe the difficulty of rendering transparent objects in OpenGL.


Luke




 

Jeffery McGehee

unread,
May 8, 2014, 4:03:29 PM5/8/14
to pyqt...@googlegroups.com
Thanks for the quick response!

The result I was after is actually what is produced when I add 'scatterItem.setGLOptions('opaque')'.  However, this turned my points into squares rather than circles... This is acceptable, but I liked the circles better.  Is there a quick fix for this?

Thanks again,

Jeff


--
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyqtgraph/2M2hwIW-vgM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pyqtgraph/CACZXET--wg_PAnEak%2BtJKALLbnvdcK2OxLG5rjDseBkt1q-OKg%40mail.gmail.com.

For more options, visit https://groups.google.com/d/optout.

Luke Campagnola

unread,
May 8, 2014, 4:17:57 PM5/8/14
to pyqt...@googlegroups.com
On Thu, May 8, 2014 at 4:03 PM, Jeffery McGehee <jlmcg...@gmail.com> wrote:
Thanks for the quick response!

The result I was after is actually what is produced when I add 'scatterItem.setGLOptions('opaque')'.  However, this turned my points into squares rather than circles... This is acceptable, but I liked the circles better.  Is there a quick fix for this?

Did you try 'translucent' mode? (and if so, what was the problem with it?)
Using 'opaque' mode forces the full rectangular sprite area to be fully opaque for every point, hence they appear as squares.


 

Jeffery McGehee

unread,
May 8, 2014, 4:35:36 PM5/8/14
to pyqt...@googlegroups.com
The datapoints are still translucent in 'translucent' mode.  Even with the alpha column of the RGBA matrix set to 1.0 . See attachment.  If I try low alpha values, it does make the points obviously more transparent.  So it's working to some extent.  If I try values larger than one, it looks the same as the image I have attached, but it does not throw an exception.

Inline image 1


--
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyqtgraph/2M2hwIW-vgM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.

Luke Campagnola

unread,
May 8, 2014, 10:39:13 PM5/8/14
to pyqt...@googlegroups.com
On Thu, May 8, 2014 at 4:35 PM, Jeffery McGehee <jlmcg...@gmail.com> wrote:
The datapoints are still translucent in 'translucent' mode.  Even with the alpha column of the RGBA matrix set to 1.0 . See attachment.  If I try low alpha values, it does make the points obviously more transparent.  So it's working to some extent.  If I 
try values larger than one, it looks the same as the image I have attached, but it does not throw an exception.

Right you are! In opengl/items/GLScatterPlotItem.py ~line 62, I see: 

                return 200 * (w/2. - np.clip(r, w/2.-1.0, w/2.))

That constant should have been 255, not 200. I have pushed a fix to the develop branch. 
Thanks for the report!

Jeffery McGehee

unread,
May 13, 2014, 9:17:31 AM5/13/14
to pyqt...@googlegroups.com
Sorry for the delayed response, I got busy on another project...  Your fix is giving me the results I wanted! I really appreciate the dedicated support! 

I simply changed the code in my currently installed package rather than pull down your branch and reinstall. Thanks a ton!

Jeff


--
You received this message because you are subscribed to a topic in the Google Groups "pyqtgraph" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pyqtgraph/2M2hwIW-vgM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pyqtgraph+...@googlegroups.com.

Jeffery McGehee

unread,
May 13, 2014, 9:34:09 AM5/13/14
to pyqt...@googlegroups.com
Actually.... Another funny bug...

When the points are fully opaque, the corners of the sprite are opaque as well (I'm assuming you colored them with the background color).  This would be fine if points didn't overlap from a given view angle, but it looks a little funny when they do.  Is there a way to make the corners transparent, and the circles opaque?  I looked through GLScatterPlotItem.py and didn't see an obvious fix to me, but I have no openGL experience.

Let me know what you think about this.. Screenshot is attached.

Screen Shot 2014-05-13 at 9.32.09 AM.png
Message has been deleted

Jamin Hu

unread,
Apr 1, 2022, 10:11:48 AM4/1/22
to pyqtgraph
Hi Luke and JLM,

I have the same issue! But apparently only on a few of the circles I'm plotting.

I set scatterItem.setGLOptions('translucent') with alphas set to the max, 255, and am getting the corners of a square around my circles. Is there some reason for this behavior?

BR,

Jamin Hu
Capture.PNG
Reply all
Reply to author
Forward
0 new messages