Matplotlib.axis.axis.get_tightbbox()
matplotlib库的Axis模块中的Axis.get_tightbbox()函数用于获取包围轴的边框。
语法:Axis.get_tightbbox(self, renderer)
参数:该方法接受以下参数。
- renderer:这个参数是RendererBase实例
返回值:该方法返回包含轴的边界框。
下面的例子演示了matplotlib.axis.axis.get_tightbbox()函数在matplotlib.axis中的作用:
示例1
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
import numpy as np
X = np.arange(-10, 10, 0.5)
Y = np.arange(-10, 10, 0.5)
U, V = np.meshgrid(X, Y)
fig, ax = plt.subplots()
ax.quiver(X, Y, U, V)
ax.invert_xaxis()
w = Axis.get_tightbbox(ax.xaxis, fig.canvas.get_renderer())
print("Value Return :\n"+str(w))
ax.grid()
fig.suptitle("""matplotlib.axis.Axis.get_tightbbox()
function Example\n""", fontweight ="bold")
plt.show()
输出:
Value Return:
Bbox(x0=75.48368298368294, y0= 29.07777777777777776, x1=574.7670454545455, y1=43.077777777777776)
示例2
# Implementation of matplotlib function
from matplotlib.axis import Axis
import numpy as np
import matplotlib.pyplot as plt
xx = np.random.rand(8, 6)
fig, ax = plt.subplots()
m = ax.pcolor(xx)
m.set_zorder(-2)
w = Axis.get_tightbbox(ax.xaxis, fig.canvas.get_renderer())
print("Value Return :\n"+str(w))
ax.grid()
fig.suptitle("""matplotlib.axis.Axis.get_tightbbox()
function Example\n""", fontweight ="bold")
plt.show()
输出:
Valure Return:
Bbox(x0=75.5625, y0=29.077777777777776, x1=580.4375, y1= 43.07777777777777776)