大家好,我是一个使用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()中仍然可见吗?
1条答案
按热度按时间z3yyvxxp1#
framon = False从最终图像中删除不透明度数据和白色背景