using the setBrush command for a list

162 views
Skip to first unread message

Bobby Henley

unread,
Oct 16, 2014, 5:41:08 PM10/16/14
to pyqt...@googlegroups.com
I have a scatterplot containing a large amount of points, I would like to be able to change the colors of points on the fly, and change certain ones to different colors.
The documentation for setBrush indicates that it should be able to take a list of values and set the brush colors accordingly. So far this command only works for using a single brush value for all points on a scatterplot. When I try to input a list, say for example

example=pg.ScatterPlotItem()
example.setBrush(['r']*numberofscatterpoints)

will return the following error

  File "E:\Robert\WinPython-64bit-2.7.6.4\python-2.7.6.amd64\lib\site-packages\pyqtgraph\graphicsItems\ScatterPlotItem.py", line 446, in setBrush
    if kargs['mask'] is not None:
KeyError: 'mask'

but if I try to use only one input value, ie

example=pg.ScatterPlotItem()
example.setBrush('r')

I have no issues. Does setBrush not actually take lists? Or am I doing something wrong?

Nicholas Tan Jerome

unread,
Oct 17, 2014, 5:09:26 AM10/17/14
to pyqt...@googlegroups.com
Hi Bobby,

I think you are right that setBrush should also accept list, not only that, one can use mask to determine which to be filled.

A hack to make this work is to pass the "mask" keyword

do it like this 

example.setBrush(['r']*numberofscatterpoints, mask=None) and this should work.

I feel like the keyword is not checked properly. If one can just check the mask keyword before, then we will not need to always pass mask=None to make this work.

pull request: 

-N

Bobby Henley

unread,
Oct 17, 2014, 11:22:41 AM10/17/14
to pyqt...@googlegroups.com
I don't fully understand why, but that did the trick! Thank you very much

Nicholas Tan Jerome

unread,
Oct 19, 2014, 10:28:01 AM10/19/14
to pyqt...@googlegroups.com
No problem, if my fix is accepted, in future you don't need this hack to make it work :)
Message has been deleted

Surabhi choudhary

unread,
Dec 9, 2016, 6:38:00 AM12/9/16
to pyqtgraph

I am facing problem in passing list through setBrush.

dkon

unread,
Nov 17, 2017, 2:32:27 AM11/17/17
to pyqtgraph
I am having the same issue trying to fill the points in a scatterplot with a list of colors. I have a list of colors that I am trying to pass with s1.setBrush. The list has the same length as x and y and each row is a 3 numbers.

it looks like this
[ (81,0,0),(135,0,0)....]


Is there a way to color each point of a scatterplot with a unique color

dkon

unread,
Nov 17, 2017, 2:34:04 AM11/17/17
to pyqtgraph


On Friday, November 17, 2017 at 12:32:27 AM UTC-7, dkon wrote:
I am having the same issue trying to fill the points in a scatterplot with a list of colors. I have a list of colors that I am trying to pass with s1.setBrush(colors). The list has the same length as x and y and each row is a 3 numbers.

colors looks like this
Reply all
Reply to author
Forward
0 new messages