Page 1 of 1

Pyqtgraph: Legende für Linien in einem Diagramm hinzufügen

Posted: 24 Dec 2024, 08:12
by Anonymous
Ich verwende pyqtgraph und möchte der Legende für InfiniteLines ein Element hinzufügen.

Ich habe den Beispielcode angepasst, um Folgendes zu demonstrieren:

# -*- coding: utf-8 -*-
"""
Demonstrates basic use of LegendItem

"""
import initExample ## Add path to library (just for examples; you do not need this)

import pyqtgraph as pg
from pyqtgraph.Qt import QtCore, QtGui

plt = pg.plot()
plt.setWindowTitle('pyqtgraph example: Legend')
plt.addLegend()

c1 = plt.plot([1,3,2,4], pen='r', name='red plot')
c2 = plt.plot([2,1,4,3], pen='g', fillLevel=0, fillBrush=(255,255,255,30), name='green plot')
c3 = plt.addLine(y=4, pen='y')
# TODO: add legend item indicating "maximum value"

## Start Qt event loop unless running in interactive mode or using pyside.
if __name__ == '__main__':
import sys
if (sys.flags.interactive != 1) or not hasattr(QtCore, 'PYQT_VERSION'):
QtGui.QApplication.instance().exec_()


Was ich als Ergebnis erhalte, ist:
Image


Wie füge ich ein geeignetes Legendenelement hinzu?