使用 matplotlib 中的多个补丁剪辑图像
我在 pylab 中有一个图,我想将其剪辑到英国地图的边界。
我还制作了一系列补丁,其中包含每个国家的轮廓:一个代表英格兰,一个代表威尔士等。
剪辑一个补丁的情节效果非常好:
fig = plt.figure()
ax = fig.add_subplot(111)
im = ax.scatter(x,y,c = z)
ax.add_patch(patch)
im.set_clip_path(patch)
但如果我尝试为多个国家做这件事,它会给我留下什么都没有——这是可以理解的,因为情节的任何部分都不会同时发生在每个国家内。
有谁知道如何使用“OR”类型语句进行剪辑? (即,如果在这个补丁或这个补丁中,则不要剪辑)。
I have a plot in pylab which I want to clip to the borders of a map of the UK.
I've also made a series of patches which contain the outlines of each country: one for England, one for Wales etc.
Clipping the plot one patch works brilliantly:
fig = plt.figure()
ax = fig.add_subplot(111)
im = ax.scatter(x,y,c = z)
ax.add_patch(patch)
im.set_clip_path(patch)
But if I try and do it for more than one, it leaves me with nothing - understandably, since no part of the plot is within each country simultaneously.
Does anyone know how I can clip using an 'OR' type statement? (ie. don't clip if within this patch or this one etc).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为你可以通过制作多个散点图,用独特的补丁剪裁每个散点图(例如,一个有英格兰,一个有爱尔兰,等等)来做到这一点。虽然这可能不是您所要求的,即“有人知道如何使用“OR”类型语句进行剪辑吗?”,它应该具有相同的效果:
在补丁之前:
打补丁后:
I think you can do this by making multiple scatter plots, clipping each one with a unique patch (eg one has England, one has Ireland, etc). Though this might not be what you asked for, ie "Does anyone know how I can clip using an 'OR' type statement?", it should have the same effect:
Before the patches:
After the patches: