Skip to content

Legend overlaps with plot contents #1226

@kangalio

Description

@kangalio

Short description

When adding a legend to a plot, the legend and the plot contents overlap. An example out of an application I'm building:
image

Code to reproduce

import pyqtgraph as pg
import numpy as np

plot = pg.plot().getPlotItem()
plot.addLegend()

x = np.arange(50)
y = np.cos(x / 100) * 3
item = pg.BarGraphItem(x=x, height=y, width=0.8, pen="w")

plot.addItem(item)
plot.legend.addItem(item, 'bar')

input("Press enter to quit")

Expected behavior

I could imagine multiple possible fixes:

  1. Make the legend opaque
  2. Automatically zoom out a little to make space for the legend

Real behavior

The legend simply appears on the top left, without any consideration whether it overlaps with the plot.

Tested environment(s)

  • PyQtGraph version: 0.11.0rc0
  • Qt Python binding: PyQt5 5.14.2 Qt 5.14.2
  • Python version: 3.8.3
  • NumPy version: 1.17.4
  • Operating system: Arch Linux
  • Installation method: pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions