Python中的 Matplotlib.artist.Artist.remove()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Artist 类包含呈现为 FigureCanvas 的对象的 Abstract 基类。图中所有可见元素都是 Artist 的子类。
Matplotlib.artist.Artist.remove() 方法
如果可能,matplotlib 库的艺术家模块中的remove() 方法用于从图形中删除艺术家。
Syntax: Artist.remove(self)
Parameters: This method does not accepts any parameter.
Returns: This method return the figure after removal of the artist.
下面的示例说明了 matplotlib 中的 matplotlib.artist.Artist.remove()函数:
示例 1:
# Implementation of matplotlib function
from matplotlib.artist import Artist
import matplotlib.pyplot as plt
fig, axs = plt.subplots()
axs.plot([1, 2, 3])
# use of remove() method
Artist.remove(axs)
fig.suptitle("""matplotlib.artist.Artist.remove()
function Example""", fontweight="bold")
plt.show()
输出:
示例 2:
# Implementation of matplotlib function
from matplotlib.artist import Artist
import matplotlib.pyplot as plt
fig, (axs, axs2) = plt.subplots(2, 1)
gs = axs2.get_gridspec()
# use of remove() method
Artist.remove(axs)
axbig = fig.add_subplot(gs[1:, -1])
axbig.annotate("Removed one Axes",
(0.4, 0.5),
xycoords ='axes fraction',
va ='center')
fig.suptitle("""matplotlib.artist.Artist.remove()
function Example""", fontweight="bold")
plt.show()
输出: