Matplotlib.axes.axes.get_lines()
Matplotlib是Python中的一个库,它是NumPy库的数值-数学扩展。Axes包含了大多数图形元素:Axis、Tick、Line2D、Text、Polygon等,并设置坐标系。Axes的实例通过callbacks属性支持回调。
函数:matplotlib.axes.axes.get_lines()
matplotlib库的Axes模块中的Axes.get_lines()函数用于返回Axes所包含的行列表
语法:Axes.get_lines(self)
参数:该方法不接受任何参数。
该方法返回Axes所包含的行列表。
下面的例子演示了matplotlib.axes.axes.get_lines()函数在matplotlib.axes中的作用:
示例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()
输出:

极客教程