Python中的 Matplotlib.axis.Axis.get_minor_ticks()函数
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。它是Python中用于二维数组图的惊人可视化库,用于处理更广泛的 SciPy 堆栈。
Matplotlib.axis.Axis.get_minor_ticks()函数
matplotlib 库的轴模块中的Axis.get_minor_ticks()函数用于获取次要刻度实例。
Syntax: Axis.get_minor_ticks(self, numticks=None)
Parameters: This method accepts the following parameter.
- numticks : This parameter is the number of ticks.
Return value: This method returns the minor tick instances.
下面的示例说明了 matplotlib.axis 中的 matplotlib.axis.Axis.get_minor_ticks()函数:
示例 1:
Python3
# Implementation of matplotlib function
import numpy as np
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
np.random.seed(19680801)
fig, ax = plt.subplots()
ax.plot(100*np.random.rand(20))
formatter = ticker.FormatStrFormatter('%1.2f')
Axis.set_minor_formatter(ax.yaxis, formatter)
print("Value of get_minor_ticks() :")
for tick in ax.yaxis.get_minor_ticks(2):
tick.label1.set_color('green')
print(tick)
plt.title("Matplotlib.axis.Axis.get_minor_ticks()\n\
Function Example", fontsize = 12, fontweight ='bold')
plt.show()
Python3
# Implementation of matplotlib function
import numpy as np
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
np.random.seed(19680801)
fig, ax = plt.subplots()
ax.plot(100*np.random.rand(20))
ax.xaxis.set_minor_locator(ticker.MultipleLocator(1))
print("Value of get_minor_ticks() :")
for tick in ax.xaxis.get_minor_ticks():
tick.label1.set_color('red')
print(tick)
plt.title("Matplotlib.axis.Axis.get_minor_ticks()\n\
Function Example", fontsize = 12, fontweight ='bold')
plt.show()
输出:
Value of get_minor_ticks() :
示例 2:
Python3
# Implementation of matplotlib function
import numpy as np
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
import matplotlib.ticker as ticker
np.random.seed(19680801)
fig, ax = plt.subplots()
ax.plot(100*np.random.rand(20))
ax.xaxis.set_minor_locator(ticker.MultipleLocator(1))
print("Value of get_minor_ticks() :")
for tick in ax.xaxis.get_minor_ticks():
tick.label1.set_color('red')
print(tick)
plt.title("Matplotlib.axis.Axis.get_minor_ticks()\n\
Function Example", fontsize = 12, fontweight ='bold')
plt.show()
输出:
Value of get_minor_ticks() :