注意
跳到結尾以下載完整的範例程式碼。
使用補丁裁剪影像#
以圓形補丁裁剪影像的範例。
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()

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