Last active
May 23, 2024 07:49
-
-
Save ArthurDelannoyazerty/577e1bb56b9a07d023fef6975fefe640 to your computer and use it in GitHub Desktop.
A function that create a gif/mp4 of a rotating 3d matplotlib plot.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rotanimate(ax, output_filename:str, angles:list=None, elevation:list=None, width:float=8, height:float=8, filename_prefix:str='tmprot_', nb_image:int=120, fps:int=30): | |
if angles==None: angles = np.linspace(0, 360, nb_image+1) | |
if elevation==None: elevation = np.linspace(20, 20, nb_image+1) | |
ax.figure.set_size_inches(width,height) | |
files = [] | |
for i, angle in enumerate(angles): | |
ax.view_init(elev = elevation[i], azim=angle) | |
fname = '%s%03d.jpeg'%(filename_prefix,i) | |
ax.figure.savefig(fname) | |
files.append(fname) | |
os.system('ffmpeg -y -r ' + str(fps) + ' -i tmprot_%03d.jpeg ' + output_filename) | |
for f in files: | |
os.remove(f) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With all comments & import
With small comments :
Example of code
Output example
of
images