使用matplotlib中的几个补丁剪辑图像

使用matplotlib中的几个补丁剪辑图像,第1张

使用matplotlib中的几个补丁剪辑图像

我认为您可以通过制作多个散点图,用一个唯一的补丁裁剪每个散点图(例如,一个具有英格兰,一个具有爱尔兰等)来做到这一点。尽管这可能不是您所要求的,即“有人知道我可以使用’OR’类型的语句进行裁剪吗?”,但它应该具有相同的效果:

import numpy as npimport matplotlib.pyplot as pltimport matplotlib.patches as patchesnp.random.seed(101)x = np.random.random(100)y = np.random.random(100)fig = plt.figure()ax = fig.add_subplot(111)imForEngland = ax.scatter(x,y)fig.savefig('beforeclip.png')imForWales = ax.scatter(x,y)england = patches.Circle((.75,.75),radius=.25,fc='none')wales = patches.Circle((.25,.25),radius=.25,fc='none')ax.add_patch(england)ax.add_patch(wales)imForEngland.set_clip_path(england)imForWales.set_clip_path(wales)fig.savefig('afterclip.png')

补丁之前:补丁 之后:



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5631670.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存