py3.4 - ColorMap method getGradient raises exception [solved]

42 views
Skip to first unread message

Charles Parker

unread,
Apr 21, 2016, 11:58:17 AM4/21/16
to pyqtgraph
Hi all,

Because reasons, I found a problem with the getGradient function in the ColorMap class when using python 3.

Here's the code that I've executed:

cmap = self.color_widget.colorMap()
self.legend.setGradient(cmap.getGradient())

which causes the following exception:

File "C:\Python34\lib\site-packages\pyqtgraph\colormap.py", line 140, in getGradient
    g.setStops(zip(pos, color))
TypeError: QGradient.setStops(list-of-tuple-of-float-QColor): argument 1 has unexpected type 'zip'


I found that modifying the function call in colormap.py from

g.setStops(zip(pos, color))

to

g.setStops(list(zip(pos, color)))

fixed the problem.

In python 2.7, zip returns a list of tuples, while in python 3.4 it returns a generator which needs to be converted to a list for setStops to work.  Hopefully this helps someone!

Vincent Le Saux

unread,
Apr 22, 2016, 8:39:32 AM4/22/16
to pyqtgraph
Hi, Thank you for the feedback. Do you think you can propose a Pull Request on the pyqtgraph repository to fix this problem?

Cheers

Vincent

Ben

unread,
Sep 28, 2016, 7:04:04 PM9/28/16
to pyqtgraph
I just created a pull request at https://github.com/pyqtgraph/pyqtgraph/pull/378

It is a simple one-liner that Charles described. It fixes the problem demonstrated above, but this issue might exist in other places as well.
Reply all
Reply to author
Forward
0 new messages