pyqtgraph: добавить элемент легенды для точечных диаграмм

Я использую pyqtgraph и хочу добавить элемент в легенду для точечных диаграмм.

Я адаптировал код примера, чтобы продемонстрировать:

# -*- 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.plot([4,3,2,1], pen=None, symbol='o', symbolPen='y', symbolBrush='r', name="point plot")


## 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_()

В результате я получаю следующее: plot image

Как добавить соответствующий элемент легенды?


person MikeyB    schedule 22.05.2013    source источник


Ответы (1)


Текущая версия pyqtgraph не поддерживает эту функцию. Однако он поддерживается в нестабильной ветке. Вы можете скопировать LegendItem.py из нестабильной ветки здесь: http://bazaar.launchpad.net/~luke-campagnola/pyqtgraph/inp/view/head:/pyqtgraph/graphicsItems/LegendItem.py

person Luke    schedule 22.05.2013