Matplotlib.axis.axis.get_gridlines()
matplotlib库的Axis模块中的Axis.get_gridlines()函数用于获取作为Line2D实例列表的网格线。
语法:Axis.get_gridlines(self)
参数:该方法不接受任何参数。
返回值:该方法将网格线作为Line2D实例的列表返回。
下面的例子演示了matplotlib.axis.axis.get_gridlines()函数在matplotlib.axis中的作用:
示例1
# Implementation of matplotlib function
from matplotlib.axis import Axis
import numpy as np
import matplotlib.pyplot as plt
import random
fig, ax2 = plt.subplots()
x = []
for i in range(1,11):
j = random.randint(1,10)
x.append(i*j)
ax2.plot(x)
print("Value of get_gridlines() :")
for i in ax2.xaxis.get_gridlines():
print(i)
fig.suptitle("Matplotlib.axis.Axis.get_gridlines()\
Function Example", fontsize = 12, fontweight ='bold')
plt.show()
输出:
Value of get_gridlines() :
Line2D((0,0),(0,1))
Line2D((0,0),(0,1))
Line2D((0,0),(0,1))
Line2D((0,0),(0,1))
Line2D((0,0),(0,1))
Line2D((0,0),(0,1))
Line2D((0,0),(0,1))
示例2
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
import matplotlib.text
fig, ax = plt.subplots()
ax.plot([5,1], label="Label 1")
ax.plot([3,0], label="Label 2")
legend = ax.legend(loc="upper right")
offset = matplotlib.text.OffsetFrom(legend, (1.0, 0.0))
ax.annotate("String - Info",
xy = (0,0),
size = 14,
xycoords = 'figure fraction',
xytext = (0,-20),
textcoords = offset,
horizontalalignment = 'right',
verticalalignment = 'top')
fig.canvas.draw()
ax.grid()
print("Value of get_gridlines() :")
for i in ax.yaxis.get_gridlines():
print(i)
fig.suptitle("Matplotlib.axis.Axis.get_gridlines()\
Function Example", fontsize = 12, fontweight ='bold')
plt.show()
输出:
Value of get_gridlines() :
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))
Line2D((0,0),(1,0))