Python中的 Matplotlib.figure.Figure.clf()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 figure 模块提供了顶级 Artist,即 Figure,其中包含所有绘图元素。该模块用于控制所有绘图元素的子图和顶级容器的默认间距。
matplotlib.figure.Figure.clf()函数
matplotlib库的图形模块的clf()方法用于清除图形。
Syntax: clf(self, keep_observers=False)
Parameters: This accept the following parameters that are described below:
- keep_observers: This parameter is the boolean value.
Returns: This method does not return any value.
下面的示例说明了 matplotlib.figure 中的 matplotlib.figure.Figure.clf()函数:
示例 1:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
ax.set_xlabel('x-axis')
ax.set_ylabel('y-axis')
ax.plot([1, 2, 3])
ax.grid(True)
fig.clf(True)
fig.suptitle('matplotlib.figure.Figure.clf() \
function Example\n\n', fontweight ="bold")
plt.show()
输出:
示例 2:
# 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)
fig, [ax, ax1] = plt.subplots(2, 1, sharex = True)
ax.set_ylabel('y-axis')
ax.plot(t, s)
ax.grid(True)
ax.set_title('Sample Example',
fontsize = 12,
fontweight ='bold')
ax1.set_ylabel('y-axis')
ax1.plot(t, s)
ax1.grid(True)
fig.clf(False)
fig.suptitle('matplotlib.figure.Figure.clf() \
function Example\n\n', fontweight ="bold")
plt.show()
输出: