Getting started with matplotlib animation (1): basic concepts

Matplotlib is a graphics library for python, and its animation functions are basically developed based on the class matplotlib.animation.Animation.

There are two main approaches to matplotlib animation, one is time-based  and the TimedAnimation other is function-basedFuncAnimation

TimedAnimation : Use a sequence of  Artist objects.

 

FuncAnimation : Repeatedly calling the func function.

call method

matplotlib.animation.FuncAnimation(figfuncframes=Noneinit_func=Nonefargs=Nonesave_count=None**kwargs)

Input parameters:

fig : matplotlib.figure.Figure
    The figure object that is used to get draw, resize, and any other needed events.
func : callable
    The function to call at each frame. The first argument will be the next value in frames. Any additional positional arguments can be supplied via the fargs parameter.
    The required signature is:  def func(frame, *fargs) -> iterable_of_artists:
frames : iterable, int, generator function, or None, optional
init_func : callable, optional
fargs : tuple or None, optional
    Additional arguments to pass to each call to func.
save_count : int, optional
    The number of values from frames to cache.

interval : number, optional
    Delay between frames in milliseconds. Defaults to 200.
repeat_delay : number, optional
    If the animation in repeated, adds a delay in milliseconds before repeating the animation. Defaults to None.
repeat : bool, optional
    Controls whether the animation should repeat when the sequence of frames is completed. Defaults to True.
blit : bool, optional
    Controls whether blitting is used to optimize drawing. Defaults to False.

 

some important concepts

1. Figure image

matplotlib.figure.Figure class. There can be multiple Figures on an artboard, and each Figure occupies a part of the area. For example, if you want to draw 4 images, then each image occupies a quarter of the space on the artboard. Each Figure has a number, and the numbers of these 4 Figures can be 1, 2, 3, 4.

The way to create a Figure is:

matplotlib.pyplot.figure(num=Nonefigsize=Nonedpi=Nonefacecolor=Noneedgecolor=Noneframeon=TrueFigureClass=<class 'matplotlib.figure.Figure'>clear=False**kwargs)

 

enter

num: 整型或字符串,表示figure的编号
figsize: tuple of integers。表示宽和高,单位:inch
dpi:分辨率
facecolor:背景颜色
edgecolor:边框颜色
frameon:是否画边框,默认true
FigureClass: matplotlib.figure.Figure的子类,用于实现自定义的Figure实例。
clear:是否清除已存在的Figure, 默认false

return:

Figure: Figure实例

 

2. Coordinate Axes

matplotlib.axes.Axes class. Axes contains most of the Figure elements, such as axes (Axis), marks (Tick), two-dimensional lines (Line2D), text (Text), polygons (polygon), etc., and a series of coordinate systems.

The way to create an Axes in a Figure is:

matplotlib.pyplot.axes(arg=None, **kwargs)

enter

arg : None or 4-tuple or Axes
    None: A new full window axes is added using subplot(111, **kwargs)

    4-tuple of floats rect = [left, bottom, width, height]. A new axes is added with dimensions rect in normalized (0, 1) units using add_axes on the current figure.

    Axes: This is equivalent to pyplot.sca. It sets the current axes to arg. Note: This implicitly changes the current figure to the parent of arg.

return:

Axes:一个Axes实例

 

AxesDrawing

matplotlib.axes.Axes.plot( *argsdata=None**kwargs ), the calling method is as follows

plot([x], y, [fmt], data=None, **kwargs)
plot([x], y, [fmt], [x2], y2, [fmt2], ..., **kwargs)
x, y : array-like or scalar,表示x和y坐标的数值
fmt : str,线条类型,比如‘ro’ 表示红色圆圈
data : indexable object,线条数据

return

lines:A list of Line2D objects representing the plotted data.

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326693022&siteId=291194637