📌  相关文章
📜  Python中的 Matplotlib.axis.Axis.set_minor_formatter()函数

📅  最后修改于: 2022-05-13 01:54:45.029000             🧑  作者: Mango

Python中的 Matplotlib.axis.Axis.set_minor_formatter()函数

Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。它是Python中用于二维数组图的惊人可视化库,用于处理更广泛的 SciPy 堆栈。

matplotlib.axis.Axis.set_minor_formatter()函数

matplotlib 库的轴模块中的Axis.set_minor_formatter()函数用于设置次要代码的格式化程序。

下面的示例说明了 matplotlib.axis 中的 matplotlib.axis.Axis.set_minor_formatter()函数:
示例 1:

Python3
# 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()


Python3
# 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()


输出:

示例 2:

Python3

# 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()

输出: