Python中的 Matplotlib.axes.Axes.get_lines()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.get_lines()函数
matplotlib 库的 axes 模块中的Axes.get_lines()函数用于返回轴包含的线列表
Syntax: Axes.get_lines(self)
Parameters: This method does not accept any parameters.
Returns: This method return a list of lines contained by the Axes.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.get_lines()函数:
示例 1:
# Implementation of matplotlib function
from matplotlib import colors
from matplotlib.ticker import PercentFormatter
import numpy as np
import matplotlib.pyplot as plt
N_points = 100000
x = np.random.randn(N_points)
y = .4 * x + np.random.randn(100000) + 5
fig, ax = plt.subplots()
ax.hist2d(x, y, bins = 100,
norm = colors.LogNorm(),
cmap ="Greens")
w = list(ax.get_lines())
if len(w)== 0:
ax.text(-2, 8.5,
"No line contained by the Axes \n")
else:
ax.text(-3, 8.5,
"List of the lines contained by the Axes \n")
x = 8.5
for i in w:
ax.text(-3, x-0.5, str(i))
x-= 0.5
fig.suptitle('matplotlib.axes.Axes.get_lines() \
function Example', fontweight ="bold")
plt.show()
输出:
示例 2:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
fig, ax = plt.subplots()
x, y = 10 * np.random.rand(2, 1000)
ax.plot(x, y, 'go', alpha = 0.2)
circ = mpatches.Circle((0.5, 0.5),
0.25,
transform = ax.transAxes,
facecolor ='blue',
alpha = 0.75)
ax.add_patch(circ)
w = list(ax.get_lines())
if len(w)== 0:
ax.text(1, 8.5,
"No line contained by the Axes \n")
else:
ax.text(1, 8.5,
"List of the lines contained by the Axes \n")
x = 8.5
for i in w:
ax.text(1, x-0.5, str(i))
x-= 0.5
fig.suptitle('matplotlib.axes.Axes.get_lines() \
function Example', fontweight ="bold")
plt.show()
输出: