SourceForge logo
SourceForge logo
Menu

matplotlib-users

From: Charlie M. <cw...@gm...> - 2005年09月29日 14:02:30
Shouldn't quiver be able to handle zero length vectors?
x =3D zeros((2,2),typecode=3D'f')
quiver(x,x)
This yields a ZeroDivisionError.
Also, is there an easy way to do a flipy for imshow?
Thanks,
 Charlie
From: John B. <by...@bu...> - 2005年09月29日 16:44:00
On Thu, 2005年09月29日 at 09:01 -0500, Charlie Moad wrote:
> Shouldn't quiver be able to handle zero length vectors?
> 
The way I handle this is to add an extremely small value to one of the
vectors.
i.e. 
quiver(x+1e-15,x)
This should provide a workaround.
I think the issue lies in this snippet of code in the quiver function:
around line 855 or so in axes.py
N = sqrt( U**2+V**2 )
if do_scale:
	Nmax = maximum.reduce(maximum.reduce(N))
	U *= (S/Nmax)
	V *= (S/Nmax)
	N /= Nmax
No provision is made for the case where N is the zero vector. 
Hope it helps.
John
--
John Byrnes (by...@bu...)
Graduate Student
Electrical Engineering
Boston University
The best way to cheer yourself is to try to cheer someone else up.
		-- Mark Twain
From: John B. <by...@bu...> - 2005年09月29日 23:30:01
On Thu, 2005年09月29日 at 12:43 -0400, John Byrnes wrote:
> around line 855 or so in axes.py
>=20
> N =3D sqrt( U**2+V**2 )
> if do_scale:
> 	Nmax =3D maximum.reduce(maximum.reduce(N))
> 	U *=3D (S/Nmax)
> 	V *=3D (S/Nmax)
> 	N /=3D Nmax
>=20
> No provision is made for the case where N is the zero vector. =20
I've attached a patch for axes.py and patches.py that takes fixes the
behavior of quiver() for zero valued vectors. I'm not sure if it breaks
anything else.
Regards,
John
--
John Byrnes (by...@bu...)
Graduate Student
Electrical Engineering
Boston University
If you know how to spend less than you get, you have the philosopher's ston=
e.
		-- Benjamin Franklin
From: John B. <by...@bu...> - 2005年09月29日 23:41:58
Attachments: quiver.diff
Sorry, didn't attach the file.
John
On Thu, 2005年09月29日 at 19:31 -0400, John Byrnes wrote:
> On Thu, 2005年09月29日 at 12:43 -0400, John Byrnes wrote:
> > around line 855 or so in axes.py
> > 
> > N = sqrt( U**2+V**2 )
> > if do_scale:
> > 	Nmax = maximum.reduce(maximum.reduce(N))
> > 	U *= (S/Nmax)
> > 	V *= (S/Nmax)
> > 	N /= Nmax
> > 
> > No provision is made for the case where N is the zero vector. 
> 
> 
> I've attached a patch for axes.py and patches.py that takes fixes the
> behavior of quiver() for zero valued vectors. I'm not sure if it breaks
> anything else.
> 
> Regards,
> 
> John
> 
> --
> John Byrnes (by...@bu...)
> Graduate Student
> Electrical Engineering
> Boston University
> 
> If you know how to spend less than you get, you have the philosopher's stone.
> 		-- Benjamin Franklin
--
John Byrnes (by...@bu...)
Graduate Student
Electrical Engineering
Boston University
The radical invents the views. When he has worn them out the conservative adopts them.
		-- Mark Twain, 'Notebook,' 1935
From: Charlie M. <cw...@gm...> - 2005年09月30日 01:20:26
 I'll commit that patch, but first I have one question. Why do you
cast X and Y to Float64 types? You should technically be able to plot
a vector field with integer components.
Thanks,
 Charlie
On 9/29/05, John Byrnes <by...@bu...> wrote:
> Sorry, didn't attach the file.
>
> John
> On Thu, 2005年09月29日 at 19:31 -0400, John Byrnes wrote:
> > On Thu, 2005年09月29日 at 12:43 -0400, John Byrnes wrote:
> > > around line 855 or so in axes.py
> > >
> > > N =3D sqrt( U**2+V**2 )
> > > if do_scale:
> > > Nmax =3D maximum.reduce(maximum.reduce(N))
> > > U *=3D (S/Nmax)
> > > V *=3D (S/Nmax)
> > > N /=3D Nmax
> > >
> > > No provision is made for the case where N is the zero vector.
> >
> >
> > I've attached a patch for axes.py and patches.py that takes fixes the
> > behavior of quiver() for zero valued vectors. I'm not sure if it break=
s
> > anything else.
> >
> > Regards,
> >
> > John
> >
> > --
> > John Byrnes (by...@bu...)
> > Graduate Student
> > Electrical Engineering
> > Boston University
> >
> > If you know how to spend less than you get, you have the philosopher's =
stone.
> > -- Benjamin Franklin
>
> --
> John Byrnes (by...@bu...)
> Graduate Student
> Electrical Engineering
> Boston University
>
> The radical invents the views. When he has worn them out the conservative=
 adopts them.
> -- Mark Twain, 'Notebook,' 1935
>
>
>
From: John B. <by...@bu...> - 2005年09月30日 03:44:46
On Thu, 2005年09月29日 at 19:54 -0500, Charlie Moad wrote:
> I'll commit that patch, but first I have one question. Why do you
> cast X and Y to Float64 types? You should technically be able to plot
> a vector field with integer components.
You're correct, they shouldn't be cast to Float64. Generally, when I run
into data problems, I cast my arrays into Float types so I don't get bit
by integer division. I tried doing that in this case and forgot to undo
my change when it didn't work. Sorry about that.
Feel free to remove the end of line comments I added as well. I just
realized I didn't remove them when I made the patch.
Regards,
John
--
John Byrnes (by...@bu...)
Graduate Student
Electrical Engineering
Boston University
You should never wear your best trousers when you go out to fight for
freedom and liberty.
		-- Henrik Ibsen
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 によって変換されたページ (->オリジナル) /