GradientLegend draws upside down

495 views
Skip to first unread message

Patrick Norman

unread,
Jun 11, 2013, 12:37:07 AM6/11/13
to pyqt...@googlegroups.com
I believe there might be a bug with the GradientLegend drawing. When I try to add a gradient legend it is always drawn upside down.

To reproduce:
Open isocurve.py from the pyqtgraph examples and add the following after line 29:
gl = pg.GradientLegend((10,300), (10,30))
vb.addItem(gl)

Run isocurve.py and the gradient legend is drawn upside down (min at the top, max at the bottom, text upside down).

I had a look inside the GradientLegend class and couldn't see any reason there why it could be drawing like this, it's as if the painter is just drawing everything upside down for some reason.

Has anyone else noticed this or could it be something wrong with my setup (running Windows 7, Qt 4.8)?

Pat.

Luke Campagnola

unread,
Jun 11, 2013, 1:32:05 AM6/11/13
to pyqt...@googlegroups.com
On Tue, Jun 11, 2013 at 12:37 AM, Patrick Norman <patr...@gmail.com> wrote:
I believe there might be a bug with the GradientLegend drawing. When I try to add a gradient legend it is always drawn upside down.

To reproduce:
Open isocurve.py from the pyqtgraph examples and add the following after line 29:
gl = pg.GradientLegend((10,300), (10,30))
vb.addItem(gl)

Run isocurve.py and the gradient legend is drawn upside down (min at the top, max at the bottom, text upside down).

GradientLegend is not intended to be placed inside a ViewBox--that coordinate system is arbitrary and meant to represent the natural coordinates of your data, whereas the position and size of a legend is generally expressed in pixels relative to the borders of the view area. So a better use for GradientLegend is this:

gl = pg.GradientLegend((10,300), (10,30))
gl.setParentItem(vb)

Having said that, it is still possible to put a GradientLegend inside a ViewBox if you flip it vertically. The reason for this is that Qt expresses all of its coordinates in pixels, with the y-axis pointing downward. This convention is preserved throughout pyqtgraph except inside ViewBox, where the y-axis is flipped because most people expect their data to be represented this way. So if you want to use a GradientLegend inside a ViewBox, it would look like this:

gl = pg.GradientLegend((10,300), (10,30))
vb.addItem(gl)
gl.scale(1, -1)

I realize this is not intuitive and deserves better documentation / examples..


Luke

Patrick Norman

unread,
Jul 4, 2013, 12:37:31 AM7/4/13
to pyqt...@googlegroups.com
Ahh, thanks for that explanation, it's all working properly now.

Cheers,
Pat.

Reply all
Reply to author
Forward
0 new messages