使用补丁剪切图像
演示的图像,已被一个圆形补丁裁剪。
import matplotlib.pyplot as pltimport matplotlib.patches as patchesimport matplotlib.cbook as cbookwith 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()

参考
下面的示例演示了以下函数和方法的使用:
import matplotlibmatplotlib.axes.Axes.imshowmatplotlib.pyplot.imshowmatplotlib.artist.Artist.set_clip_path
