【问题标题】:Symbol '|' in pyqtgraph符号“|”在pyqtgraph中
【发布时间】:2022-01-02 20:42:50
【问题描述】:

我正在尝试使用“|”制作散点图pyqtgraph 中的符号(从 matplotlib 开始)。该符号在 pyqtgraph 中不可用。谁能知道我应该做什么来重现它?

【问题讨论】:

    标签: symbols scatter-plot pyqtgraph


    【解决方案1】:

    确实没有“|” pyqtgraph 中的符号。
    但是,您可以使用任何字符创建自己的符号。
    这是一个带有函数的短代码,它可以从任何字符创建新符号:

    import sys
    
    import numpy as np
    import pyqtgraph as pg
    from PyQt5 import QtGui
    from PyQt5.QtGui import QFont
    from PyQt5.QtWidgets import QApplication
    
    
    def custom_symbol(symbol: str, font: QFont = QtGui.QFont("San Serif")):
        """Create custom symbol with font"""
        # We just want one character here, comment out otherwise
        assert len(symbol) == 1
        pg_symbol = QtGui.QPainterPath()
        pg_symbol.addText(0, 0, font, symbol)
        # Scale symbol
        br = pg_symbol.boundingRect()
        scale = min(1. / br.width(), 1. / br.height())
        tr = QtGui.QTransform()
        tr.scale(scale, scale)
        tr.translate(-br.x() - br.width() / 2., -br.y() - br.height() / 2.)
        return tr.map(pg_symbol)
    
    
    if __name__ == "__main__":
        app = QApplication(sys.argv)
    
        x = np.random.normal(size=1000)
        y = np.random.normal(size=1000)
    
        pg.plot(x, y, pen=None, symbol=custom_symbol("|"))
    
        status = app.exec_()
        sys.exit(status)
    

    我使用较早的帖子来准备这个答案,可以在 here 找到。

    【讨论】:

      猜你喜欢
      • 2015-08-08
      • 2014-10-30
      • 2016-12-30
      • 2017-03-18
      • 2019-02-10
      • 2019-01-30
      • 2015-10-24
      • 2013-08-14
      • 2018-08-12
      相关资源
      最近更新 更多