Package: animplotlib
animplotlibThis package acts as a thin wrapper around thematplotlib.animation.FuncAnimationclass to simplify animatingmatplotlibplots.Installationpip install animplotlibUser manualThere are two classes which can be called:AnimPlot, for 2-D plots,
andAnimPlot3D, for 3-D plots.AnimPlotAs an example, below is a demonstration of the steps required to make a
basic plot of an Euler spiral. An Euler spiral can be obtained by plotting
theFresnel integrals,
which can be generated usingscipy.special.Import the necessary libraries and create amatplotlibfigure and axes:importanimplotlibasanimimportnumpyasnpimportmatplotlib.pyplotaspltimportscipy.specialasscfig=plt.figure()ax=fig.add_subplot(111)Generate the points being plotted:x=np.linspace(-10,10,2500)y,z=sc.fresnel(x)Create two emptymatplotlibplots: one to plot the points up to the current
most point (i.e. the 'line') and one to plot the current most point:line,=ax.plot([],[],lw=1)point,=ax.plot([],[],'o')ax.set_xlim(-1,1)ax.set_ylim(-1,1)Call theAnimPlotclass and show the plot:animation=anim.AnimPlot(fig,line,point,y,z,l_num=len(x),plot_speed=5)plt.show()l_numis the number of points before the current most point being plotted toline. The default value is set to 10, however in this example it makes sense
to set it to the same length asx(i.e. all the points before the current most
point are plotted). Similarly, an argumentp_numcan be passed to determine
the number of points being plotted topoint. This is set to 1 by default.Optional arguments:plot_speed(int) : set to 10 by default.l_num(int) : The number of points being plotted tolineeach frame. By
default this is set to 10.p_num(int) : The number of points being plotted topointeach frame. By
default, this is set to 1, i.e. only the current most point is plotted each
frame (the orange point in the gif).save_as(str) : file name to save the animation as a gif in the
current working directory.**kwargs: other arguments passable intomatplotlib.animation.FuncAnimation(seethe docsfor more info).AnimPlot3DCreating a 3-D animated plot is similar to creating a 2-D plot but with a
few additional steps.importanimplotlibasanimimportnumpyasnpimportmatplotlib.pyplotaspltimportscipy.specialasscfig=plt.figure()ax=fig.add_subplot(111,projection='3d')x=np.linspace(-10,10,3000)y,z=sc.fresnel(x)For 3-D plots, two emptymatplotlibplots must be created:lines,=[ax.plot([],[],[])]points,=[ax.plot([],[],[],'o')]The second plot,points, by default plots the 'ith' point each frame. After
that set the x, y and z limits and call theAnimPlot3Dclass.ax.set_xlim(-10,10)ax.set_ylim(-1,1)ax.set_zlim(-1,1)animation=anim.AnimPlot3D(fig,ax,[lines],[points],x,y,z,plot_speed=5)plt.show()Optional arguments:plot_speed(int) : set to 10 by default.rotation_speed(int) : proportional toplot_speed. Off by default,
enabled by setting a value.l_num(int) : The number of points being plotted tolineseach frame. By
default, all the points up until the current point get plotted.p_num(int) : The number of points being plotted topointseach frame. By
default, this is set to 1, i.e. only the current most point is plotted each
frame (the orange point in the gif).save_as(str) : file name to save the animation as a gif in the
current working directory.**kwargs: other arguments passable intomatplotlib.animation.FuncAnimation(seethe
docsfor more info).Both the 2-D and 3-D plots can be customised visually the same way you would
a normalmatplotlibplot.