【问题标题】:Transparency of a filled plot in pyqtgraphpyqtgraph中填充图的透明度
【发布时间】:2019-10-29 05:11:37
【问题描述】:

如果我正在制作一个基本的填充图,例如 pyqtgraph 中的示例。如何编辑填充区域的透明度?

import pyqtgraph as pg
win = pg.GraphicsWindow(title="Basic plotting examples")
p7 = win.addPlot(title="Filled plot, axis disabled")
y = np.sin(np.linspace(0, 10, 1000)) + np.random.normal(size=1000, scale=0.1)
p7.plot(y, fillLevel=-0.3, brush=(50,50,200,100))

您可以使用 mkBrush 制作自定义画笔:

br = pg.mkBrush(color='r')

但我找不到任何透明度选项。

【问题讨论】:

    标签: python plot pyqtgraph


    【解决方案1】:

    您可以通过更改画笔的(r,g,b,a) 元组来调整绘图的透明度。最后一个参数 (a) 确定填充图的 alpha 设置,范围为0-255。将此值设置为 0 将提供 100% 的透明度,而将其设置为 255 将提供 100% 的不透明填充。

    对于您的示例,更改此行将影响填充的透明度。将其设置为50 会给你一个半透明的填充

    p7.plot(y, fillLevel=-0.3, brush=(50,50,200,50))
    

    将值设置为 200 会提供更不透明的填充

    p7.plot(y, fillLevel=-0.3, brush=(50,50,200,200))
    

    from pyqtgraph.Qt import QtGui, QtCore
    import numpy as np
    import pyqtgraph as pg
    
    app = QtGui.QApplication([])
    
    win = pg.GraphicsWindow(title="Basic plotting examples")
    win.resize(1000,600)
    win.setWindowTitle('pyqtgraph example: Plotting')
    
    # Enable antialiasing for prettier plots
    pg.setConfigOptions(antialias=True)
    
    p7 = win.addPlot(title="Filled plot, axis disabled")
    y = np.sin(np.linspace(0, 10, 1000)) + np.random.normal(size=1000, scale=0.1)
    p7.plot(y, fillLevel=-0.3, brush=(50,50,200,50)) # <-- Adjust the brush alpha value
    p7.showAxis('bottom', False)
    
    ## 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_()
    

    【讨论】:

      猜你喜欢
      • 2016-10-12
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-17
      • 1970-01-01
      相关资源
      最近更新 更多