SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: <pro...@cl...> - 2009年01月29日 19:40:51
<!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>&nbsp;</P>
<P>Christophe.</P>
<P><BR>----Message d'origine---- <BR>&gt;Date: 2009年1月29日 09:34:11 -0600 <BR>&gt;Sujet: Re: [Matplotlib-users] Plot only inside a disc <BR>&gt;De: John Hunter <BR>&gt;A: pro...@cl... <BR>&gt;Copie à: mat...@li... <BR>&gt; <BR>&gt;On Thu, Jan 29, 2009 at 9:19 AM, <PRO...@CL...>wrote: <BR>&gt;&gt; Hello, <BR>&gt;&gt; I would like to make a kind of magnifying glass. So I need to have a piece of <BR>&gt;&gt; a graph and I would like it to have the form
of a disc rather than of a box. <BR>&gt;&gt; So is-it possible to only draw in a disc (I'm searching for a fast way to do <BR>&gt;&gt; that) ? <BR>&gt; <BR>&gt;You can turn off the rendering of the normal axes and axis, and clip <BR>&gt;your data to an arbitrary patch or path; eg <BR>&gt; <BR>&gt; <BR>&gt; """ <BR>&gt; Clipping to arbitrary patches and paths <BR>&gt; """ <BR>&gt; import numpy as np <BR>&gt; import matplotlib.pyplot as plt <BR>&gt; import matplotlib.path as path <BR>&gt; import matplotlib.
patches as patches <BR>&gt; <BR>&gt; <BR>&gt; fig = plt.figure() <BR>&gt; ax = fig.add_subplot(111, frameon=False, xticks=[], yticks=[]) <BR>&gt; <BR>&gt; im = ax.imshow(np.random.rand(10,10)) <BR>&gt; <BR>&gt; patch = patches.Circle((300,300), radius=100) <BR>&gt; im.set_clip_path(patch) <BR>&gt; <BR>&gt; plt.show() <BR>&gt; </P></body></html>
From: <pro...@cl...> - 2009年01月29日 20:05:54
>> 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.
From: <And...@gt...> - 2009年01月30日 14:54:27
>>[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()
From: John H. <jd...@gm...> - 2009年01月30日 16:12:38
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
From: <And...@gt...> - 2009年01月30日 16:27:17
Attachments: temp.png
> -----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.
From: John H. <jd...@gm...> - 2009年01月30日 16:29:18
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
From: <And...@gt...> - 2009年01月30日 16:46:10
> -----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?
From: <And...@gt...> - 2009年01月30日 18:14:54
> -----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.
From: John H. <jd...@gm...> - 2009年01月29日 19:50:53
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
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.
Thanks for helping keep SourceForge clean.
X





Briefly describe the problem (required):
Upload screenshot of ad (required):
Select a file, or drag & drop file here.
Screenshot instructions:

Click URL instructions:
Right-click on the ad, choose "Copy Link", then paste here →
(This may not be possible with some types of ads)

More information about our ad policies

Ad destination/click URL:

AltStyle によって変換されたページ (->オリジナル) /