pyqtgraph 中填充图的透明度
Transparency of a filled plot in 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')
但是我找不到任何透明度选项。
您可以通过更改画笔的 (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_()
如果我正在制作一个基本的填充图,就像 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')
但是我找不到任何透明度选项。
您可以通过更改画笔的 (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_()