Matplotlib是Python中的一个库,它是数字的-NumPy库的数学扩展。轴类包含大多数图形元素:Axis,Tick,Line2D,Text,Polygon等,并设置坐标系。 Axes实例通过callbacks属性支持回调。
matplotlib.axes.Axes.get_lines()函数
matplotlib库的axiss模块中的Axes.get_lines()函数用于返回Axes包含的线的列表
用法: Axes.get_lines(self)
参数:此方法不接受任何参数。
返回:此方法返回轴包含的行的列表。
以下示例说明了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()
输出:
相关用法
注:本文由纯净天空筛选整理自SHUBHAMSINGH10大神的英文原创作品 Matplotlib.axes.Axes.get_lines() in Python。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。