Python中的 Matplotlib.axes.Axes.get_window_extent()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 Axes 类包含大部分图形元素:Axis、Tick、Line2D、Text、Polygon 等,并设置坐标系。 Axes 的实例通过回调属性支持回调。
matplotlib.axes.Axes.get_window_extent()函数
matplotlib 库的 axes 模块中的Axes.get_window_extent()函数用于以显示间隔返回轴边界框。
Syntax: Axes.get_window_extent(self, \*args, \*\*kwargs)
Here, args and kwargs are empty.
Parameters: This method does not accepts any parameters.
Returns: This method return the the axes bounding box in display space.
下面的示例说明了 matplotlib.axes 中的 matplotlib.axes.Axes.get_window_extent()函数:
示例 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_window_extent()
print(str(w))
fig.suptitle('matplotlib.axes.Axes.get_window_extent()\
function Example', fontweight ="bold")
plt.show()
输出:
TransformedBbox(
Bbox(x0=0.125, y0=0.10999999999999999, x1=0.9, y1=0.88),
BboxTransformTo(
TransformedBbox(
Bbox(x0=0.0, y0=0.0, x1=6.4, y1=4.8),
Affine2D(
[[100. 0. 0.]
[ 0. 100. 0.]
[ 0. 0. 1.]]))))
示例 2:
# Implementation of matplotlib function
import numpy as np
import matplotlib.pyplot as plt
xx = np.random.rand(16, 30)
fig, ax3 = plt.subplots()
m = ax3.pcolor(xx)
m.set_zorder(-20)
w = ax3.get_window_extent()
print(str(w))
fig.suptitle('matplotlib.axes.Axes.get_window_extent() \
function Example', fontweight ="bold")
plt.show()
输出:
TransformedBbox(
Bbox(x0=0.125, y0=0.10999999999999999, x1=0.9, y1=0.88),
BboxTransformTo(
TransformedBbox(
Bbox(x0=0.0, y0=0.0, x1=6.4, y1=4.8),
Affine2D(
[[100. 0. 0.]
[ 0. 100. 0.]
[ 0. 0. 1.]]))))