保存动画散点图时丢失不透明度信息

问题描述 投票:0回答:1

大家好,我对使用 python 还很陌生,目前正在运行以下代码来为我的模拟生成动画散点图:

import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
mpl.rcParams['animation.ffmpeg_path'] = r'C:\\ffmpeg\\bin\\ffmpeg.exe'

'''removed large chunk of code which correctly calculates positions etc'''

duration = 40  # length of movie in seconds

fps = 200  # required frames per second of movie

pixelx = 512  # length of x for resulting movie in pixels

pixely = 512  # length of x for resulting movie in pixels

positionlist2d, positionlist3d, alphas, sizes = movement()  # gets 2D and 3D particle co-ords for each frame in movie duration, alphas are the opacities which range dependant on z co-ord of particle and are visible in plt.show()

px = 1/plt.rcParams['figure.dpi']

fig2d, ax2d = plt.subplots(figsize=(pixelx * px, pixely * px), dpi=72, frameon=False)  # graph size, dpi correct ratio for particle size

plt.margins(x=0, y=0, tight=True)

ax2d.set_axis_off()

scatter2d = ax2d.scatter([], [], s=(pixelx*particle.rad/sim.X)**2, alpha=alphas)  # scatter, particle scale size, edgecolors='black'

ani2d = FuncAnimation(fig2d, update2d, frames=(duration * fps), init_func=initial2d, blit=False, interval=1000/fps,
                      repeat=True)  # update function to create animation of particle using calculated data

ani2d.save('2D.gif', fps=fps)

plt.show()

任何人都可以告诉我为什么我在以这种格式保存时丢失了 alpha(不透明度)数据,而它在 plt.show() 中仍然可见?

python matplotlib opacity
1个回答
0
投票

framon = False 从最终图像中删除不透明度数据和白色背景

© www.soinside.com 2019 - 2024. All rights reserved.