Matplotlib.axis.Axis.get_major_locator()
matplotlib库的Axis模块中的Axis.get_major_locator()函数用于获取主时钟的定位器。
语法:Axis.get_major_locator(self)
参数:该方法不接受任何参数。
返回值:该方法返回主标记符的定位器。
下面的例子演示了matplotlib.axis.axis.get_major_locator()函数在matplotlib.axis中的作用:
示例1
# Implementation of matplotlib function
import numpy as np
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
x = np.linspace(0, 10, 1000)
y = np.sin(2 * x)
fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(x, y)
ax.grid()
print(Axis.get_major_locator(ax.yaxis))
plt.title("Matplotlib.axis.Axis.get_major_locator()\n\
Function Example", fontsize = 12, fontweight ='bold')
plt.show()
输出:
<matplotlib.ticker.AutoLocator object at 0x07D67ED0>
示例2
# Implementation of matplotlib function
import numpy as np
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
np.random.seed(19680801)
fig, ax = plt.subplots()
x, y, s, c = np.random.rand(4, 100)
s *= 100
ax.scatter(x, y, s, c)
ax.grid()
print(Axis.get_major_locator(ax.xaxis))
plt.title("Matplotlib.axis.Axis.get_major_locator()\n\
Function Example", fontsize = 12, fontweight ='bold')
plt.show()
输出:
<matplotlib.ticker.AutoLocator object at 0x07CA9FD0>