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
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
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
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
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 > > >
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