pyqtgraph中填充图的透明度

时间:2019-06-14 14:34:43

标签: python plot pyqtgraph

如果我正在制作基本的填充图,例如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')

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

1 个答案:

答案 0 :(得分:3)

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

以您的示例为例,更改此行将影响填充的透明度。将其设置为50可为您提供半透明填充

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

enter image description here

将值设置为200可以使填充更加不透明

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

enter image description here

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