Can Mayavi render a figure scene with a transparent background?

后端 未结 2 728
谎友^
谎友^ 2021-01-18 03:37

I am generating a mesh plot using mayavi.mlab and want the background opacity to be 0. (or transparent). Is this possible?

2条回答
  •  独厮守ぢ
    2021-01-18 04:21

    You cannot set the transparency directly. However, you can save the figure with a background colour (different than the foreground colour) and use ImageMagick to remove the background

    For example

    mlab.figure(size = (1024,768),\
                bgcolor = (1,1,1), fgcolor = (0.5, 0.5, 0.5))
    
    # Your fantastic plotting script
    
    mlab.save('pure_beauty.png')
    

    now use ImageMagick to remove the background

    convert pure_beauty.png -transparent white pure_transparent_beauty.png
    

    like shown here.

提交回复
热议问题