gpt4 book ai didi

pyqtgraph:为散点图添加图例项

转载 作者:行者123 更新时间:2023-12-02 02:02:19 24 4
gpt4 key购买 nike

我正在使用 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

如何添加适当的图例项?

最佳答案

当前版本的 pyqtgraph 不支持此功能。但是,它在 unstable 分支中受支持。您可以从此处的不稳定分支复制 LegendItem.py:http://bazaar.launchpad.net/~luke-campagnola/pyqtgraph/inp/view/head:/pyqtgraph/graphicsItems/LegendItem.py

关于pyqtgraph:为散点图添加图例项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16698116/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com