Matplotlib.axis.axis.set_minor_formatter()
matplotlib库的Axis模块中的Axis.set_minor_formatter()函数用于设置次要指针的格式化器。
语法:Axis.set_minor_formatter(self, formatter)
参数:该方法接受以下参数。
- formatter:该参数是 格式化程序 .
返回值:该方法不返回任何值。
下面的例子说明了matplotlib.axis.axis.set_minor_formatter()函数在matplotlib.axis中的作用:
示例1
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
from matplotlib.ticker import MultipleLocator, ScalarFormatter
fig, ax = plt.subplots()
ax.plot([0, 5, 10, 15, 20], [3, 2, 1, 2, 4])
Axis.set_minor_locator(ax.xaxis, MultipleLocator(1))
Axis.set_minor_formatter(ax.xaxis, ScalarFormatter())
ax.tick_params(axis ='both', which ='major',
labelsize = 14, pad = 12,
colors ='g')
ax.tick_params(axis ='both', which ='minor',
labelsize = 8, colors ='b')
plt.title("Matplotlib.axis.Axis.set_minor_formatter()\n\
Function Example", fontsize = 12, fontweight ='bold')
plt.show()
输出:
示例2
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
from matplotlib.ticker import LogFormatter
import numpy as np
fig, axes = plt.subplots(2)
dt = 0.01
t = np.arange(dt, 20.0, dt)
# first plot doesn't use a formatter
axes[0].semilogx(t, np.exp(-t / 5.0))
axes[0].grid()
xlims = [[0, 25], [0.2, 8], [0.6, 0.9]]
for ax, xlim in zip(axes[1:], xlims):
ax.semilogx(t, np.exp(-t / 5.0))
formatter = LogFormatter(labelOnlyBase = False,
minor_thresholds = (2, 0.4))
Axis.set_minor_formatter(ax.xaxis, formatter)
ax.grid()
fig.suptitle("Matplotlib.axis.Axis.set_minor_formatter()\n\
Function Example", fontsize = 12, fontweight ='bold')
plt.show()
输出: