With clip_path set, things inside the clip_path is only drawn. So, I
think you're misusing clip_path.
To draw a rectangle with a hole in it, you need to create a compound
path. And, this requires some understanding of how path system works
in general.
See this,
http://matplotlib.sourceforge.net/users/path_tutorial.html
and
http://old.nabble.com/Compound-paths-to19278422.html#a19296862
Here is modified version of your script that draws a rectangle with a
hole. It concatenates two existing paths. But, often it is better to
start from scratch (but again you need to understand how path works).
And of course, the resulting compound path can be set as a clip_path
of other artist.
Regards,
-JJ
import matplotlib
from matplotlib import patches
import pylab
fig=pylab.figure()
ax=fig.add_subplot(111)
# background line
line = ax.plot( [ 1, 2, 3], [ 1, 2, 3 ] )
# mask polygon that should cover/hide the area not intersecting the
poly_patch = patches.Polygon(((1,1),(1,3),(3,3), (3,1)))
# part I would like to see through
hole_patch = patches.Circle((2,2), radius=.5, facecolor='red')
from matplotlib.bezier import make_path_regular, concatenate_paths
from matplotlib.path import Path
from matplotlib.patches import PathPatch
poly_path = make_path_regular(poly_patch.get_path())
# close the path
closed_polygon_path = Path(list(poly_path.vertices)+[(0,0)],
list(poly_path.codes)+[Path.CLOSEPOLY])
# circle with coordinate transformed
hole_path = hole_patch.get_path()
hole_path_transformed =
hole_patch.get_patch_transform().transform_path(hole_path)
# make polygon with a hole
poly_with_hole_path = concatenate_paths([closed_polygon_path,
hole_path_transformed])
poly_with_hole_patch = PathPatch(poly_with_hole_path)
ax.add_patch(poly_with_hole_patch)
ax.set_xlim(0, 4)
ax.set_ylim(0, 4)
pylab.show()
···
On Fri, Mar 12, 2010 at 7:45 AM, othererik <othererik@...287...> wrote:
Here's a short example that does the opposite of what I'm looking for. The
goal is to take a the polygon "poly_patch" and "cut" regions out of it.
All I've managed to achieve so far has been to show regions of the
"poly_patch".