Python中的 Matplotlib.axis.Axis.get_window_extent()函数
Matplotlib是Python中的一个库,它是 NumPy 库的数值数学扩展。它是Python中用于二维数组图的惊人可视化库,用于处理更广泛的 SciPy 堆栈。
Matplotlib.axis.Axis.get_window_extent()函数
matplotlib 库的轴模块中的Axis.get_window_extent()函数用于获取显示空间中的轴边界框。
Syntax: Axis.get_window_extent(self, renderer)
Parameters: This method accepts the following parameters.
- renderer: This parameter is the RendererBase subclass.
Return value: This method return the axes bounding box in display space.
下面的示例说明了 matplotlib.axis 中的 matplotlib.axis.Axis.get_window_extent()函数:
示例 1:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import numpy as np
import matplotlib.pyplot as plt
X = np.arange(-10, 10, 1.5)
Y = np.arange(-10, 10, 1.5)
U, V = np.meshgrid(X, Y)
fig, ax = plt.subplots()
ax.quiver(X, Y, U, V)
fig.canvas.draw()
renderer = fig.canvas.renderer
# use of get_window_extent() method
val = Axis.get_window_extent(ax, renderer)
print("Value Return by get_window_extent():")
print(val)
fig.suptitle('matplotlib.axis.Axis.get_window_extent() \
function Example\n', fontweight ="bold")
plt.show()
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
import numpy as np
xx = np.random.rand(10, 10)
fig, ax = plt.subplots()
m = ax.pcolor(xx)
m.set_zorder(-20)
fig.canvas.draw()
renderer = fig.canvas.renderer
# use of get_window_extent() method
val = Axis.get_window_extent(ax, renderer)
print("Value Return by get_window_extent():")
print(val)
fig.suptitle('matplotlib.axis.Axis.get_window_extent() \
function Example\n', fontweight ="bold")
plt.show()
输出:
Value Return by get_window_extent():
Bbox(x0=0.0, y0=0.0, x1=0.0, y1=0.0)
示例 2:
Python3
# Implementation of matplotlib function
from matplotlib.axis import Axis
import matplotlib.pyplot as plt
import numpy as np
xx = np.random.rand(10, 10)
fig, ax = plt.subplots()
m = ax.pcolor(xx)
m.set_zorder(-20)
fig.canvas.draw()
renderer = fig.canvas.renderer
# use of get_window_extent() method
val = Axis.get_window_extent(ax, renderer)
print("Value Return by get_window_extent():")
print(val)
fig.suptitle('matplotlib.axis.Axis.get_window_extent() \
function Example\n', fontweight ="bold")
plt.show()
输出:
Value Return by get_window_extent():
Bbox(x0=0.0, y0=0.0, x1=0.0, y1=0.0)