用补丁剪辑图像

一个圆形补丁剪辑的图像演示。

import matplotlib.pyplot as plt
import matplotlib.patches as patches
import matplotlib.cbook as cbook


with cbook.get_sample_data('grace_hopper.png') 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

工具书类

本例中显示了以下函数和方法的使用:

出:

<function Artist.set_clip_path at 0x7faa1688e950>

关键词:matplotlib代码示例,codex,python plot,pyplot Gallery generated by Sphinx-Gallery