>>[Christophe] Thanks, your example works but what I must do so to plot for 
>>example
y=cos x
>> ? I'm a very beginner.
>
>  line, = ax.plot(x, np.cos(x))
>  patch = patches.Circle((300,300), radius=100)
>  line.set_clip_path(patch)
>
>Everything in the matplotlib figure is an "Artist" (lines, images,
>text, rectangles) and you can set the clippath of any artist.  See
>
>  http://matplotlib.sourceforge.net/users/artists.html
>  http://matplotlib.sourceforge.net/api/artist_api.html
>
>JDH

This is a very timely question for me.  I'm needing to do something very 
similar, but I need to overlay a semi-transparent rectangle with a hole cut out 
of it.  So, I'm making a rectangular patch, making a circular patch, setting 
the circular patch as the clip region for the rectangular patch, and then 
adding the clipped patch to the plot.  However, I seem to be having trouble 
with the coordinate system, as there is no clipping on the rectangle.

My test code looks like this:

import numpy as np
import matplotlib.pyplot as plt
import matplotlib.path as path
import matplotlib.patches as patches

fig = plt.figure()
ax = fig.add_subplot(111)
x = np.arange(-50,50,0.1)
line, = ax.plot(x, np.cos(x)*50)
r=patches.Rectangle((-10,-10), 20, 20, fc=(0.5,0.5,0.5,0.9))
r.set_zorder(100)

# shouldn't one of these work?
# Plot coordinate system
cutout = patches.Circle((0,0), radius=10)
# Window coordinate system
#~ cutout = patches.Circle((300,300), radius=50)

r.set_clip_path(cutout)
ax.add_patch(r)
plt.show()

------------------------------------------------------------------------------
This SF.net email is sponsored by:
SourcForge Community
SourceForge wants to tell your story.
http://p.sf.net/sfu/sf-spreadtheword
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to