# 动态matplotlib图像

matplotlib有个官方教程提供多种方式的动态图像展示：[animation](https://matplotlib.org/gallery/index.html#animation)；

这里[官方API](https://matplotlib.org/gallery/animation/animation_demo.html#sphx-glr-gallery-animation-animation-demo-py)的例子，就是不断的清除图像画布，然后不断的重画，个人感觉这种方式简单粗暴好用，因此简单的展示用这个就好了，这里给出了一个常见的绘制散点图的动态例子：

```python
import numpy as np
import matplotlib.pyplot as plt


def draw_func():
    # 需要绘制的图形
    X = np.random.rand(100)
    Y = np.random.rand(100)
    plt.scatter(X, Y)


# 调用，不需要plt.show()
for _ in range(100000):
    plt.cla()#清除
    draw_func()#绘制
    plt.pause(0.001)#显示间隔0.001s
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://im-qianuxn.gitbook.io/pytorch/ji-suan-ji/numpy-pandas-matplotlib/matplotlib/dynamic-draw.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
