📜  Python中的 Matplotlib.pyplot.clf()

📅  最后修改于: 2022-05-13 01:54:22.947000             🧑  作者: Mango

Python中的 Matplotlib.pyplot.clf()

Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 PyplotMatplotlib模块的基于状态的接口,它提供了一个类似 MATLAB 的接口。在 Pyplot 中可以使用各种图,包括线图、等高线图、直方图、散点图、3D 图等。

matplotlib.pyplot.clf()函数

matplotlib 库的 pyplot 模块中的clf()函数用于清除当前图形。
句法:

matplotlib.pyplot.clf()

下面的示例说明了 matplotlib.pyplot 中的 matplotlib.pyplot.clf()函数:
示例 1:

Python3
# Implementation of matplotlib function
import matplotlib.pyplot as plt
     
plt.plot([1, 2, 3, 4], [16, 4, 1, 8]) 
plt.clf()
 
plt.title('matplotlib.pyplot.clf Example')
plt.show()


Python3
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
     
t = np.linspace(0.0, 2.0, 201)
s = np.sin(2 * np.pi * t)
 
plt.ylabel('y-axis')
plt.xlabel('x-axis')
plt.plot(t, s)
plt.grid(True)
plt.clf()
 
plt.title('matplotlib.pyplot.clf Example')
plt.show()


输出:

示例 2:

Python3

# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
     
t = np.linspace(0.0, 2.0, 201)
s = np.sin(2 * np.pi * t)
 
plt.ylabel('y-axis')
plt.xlabel('x-axis')
plt.plot(t, s)
plt.grid(True)
plt.clf()
 
plt.title('matplotlib.pyplot.clf Example')
plt.show()

输出:
使用 clf()函数之前

使用 clf()函数后