Python中的 Matplotlib.figure.Figure.get_axes()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 figure 模块提供了顶级 Artist,即 Figure,其中包含所有绘图元素。该模块用于控制所有绘图元素的子图和顶级容器的默认间距。
matplotlib.figure.Figure.get_axes() 方法
matplotlib库的get_axes()方法figure模块用于获取Figure中轴的列表。
Syntax: get_axes(self)
Parameters: This method does not accept any parameters.
Returns: This method returns a list of axes in the Figure.
下面的示例说明了 matplotlib.figure 中的 matplotlib.figure.Figure.get_axes()函数:
示例 1:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
from matplotlib.tri import Triangulation
from matplotlib.patches import Polygon
import numpy as np
xs = list([ 1, 2, 3, 4, 5, 6, 7, 8, 9])
ys = list([9, 8, 7, 6, 5, 4, 3, 2, 1])
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(ys, xs)
fig.get_axes()[0].set_ylabel("Y label")
fig.get_axes()[0].set_xlabel("X label")
fig.suptitle('matplotlib.figure.Figure.get_axes()\
function Example\n\n', fontweight ="bold")
plt.show()
输出:
示例 2:
# Implementation of matplotlib function
import matplotlib.pyplot as plt
from matplotlib.tri import Triangulation
from matplotlib.patches import Polygon
import numpy as np
xs = list([ 1, 2, 3, 4, 5, 6, 7, 8, 9])
ys = list([9, 8, 7, 6, 5, 4, 3, 2, 1])
fig = plt.figure()
ax = fig.add_subplot(111)
ax.bar(ys, xs, width = 0.5, align ="center")
fig.get_axes()[0].set_ylabel("Number")
fig.get_axes()[0].set_xlabel("Values")
fig.suptitle('matplotlib.figure.Figure.get_axes()\
function Example\n\n', fontweight ="bold")
plt.show()
输出: