Python中的 Matplotlib.figure.Figure.delaxes()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 figure 模块提供了顶级 Artist,即 Figure,其中包含所有绘图元素。该模块用于控制所有绘图元素的子图和顶级容器的默认间距。
matplotlib.figure.Figure.delaxes()函数
matplotlib库的图形模块的delaxes()方法用于从图形中移除Axes ax并更新当前轴。
Syntax: delaxes(self, ax)
Parameters: This accept the following parameters that are described below:
- ax: This parameter is the axes to be removed.
Returns: This method does not return any value.
下面的示例说明了 matplotlib.figure 中的 matplotlib.figure.Figure.delaxes()函数:
示例 1:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
import numpy as np
# make an agg figure
fig, ax = plt.subplots()
ax.plot([1, 2, 3])
fig.delaxes(ax)
fig.suptitle('matplotlib.figure.Figure.delaxes() \
function Example\n\n', fontweight ="bold")
plt.show()
输出:
示例 2:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
dt = 0.01
t = np.arange(0, 30, dt)
nse1 = np.random.randn(len(t))
r = np.exp(-t / 0.05)
cnse1 = np.convolve(nse1, r, mode ='same')*dt
s1 = np.cos(np.pi * t) + cnse1 + np.sin(2 * np.pi * 10 * t)
fig, [ax1, ax2] = plt.subplots(2, 1)
ax1.plot(t, s1)
ax1.set_xlim(0, 5)
ax1.set_ylabel('value s1')
ax1.grid(True)
ax2.psd(s1, 256, 1./dt)
ax2.set_ylabel('PSD(db)')
ax2.set_xlabel('Frequency')
fig.delaxes(ax = ax1)
fig.suptitle('matplotlib.figure.Figure.delaxes() \
function Example\n\n', fontweight ="bold")
plt.show()
输出: