|
From: Phil E. <pel...@gm...> - 2013-03-12 16:43:27
|
You could just use paths which have holes in them, making the exterior so
broad that you wouldn't notice the edge of the clipping. I've put together
an example of doing just that:
import matplotlib.pyplot as plt
import matplotlib.path as mpath
import matplotlib.collections as mcol
import numpy as np
import copy
exterior = mpath.Path.unit_rectangle()
exterior = mpath.Path(copy.deepcopy(exterior.vertices),
copy.deepcopy(exterior.codes[:]))
exterior.vertices *= 4
exterior.vertices -= 2
interior = mpath.Path.unit_circle()
interior.vertices = interior.vertices[::-1]
clip_path = mpath.Path(vertices=np.concatenate([exterior.vertices,
interior.vertices]),
codes=np.concatenate([exterior.codes,
interior.codes]))
star = mpath.Path.unit_regular_star(6)
star.vertices *= 2.6
ax = plt.subplot(321)
col = mcol.PathCollection([clip_path], facecolor='yellow')
ax.add_collection(col)
ax.set_title('Clip path')
ax.set_xlim([-3, 3])
ax.set_ylim([-3, 3])
ax = plt.subplot(322)
col = mcol.PathCollection([star], facecolor='red')
ax.add_collection(col)
ax.set_title('Target polygon')
ax.set_xlim([-3, 3])
ax.set_ylim([-3, 3])
ax = plt.subplot2grid((3, 2), (1, 0), colspan=2, rowspan=2)
col = mcol.PathCollection([star])
col.set_clip_path(clip_path, ax.transData)
ax.add_collection(col)
ax.set_title('Target polygon clipped by clip_path')
ax.set_xlim([-3, 3])
ax.set_ylim([-3, 3])
plt.tight_layout()
plt.show()
[image: Inline images 1]
There are other options if this doesn't cut the mustard.
HTH,
On 12 March 2013 15:37, Andrew Dawson <da...@at...> wrote:
> Hi
>
> I'd like to be able to clip a line so that the portion of it lying outside
> of a given polygon remains visible and the part that lies inside of the
> polygon is not visible. What I want is basically the opposite of:
>
> line.set_clip_path(polygon)
>
> which leaves only the part of the line inside the polygon visible. Is this
> possible?
>
> I know I can just fill the polygon with the background color or something
> but this gets messy when there are other lines on the plot that don't need
> to be clipped.
>
> Thanks,
> Andrew
>
>
> ------------------------------------------------------------------------------
> Symantec Endpoint Protection 12 positioned as A LEADER in The Forrester
> Wave(TM): Endpoint Security, Q1 2013 and "remains a good choice" in the
> endpoint security space. For insight on selecting the right partner to
> tackle endpoint security challenges, access the full report.
> http://p.sf.net/sfu/symantec-dev2dev
> _______________________________________________
> Matplotlib-users mailing list
> Mat...@li...
> https://lists.sourceforge.net/lists/listinfo/matplotlib-users
>
>
|