matplotlib.pyplot.axes.bbox 的定义
Definition of matplotlib.pyplot.axes.bbox
我不明白axes.bbox
的定义。例如:
>>> import matplotlib.pyplot as plt
>>> f, ax = plt.subplots()
>>> ax.bbox
TransformedBbox(Bbox('array([[ 0.125, 0.1 ],\n [ 0.9 , 0.9 ]])'), BboxTransformTo(TransformedBbox(Bbox('array([[ 0., 0.],\n [ 8., 6.]])'), Affine2D(array([[ 80., 0., 0.],
[ 0., 80., 0.],
[ 0., 0., 1.]])))))
这些值是什么意思?我会假设 4 个数字就足以定义一个矩形。显然这里存储了更多的信息。
对于像ax.figure.canvas.blit(bbox)
这样的命令,我需要为bbox定义一个值。我如何手动定义特定尺寸的 bbox
(比如说轴的右下四分之一)?
您看到的显示值有点复杂 Bbox
,其中包含自动应用的嵌套转换。首先,它是一个 TransformedBbox
实例——引用自文档:
A Bbox that is automatically transformed by a given transform.
它在上面显示的控制台中的表示显示了两件事(逗号分隔)- 它所基于的主要 Bbox
和它应用的 transform
。本例中的 transform
是一个 BboxTransformTo
对象,其中:
BboxTransformTo is a transformation that linearly transforms points from the unit bounding box to a given Bbox.
在你的例子中,transform
本身是基于 TransformedBBox
的,而 TransformedBBox
又具有它所基于的 Bbox
和一个转换 - 对于这个嵌套实例 Affine2D
变换。
转换的目的(我相信)是将相对坐标转换为屏幕单位。
在您的示例中,您可能会发现您期望看到的点是由
给出的
>>> ax.bbox.get_points()
array([[ 80., 48.],
[ 576., 432.]])
如果您想确定所显示的内容,所有相关代码都在 available on github 中。
从文档中,您可以用您想象的四个数字实例化一个 Bbox object,例如
from matplotlib.transforms import Bbox
my_blit_box = Bbox(np.array([[x0,y0],[x1,y1]])
您也可以使用 static methods 之一,例如
my_blit_box = Bbox.from_bounds(x0, y0, width, height)
警告
我没有你的用例,所以不能说滚动你自己的 Bbox
并将其传递给 blit()
是否会直接适用于你的案例。
然而,这可能是一个非常复杂的方法来做你想做的事。
假设您想为情节设置动画 - 您通常可以将 blit=True
作为参数传递给动画函数,它们会自行解决这个问题。 The docs are here. There are some examples here,包括有次要情节的。作为骨架 - 你可能会做类似
的事情
fig = plt.figure()
ax1 = fig.add_subplot(1, 2, 1)
ax2 = fig.add_subplot(2, 2, 2)
ax3 = fig.add_subplot(2, 2, 4)
# Code to actually put data on your 3 axes
animation.TimedAnimation.__init__(self, fig, interval=50, blit=True)
如果您想刷新多个子图中的一个 - 将 ax.bbox
直接传入 blit
函数应该可以。
请注意,给出的大多数示例都没有定义自己的 Bbox,而是将派生自 axes
、figure
或 canvas
的 Bbox 传递给 blit
.另请注意,不向 ax.figure.canvas.blit()
传递任何内容将重绘整个 canvas(默认选项 - 虽然我不明白你为什么要这样做)。
我不明白axes.bbox
的定义。例如:
>>> import matplotlib.pyplot as plt
>>> f, ax = plt.subplots()
>>> ax.bbox
TransformedBbox(Bbox('array([[ 0.125, 0.1 ],\n [ 0.9 , 0.9 ]])'), BboxTransformTo(TransformedBbox(Bbox('array([[ 0., 0.],\n [ 8., 6.]])'), Affine2D(array([[ 80., 0., 0.],
[ 0., 80., 0.],
[ 0., 0., 1.]])))))
这些值是什么意思?我会假设 4 个数字就足以定义一个矩形。显然这里存储了更多的信息。
对于像
ax.figure.canvas.blit(bbox)
这样的命令,我需要为bbox定义一个值。我如何手动定义特定尺寸的bbox
(比如说轴的右下四分之一)?
您看到的显示值有点复杂
Bbox
,其中包含自动应用的嵌套转换。首先,它是一个TransformedBbox
实例——引用自文档:A Bbox that is automatically transformed by a given transform.
它在上面显示的控制台中的表示显示了两件事(逗号分隔)- 它所基于的主要
Bbox
和它应用的transform
。本例中的transform
是一个BboxTransformTo
对象,其中:BboxTransformTo is a transformation that linearly transforms points from the unit bounding box to a given Bbox.
在你的例子中,
transform
本身是基于TransformedBBox
的,而TransformedBBox
又具有它所基于的Bbox
和一个转换 - 对于这个嵌套实例Affine2D
变换。转换的目的(我相信)是将相对坐标转换为屏幕单位。
在您的示例中,您可能会发现您期望看到的点是由
给出的>>> ax.bbox.get_points() array([[ 80., 48.], [ 576., 432.]])
如果您想确定所显示的内容,所有相关代码都在 available on github 中。
从文档中,您可以用您想象的四个数字实例化一个 Bbox object,例如
from matplotlib.transforms import Bbox my_blit_box = Bbox(np.array([[x0,y0],[x1,y1]])
您也可以使用 static methods 之一,例如
my_blit_box = Bbox.from_bounds(x0, y0, width, height)
警告
我没有你的用例,所以不能说滚动你自己的 Bbox
并将其传递给 blit()
是否会直接适用于你的案例。
然而,这可能是一个非常复杂的方法来做你想做的事。
假设您想为情节设置动画 - 您通常可以将 blit=True
作为参数传递给动画函数,它们会自行解决这个问题。 The docs are here. There are some examples here,包括有次要情节的。作为骨架 - 你可能会做类似
fig = plt.figure()
ax1 = fig.add_subplot(1, 2, 1)
ax2 = fig.add_subplot(2, 2, 2)
ax3 = fig.add_subplot(2, 2, 4)
# Code to actually put data on your 3 axes
animation.TimedAnimation.__init__(self, fig, interval=50, blit=True)
如果您想刷新多个子图中的一个 - 将 ax.bbox
直接传入 blit
函数应该可以。
请注意,给出的大多数示例都没有定义自己的 Bbox,而是将派生自 axes
、figure
或 canvas
的 Bbox 传递给 blit
.另请注意,不向 ax.figure.canvas.blit()
传递任何内容将重绘整个 canvas(默认选项 - 虽然我不明白你为什么要这样做)。