Matplotlib.axis.axis.get_ticklabel_extents()
matplotlib库Axis模块中的Axis.get_ticklabel_extents()函数用于获取轴两侧的刻度标签的区段
语法:Axis.get_ticklabel_extents(self, renderer)
参数:该方法接受以下参数。
- renderer:这个参数是RendererBase实例
渲染器。返回值:该方法返回轴两侧标记标签的范围
下面的例子说明了matplotlib.axis.axis.get_ticklabel_extents()函数在matplotlib.axis中的作用:
示例1
# 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()
输出:
Value Return:
(Bbox([[98.10795454545453, 29. 0777777777776], [513. 603535353535353, 43.0777777777776]]), Bbox([[0.0, 0.0], [0.0, 0.0]]))
示例2
# 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()
输出:
Value Return:
(Bbox ([[75.5625, 29.077777777777776], [580.4375, 43.077777777777776]]), Bbox ([[0.0, 0.0], [0.0, 0.0]]))