pyqtgraph:为散点图添加图例项

Posted

技术标签:

【中文标题】pyqtgraph:为散点图添加图例项【英文标题】:pyqtgraph: add legend item for scatter plots 【发布时间】:2013-05-17 21:06:39 【问题描述】:

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

我得到的结果是:

如何添加适当的图例项?

【问题讨论】:

【参考方案1】:

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

【讨论】:

以上是关于pyqtgraph:为散点图添加图例项的主要内容,如果未能解决你的问题,请参考以下文章

为散点图添加图例

R语言散点图可视化:自定义标题和标签拟合回归线lowess为散点图添加平滑拟合线修改散点图中点颜色和点符号分组散点图添加图例pairs可视化散点图矩阵ggplt2可视化lattice

seaborn使用jointplot函数为散点图添加边缘图为散点图添加边缘直方图(Marginal Plot in Python with Seaborn jointplot)

将文本添加到道场图表(在本例中为散点图)

将图例添加到 dc.js 散点图

如何将excel的一组数据既做成散点图又做成条状图,意思就是散点图和条状图在一个图里