<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv=Content-Type content="text/html; charset=iso-8859-1"> <title>Flashmail</title> <style type="text/css"> BODY, TABLE, TR, TD, P {margin:0;padding:0;} BODY {background:#FFFFFF;} </style> </head> <body> <P>Thanks, your example works but what I must do so to plot for example y=cos x ? I'm a very beginner.</P> <P> </P> <P>Christophe.</P> <P><BR>----Message d'origine---- <BR>>Date: 2009年1月29日 09:34:11 -0600 <BR>>Sujet: Re: [Matplotlib-users] Plot only inside a disc <BR>>De: John Hunter <BR>>A: pro...@cl... <BR>>Copie à: mat...@li... <BR>> <BR>>On Thu, Jan 29, 2009 at 9:19 AM, <PRO...@CL...>wrote: <BR>>> Hello, <BR>>> I would like to make a kind of magnifying glass. So I need to have a piece of <BR>>> a graph and I would like it to have the form of a disc rather than of a box. <BR>>> So is-it possible to only draw in a disc (I'm searching for a fast way to do <BR>>> that) ? <BR>> <BR>>You can turn off the rendering of the normal axes and axis, and clip <BR>>your data to an arbitrary patch or path; eg <BR>> <BR>> <BR>> """ <BR>> Clipping to arbitrary patches and paths <BR>> """ <BR>> import numpy as np <BR>> import matplotlib.pyplot as plt <BR>> import matplotlib.path as path <BR>> import matplotlib. patches as patches <BR>> <BR>> <BR>> fig = plt.figure() <BR>> ax = fig.add_subplot(111, frameon=False, xticks=[], yticks=[]) <BR>> <BR>> im = ax.imshow(np.random.rand(10,10)) <BR>> <BR>> patch = patches.Circle((300,300), radius=100) <BR>> im.set_clip_path(patch) <BR>> <BR>> plt.show() <BR>> </P></body></html>
>> 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 Thanks a lot ! I'll look more precisely the concept of artist later. Best regards. Christophe.
>>[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()
On Fri, Jan 30, 2009 at 8:54 AM, <And...@gt...> wrote: > 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: > r.set_clip_path(cutout) > ax.add_patch(r) > plt.show() The problem is that the "add_patch" command is setting the clippath to the axes bounding box. I just committed a patch on the branch and trunk which only sets the clippath to the default if it is not already set. If you don't have access to svn, just make the call to r.set_clip_path *after* you call ax.add_patch. JDH
> -----Original Message----- > From: John Hunter [mailto:jd...@gm...] > > On Fri, Jan 30, 2009 at 8:54 AM, <And...@gt...> wrote: > > > 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: > > > r.set_clip_path(cutout) > > ax.add_patch(r) > > plt.show() > > > The problem is that the "add_patch" command is setting the clippath to > the axes bounding box. I just committed a patch on the branch and > trunk which only sets the clippath to the default if it is not already > set. If you don't have access to svn, just make the call to > r.set_clip_path *after* you call ax.add_patch. > > JDH Hmm ... this doesn't quite give me what I'm looking for. When I do that, I get a semitransparent circle that is clipped to a rectangle. What I need is a semi-transparent rectangle (with a hole cut out of the middle) that overlays the plot. The attached graphic demonstrates the concept. Thanks for the response.
On Fri, Jan 30, 2009 at 10:27 AM, <And...@gt...> wrote: > Hmm ... this doesn't quite give me what I'm looking for. When I do that, I get a semitransparent circle that is clipped to a rectangle. What I need is a semi-transparent rectangle (with a hole cut out of the middle) that overlays the plot. The attached graphic demonstrates the concept. It sounds like what you want is a complex path and may not need to muck with clipping at all. Take a look at http://matplotlib.sourceforge.net/examples/api/donut_demo.html
> -----Original Message----- > From: John Hunter [mailto:jd...@gm...] > Sent: Friday, January 30, 2009 11:29 AM > To: Henshaw, Andy > Cc: mat...@li... > Subject: Re: [Matplotlib-users] Plot only inside a disc > > On Fri, Jan 30, 2009 at 10:27 AM, <And...@gt...> > wrote: > > > Hmm ... this doesn't quite give me what I'm looking for. When I do > that, I get a semitransparent circle that is clipped to a rectangle. > What I need is a semi-transparent rectangle (with a hole cut out of the > middle) that overlays the plot. The attached graphic demonstrates the > concept. > > It sounds like what you want is a complex path and may not need to > muck with clipping at all. Take a look at > > http://matplotlib.sourceforge.net/examples/api/donut_demo.html Okay, although I wish the clipping was working as I expected, as it looks like it would have been **quite a bit** cleaner. It looks like your svn patch would enable me to do what I want with patches, wouldn't you agree?
> -----Original Message----- > From: And...@gt... > [mailto:And...@gt...] > Sent: Friday, January 30, 2009 11:46 AM > To: jd...@gm... > Cc: mat...@li... > Subject: Re: [Matplotlib-users] Plot only inside a disc > > > > > -----Original Message----- > > From: John Hunter [mailto:jd...@gm...] > > Sent: Friday, January 30, 2009 11:29 AM > > To: Henshaw, Andy > > Cc: mat...@li... > > Subject: Re: [Matplotlib-users] Plot only inside a disc > > > > On Fri, Jan 30, 2009 at 10:27 AM, <And...@gt...> > > wrote: > > > > > Hmm ... this doesn't quite give me what I'm looking for. When I do > > that, I get a semitransparent circle that is clipped to a rectangle. > > What I need is a semi-transparent rectangle (with a hole cut out of > the > > middle) that overlays the plot. The attached graphic demonstrates > the > > concept. > > > > It sounds like what you want is a complex path and may not need to > > muck with clipping at all. Take a look at > > > > http://matplotlib.sourceforge.net/examples/api/donut_demo.html > Thanks, that is working quite well, now.
On Thu, Jan 29, 2009 at 1:40 PM, <pro...@cl...> wrote: > 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