You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在vtkplotlib的QtFigure组件中设置背景透明度为0

vtkplotlib QtFigure2 背景透明度设置解决方案

vtkplotlib 的 background_color 属性原生支持RGBA四通道参数,第四个参数即为透明度通道,取值范围0-255,设为0时即为完全透明,你可以直接修改背景色赋值语句实现需求。

修改后的示例代码如下:

import vtkplotlib as vpl

# ModelViewer
ModelViewer = vpl.QtFigure2(name="Model viewer")
ModelViewer.add_screenshot_button(pixels=1080)
ModelViewer.add_preset_views()
ModelViewer.add_cursor_tracker()

# 设置完全透明背景,四通道格式为[R, G, B, 透明度],透明度0为完全透明
ModelViewer.background_color = [255, 255, 255, 0]

# add model
plot = vpl.mesh_plot(vpl.data.get_rabbit_stl(), color=[0,100,0], fig=ModelViewer, opacity=0.1)
plot.name = "rabbit"

ModelViewer.show()

补充注意事项:

  • 若需要导出截图时保留透明背景,调用截图方法时需额外传入transparent_background=True参数,示例:ModelViewer.screenshot("output.png", transparent_background=True)
  • 透明度取值范围和RGB通道一致,数值越低透明度越高,255为完全不透明

内容的提问来源于stack exchange,提问作者marxcell

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.05 02:57:01