Python中的 Matplotlib.axes.Axes.get_tightbbox()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.get_tightbbox()函数
matplotlib 库的 axes 模块中的Axes.get_tightbbox()函数用于返回轴的紧密边界框,包括轴及其装饰器。
Syntax: Axes.get_tightbbox(self, renderer, call_axes_locator=True, bbox_extra_artists=None)
Parameters: This method accepts the following parameters.
- renderer : This parameter is the RendererBase instance
renderer that will be used to draw the figures. - bbox_extra_artists : This parameter is the list of artists to include in the tight bounding box.
- call_axes_locator : This parameter is the list of artists to include in the tight bounding box.
Returns: This method return the bounding box in figure pixel coordinates.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.get_tightbbox()函数:
示例 1:
# Implementation of matplotlib function
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 = ax.get_tightbbox(fig.canvas.get_renderer(),
call_axes_locator = True,
bbox_extra_artists = None)
ax.set_title("Value Return :\n"+str(w),
fontsize = 10)
fig.suptitle('matplotlib.axes.Axes.get_tightbbox()\
function Example', fontweight ="bold")
plt.show()
输出:
示例 2:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
xx = np.random.rand(16, 30)
fig, ax = plt.subplots()
m = ax.pcolor(xx)
m.set_zorder(-20)
w = ax.get_tightbbox(fig.canvas.get_renderer(),
call_axes_locator = True,
bbox_extra_artists = None)
ax.set_title("Value Return :\n"+str(w),
fontsize = 10)
fig.suptitle('matplotlib.axes.Axes.get_tightbbox()\
function Example', fontweight ="bold")
plt.show()
输出: