Never Mind. I realized that the getGradient() function on a pg.ColorMap 
object gave me a QLinearGradient object, so I just used that to create my 
own color scale in a separate widget, thus satisfying all my requirements.

On Wednesday, May 29, 2019 at 9:28:27 AM UTC-8, Israel Brewster wrote:
>
> When I add a legend to a graph using the plotItem.addLegend() function, I 
> get a nice, stationary legend that doesn't move around as I move/scale the 
> graph. This is great, but I need a color scale (I have a scatter plot with 
> colored points, and I need to show a scale bar for the colors). To this 
> end, I found the "GradientLegend" class, and managed to get it to show my 
> color map and add it to the graph using the following code:
>
> self._plot_widget = pg.PlotWidget()
> self._plot_item = self._plot_widget.getPlotItem()
> ...
> gl = pg.GradientLegend((10, 500), (10, 30))
> gl.setGradient(self._color_map.getGradient())
> gl.setParentItem(self._plot_item.getViewBox())
>
> This works, but I have to questions/issues with it:
>
> 1) Unlike the legend added with addLegend, this "legend" is not stationary 
> - it moves around as I move/scale the graph. Generally speaking, it moves 
> back to the correct location more often than not, but the effect is that it 
> "jiggles" around on the screen whenever I do something with the graph.And 
> while, as I said, it "generally" ends up back where it is supposed to, this 
> is not always the case - some times it winds up half off the screen, and I 
> have to "bump" the graph somehow to get it back on. How can I fix this so 
> it is truly stationary, in the same way a "formal" legend is?
>
> 2) Is there a way to set the size as a percentage of the window? At the 
> moment if the user scales their window down, it often cuts off the legend
>
> Assuming that at some level the GradientLegend item is/behaves like a 
> normal QtWidget, I could easily just add it to a layout and set it to 
> expanding, or at least have a minimum size constraint, so if that's 
> possible, I can work with that. Thanks.
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/c8f84084-c333-4f8f-bf14-2f5db64564ae%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to