當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Python matplotlib Bbox用法及代碼示例

本文簡要介紹 python 語言中 matplotlib.transforms.Bbox 的用法。

用法

class matplotlib.transforms.Bbox(points, **kwargs)

基礎:BboxBase

一個可變的邊界框。

例子

從已知邊界創建

默認構造函數采用邊界 "points" [[xmin, ymin], [xmax, ymax]]

>>> Bbox([[1, 1], [3, 7]])
Bbox([[1.0, 1.0], [3.0, 7.0]])

或者,可以從展平的點數組創建 Bbox,即所謂的 "extents" (xmin, ymin, xmax, ymax)

>>> Bbox.from_extents(1, 1, 3, 7)
Bbox([[1.0, 1.0], [3.0, 7.0]])

或來自 "bounds" (xmin, ymin, width, height)

>>> Bbox.from_bounds(1, 1, 2, 6)
Bbox([[1.0, 1.0], [3.0, 7.0]])

從點集合創建

用於累加Bboxs的"empty"對象是null bbox,它是一個空集的stand-in。

>>> Bbox.null()
Bbox([[inf, inf], [-inf, -inf]])

向空 bbox 添加點將為您提供這些點的 bbox。

>>> box = Bbox.null()
>>> box.update_from_data_xy([[1, 1]])
>>> box
Bbox([[1.0, 1.0], [1.0, 1.0]])
>>> box.update_from_data_xy([[2, 3], [3, 2]], ignore=False)
>>> box
Bbox([[1.0, 1.0], [3.0, 3.0]])

設置ignore=True 相當於從一個空bbox 重新開始。

>>> box.update_from_data_xy([[1, 1]], ignore=True)
>>> box
Bbox([[1.0, 1.0], [1.0, 1.0]])
警告

建議始終顯式指定ignore。如果沒有,ignore 的默認值可以隨時通過有權訪問 Bbox 的代碼進行更改,例如使用方法 ignore

``null`` bbox 的屬性

注意

Bbox.null() 當前的行為可能會令人驚訝,因為它不具有 "empty set" 的所有屬性,因此在數學意義上的行為不像 "zero" 對象。我們將來可能會改變這一點(有一個棄用期)。

空 bbox 是交叉點的標識

>>> Bbox.intersection(Bbox([[1, 1], [3, 7]]), Bbox.null())
Bbox([[1.0, 1.0], [3.0, 7.0]])

除了它本身,它返回完整的空間。

>>> Bbox.intersection(Bbox.null(), Bbox.null())
Bbox([[-inf, -inf], [inf, inf]])

包含 null 的聯合將始終返回完整空間(而不是其他集合!)

>>> Bbox.union([Bbox([[0, 0], [0, 0]]), Bbox.null()])
Bbox([[-inf, -inf], [inf, inf]])
參數
points numpy.ndarray

[[x0, y0], [x1, y1]] 形式的 (2, 2) 數組。

相關用法


注:本文由純淨天空篩選整理自skytowner.com大神的英文原創作品 matplotlib.transforms.Bbox。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。