使用補丁裁剪影像#

以圓形補丁裁剪影像的範例。

import matplotlib.pyplot as plt

import matplotlib.cbook as cbook
import matplotlib.patches as patches

with cbook.get_sample_data('grace_hopper.jpg') as image_file:
    image = plt.imread(image_file)

fig, ax = plt.subplots()
im = ax.imshow(image)
patch = patches.Circle((260, 200), radius=200, transform=ax.transData)
im.set_clip_path(patch)

ax.axis('off')
plt.show()
image clip path

參考資料

此範例中顯示了以下函數、方法、類別和模組的使用

由 Sphinx-Gallery 產生之展示圖庫