Python中的 Matplotlib.figure.Figure.get_window_extent()
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。 figure 模块提供了顶级 Artist,即 Figure,其中包含所有绘图元素。该模块用于控制所有绘图元素的子图和顶级容器的默认间距。
matplotlib.figure.Figure.get_window_extent() 方法
matplotlib库的get_window_extent()方法figure模块用于获取显示空间中的图形边界框。
Syntax: get_window_extent(self, *args, **kwargs)
Parameters: This method does not accepts any parameter.
Returns: This method return the figure bounding box in display space.
下面的示例说明了 matplotlib.figure 中的 matplotlib.figure.Figure.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 = fig.get_window_extent()
print("Value Return by get_window_extent():")
print(w)
fig.suptitle('matplotlib.figure.Figure.get_window_extent()\
function Example', fontweight ="bold")
plt.show()
输出:
Value Return by get_window_extent():
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, ax = plt.subplots()
m = ax.pcolor(xx)
m.set_zorder(-20)
w = fig.get_window_extent()
print("Value Return by get_window_extent():")
print(w)
fig.suptitle('matplotlib.figure.Figure.get_window_extent()\
function Example', fontweight ="bold")
plt.show()
输出:
Value Return by get_window_extent():
TransformedBbox(
Bbox(x0=0.0, y0=0.0, x1=6.4, y1=4.8),
Affine2D(
[[100. 0. 0.]
[ 0. 100. 0.]
[ 0. 0. 1.]]))