多邊形選擇器#

示範如何以程式或互動方式建立多邊形

import matplotlib.pyplot as plt

from matplotlib.widgets import PolygonSelector

以程式方式建立多邊形

fig, ax = plt.subplots()
fig.show()

selector = PolygonSelector(ax, lambda *args: None)

# Add three vertices
selector.verts = [(0.1, 0.4), (0.5, 0.9), (0.3, 0.2)]
polygon selector simple

以互動方式建立多邊形

fig2, ax2 = plt.subplots()
fig2.show()

selector2 = PolygonSelector(ax2, lambda *args: None)

print("Click on the figure to create a polygon.")
print("Press the 'esc' key to start a new polygon.")
print("Try holding the 'shift' key to move all of the vertices.")
print("Try holding the 'ctrl' key to move a single vertex.")
polygon selector simple
Click on the figure to create a polygon.
Press the 'esc' key to start a new polygon.
Try holding the 'shift' key to move all of the vertices.
Try holding the 'ctrl' key to move a single vertex.

標籤:元件:座標軸 樣式:位置 圖表類型:線條 等級:中級 領域:製圖 領域:幾何 領域:統計

參考資料

本範例展示了以下函式、方法、類別和模組的使用

由 Sphinx-Gallery 產生的圖庫