More quiver

Shouldn't quiver be able to handle zero length vectors?

x = zeros((2,2),typecode='f')
quiver(x,x)

This yields a ZeroDivisionError.

Also, is there an easy way to do a flipy for imshow?

Thanks,
     Charlie

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

···

On Thu, 2005-09-29 at 09:01 -0500, Charlie Moad wrote:

Shouldn't quiver be able to handle zero length vectors?

--
John Byrnes (byrnes@...728...)
Graduate Student
Electrical Engineering
Boston University

The best way to cheer yourself is to try to cheer someone else up.
    -- Mark Twain

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

···

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.

--
John Byrnes (byrnes@...728...)
Graduate Student
Electrical Engineering
Boston University

If you know how to spend less than you get, you have the philosopher's stone.
    -- Benjamin Franklin

Sorry, didn't attach the file.

John

quiver.diff (1.96 KB)

···

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 (byrnes@...728...)
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 (byrnes@...728...)
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 <byrnes@...728...> 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 = 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 (byrnes@...728...)
> 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 (byrnes@...728...)
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

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

···

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.

--
John Byrnes (byrnes@...728...)
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