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

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

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

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

Matplotlib.axis.Axis.get_ticklabel_extents()函数

matplotlib 库的轴模块中的Axis.get_ticklabel_extents()函数用于获取轴两侧刻度标签的范围

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

示例 1:

Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt 
import numpy as np 
     
     
X = np.arange(-5, 5, 1) 
Y = np.arange(-5, 5, 1) 
U, V = np.meshgrid(X, Y) 
       
fig, ax = plt.subplots() 
ax.quiver(X, Y, U, V) 
ax.invert_xaxis() 
w = Axis.get_ticklabel_extents(ax.xaxis,
                               fig.canvas.get_renderer()) 
     
print("Value Return :\n"+str(w)) 
ax.grid()
    
fig.suptitle("""matplotlib.axis.Axis.get_ticklabel_extents()
function Example\n""", fontweight ="bold")  
        
plt.show()


Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import numpy as np  
import matplotlib.pyplot as plt  
        
xx = np.random.rand(10, 5)  
        
fig, ax = plt.subplots()  
        
m = ax.pcolor(xx)  
m.set_zorder(-2)
  
w = Axis.get_ticklabel_extents(ax.xaxis, fig.canvas.get_renderer()) 
     
print("Value Return :\n"+str(w)) 
ax.grid()
    
fig.suptitle("""matplotlib.axis.Axis.get_ticklabel_extents()
function Example\n""", fontweight ="bold")  
        
plt.show()


输出:

示例 2:

Python3

# Implementation of matplotlib function
from matplotlib.axis import Axis
import numpy as np  
import matplotlib.pyplot as plt  
        
xx = np.random.rand(10, 5)  
        
fig, ax = plt.subplots()  
        
m = ax.pcolor(xx)  
m.set_zorder(-2)
  
w = Axis.get_ticklabel_extents(ax.xaxis, fig.canvas.get_renderer()) 
     
print("Value Return :\n"+str(w)) 
ax.grid()
    
fig.suptitle("""matplotlib.axis.Axis.get_ticklabel_extents()
function Example\n""", fontweight ="bold")  
        
plt.show()

输出: