fancy arrow

I am struggling to learn how to use the new fancy arrow.

    > Does anyone have a short example of its use or is there
    > documentation aside from arrow_demo.py?

Hey Ryan,

I'm CC-ing Rob Knight, who wrote the arrow code. Perhaps you can
provide some additional detail about what you are trying to
accomplish, what you've tried, and what you don't understand.

Rob, the arrow_demo.py example Ryan is referring to is the one you

  http://svn.sourceforge.net/viewcvs.cgi/matplotlib/trunk/matplotlib/examples/arrow_demo.py?view=markup&rev=2188

Thanks!
JDH

···

sent with your original contribution, ie

I guess I am o.k. I don't know what I was doing wrong at first. I
think I was drawing the arrow off the visible part of the plot. I
seem to get pretty good results from

pylab.arrow(-30,10,10,10,head_width=2,fc='k')

and I can infer some of the options from this line in arrow_demo.py (181-183):

arrow(x_pos, y_pos, x_scale*length, y_scale*length, \
            fc=fc, ec=ec, alpha=alpha, width=width, head_width=head_width, \
            head_length=head_length, **arrow_params)

It would be great though if the docstring was more help:

Help on function arrow in module matplotlib.pylab:

arrow(*args, **kwargs)
    Draws arrow on specified axis from (x,y) to (x+dx,y+dy).
    Addition kwargs: hold = [True|False] overrides default hold state

Ryan

···

On 3/31/06, John Hunter <jdhunter@...4...> wrote:

    > I am struggling to learn how to use the new fancy arrow.
    > Does anyone have a short example of its use or is there
    > documentation aside from arrow_demo.py?

Hey Ryan,

I'm CC-ing Rob Knight, who wrote the arrow code. Perhaps you can
provide some additional detail about what you are trying to
accomplish, what you've tried, and what you don't understand.

Rob, the arrow_demo.py example Ryan is referring to is the one you
sent with your original contribution, ie

  http://svn.sourceforge.net/viewcvs.cgi/matplotlib/trunk/matplotlib/examples/arrow_demo.py?view=markup&rev=2188

Thanks!
JDH

Things are going o.k. with the fancy arrow, but I am not real happy
with the shape of my arrow head. It doesn't seem like the back of the
arrow head is perpendicular to the arrow line. I am generating an
arrow with the following code:

arrow_params={'length_includes_head':True, 'shape':'full', \
        'head_starts_at_zero':True}

arrow(-6.7,-4.5,5.4,3.2,head_width=1.5,head_length=1.0,fc='k',**arrow_params)

It seems like the problem is that my x and y axes limits are the same.
If I change the axes so they are roughly square, I get a good looking
arrow head, but my plot isn't zoomed very well.

Ryan

arrow_test.png

···

On 4/1/06, Ryan Krauss <ryanlists@...287...> wrote:

I guess I am o.k. I don't know what I was doing wrong at first. I
think I was drawing the arrow off the visible part of the plot. I
seem to get pretty good results from

pylab.arrow(-30,10,10,10,head_width=2,fc='k')

and I can infer some of the options from this line in arrow_demo.py (181-183):

arrow(x_pos, y_pos, x_scale*length, y_scale*length, \
            fc=fc, ec=ec, alpha=alpha, width=width, head_width=head_width, \
            head_length=head_length, **arrow_params)

It would be great though if the docstring was more help:

Help on function arrow in module matplotlib.pylab:

arrow(*args, **kwargs)
    Draws arrow on specified axis from (x,y) to (x+dx,y+dy).
    Addition kwargs: hold = [True|False] overrides default hold state

Ryan

On 3/31/06, John Hunter <jdhunter@...4...> wrote:

>
> > I am struggling to learn how to use the new fancy arrow.
> > Does anyone have a short example of its use or is there
> > documentation aside from arrow_demo.py?
>
> Hey Ryan,
>
> I'm CC-ing Rob Knight, who wrote the arrow code. Perhaps you can
> provide some additional detail about what you are trying to
> accomplish, what you've tried, and what you don't understand.
>
> Rob, the arrow_demo.py example Ryan is referring to is the one you
> sent with your original contribution, ie
>
> http://svn.sourceforge.net/viewcvs.cgi/matplotlib/trunk/matplotlib/examples/arrow_demo.py?view=markup&rev=2188
>
> Thanks!
> JDH
>

It seems like the problem is here:

cx = float(dx)/distance
sx = float(dy)/distance
m = array([[cx, sx],[-sx,cx]])
matrixmultiply(coords, M)

and this same code is used in regular arrow and fancy arrow. This
code is rotating by and angle whose tangent is dy/dx. That is only
going to look right to me if the x and y ranges are the same. I tried
building a hack to define my own rotation angle based on scaling dx
and dy by the axis span, but I don't know how to determine the x and y
limits from within patches.py. I don't seem to have access to gca()
or ylim() from within that script.

Ryan

···

On 4/1/06, Ryan Krauss <ryanlists@...287...> wrote:

Things are going o.k. with the fancy arrow, but I am not real happy
with the shape of my arrow head. It doesn't seem like the back of the
arrow head is perpendicular to the arrow line. I am generating an
arrow with the following code:

arrow_params={'length_includes_head':True, 'shape':'full', \
        'head_starts_at_zero':True}

arrow(-6.7,-4.5,5.4,3.2,head_width=1.5,head_length=1.0,fc='k',**arrow_params)

It seems like the problem is that my x and y axes limits are the same.
If I change the axes so they are roughly square, I get a good looking
arrow head, but my plot isn't zoomed very well.

Ryan

On 4/1/06, Ryan Krauss <ryanlists@...287...> wrote:
> I guess I am o.k. I don't know what I was doing wrong at first. I
> think I was drawing the arrow off the visible part of the plot. I
> seem to get pretty good results from
>
> pylab.arrow(-30,10,10,10,head_width=2,fc='k')
>
> and I can infer some of the options from this line in arrow_demo.py (181-183):
>
> arrow(x_pos, y_pos, x_scale*length, y_scale*length, \
> fc=fc, ec=ec, alpha=alpha, width=width, head_width=head_width, \
> head_length=head_length, **arrow_params)
>
> It would be great though if the docstring was more help:
>
> Help on function arrow in module matplotlib.pylab:
>
> arrow(*args, **kwargs)
> Draws arrow on specified axis from (x,y) to (x+dx,y+dy).
> Addition kwargs: hold = [True|False] overrides default hold state
>
> Ryan
>
> On 3/31/06, John Hunter <jdhunter@...4...> wrote:

> >
> > > I am struggling to learn how to use the new fancy arrow.
> > > Does anyone have a short example of its use or is there
> > > documentation aside from arrow_demo.py?
> >
> > Hey Ryan,
> >
> > I'm CC-ing Rob Knight, who wrote the arrow code. Perhaps you can
> > provide some additional detail about what you are trying to
> > accomplish, what you've tried, and what you don't understand.
> >
> > Rob, the arrow_demo.py example Ryan is referring to is the one you
> > sent with your original contribution, ie
> >
> > http://svn.sourceforge.net/viewcvs.cgi/matplotlib/trunk/matplotlib/examples/arrow_demo.py?view=markup&rev=2188
> >
> > Thanks!
> > JDH
> >
>

This isn't a bug in fancy_arrow -- this code intentionally does everything in data coordinates because that's the application we have for the arrows (we use both the location and size to display quantitative information).

If you want to add an option to do things in viewport coordinates, that would be great, but please don't break the existing functionality. I suggest adding viewport_coords=False in the parameter list, set to True for viewport. I believe there are hooks to get the transformation between data and viewport coordinates in mpl already, but I will not have time to look into this until after I finish teaching this semester. As John kindly pointed out, the documentation in the module itself is fairly extensive, although there is no external documentation at this point.

From inside the script, you'll want to access things from the axis's object model rather than importing pylab. Hope this is useful.

Rob

···

On Mar 31, 2006, at 11:27 PM, Ryan Krauss wrote:

It seems like the problem is here:

cx = float(dx)/distance
sx = float(dy)/distance
m = array([[cx, sx],[-sx,cx]])
matrixmultiply(coords, M)

and this same code is used in regular arrow and fancy arrow. This
code is rotating by and angle whose tangent is dy/dx. That is only
going to look right to me if the x and y ranges are the same. I tried
building a hack to define my own rotation angle based on scaling dx
and dy by the axis span, but I don't know how to determine the x and y
limits from within patches.py. I don't seem to have access to gca()
or ylim() from within that script.

Ryan

On 4/1/06, Ryan Krauss <ryanlists@...287...> wrote:

Things are going o.k. with the fancy arrow, but I am not real happy
with the shape of my arrow head. It doesn't seem like the back of the
arrow head is perpendicular to the arrow line. I am generating an
arrow with the following code:

arrow_params={'length_includes_head':True, 'shape':'full', \
        'head_starts_at_zero':True}

arrow(-6.7,-4.5,5.4,3.2,head_width=1.5,head_length=1.0,fc='k',**arrow_params)

It seems like the problem is that my x and y axes limits are the same.
If I change the axes so they are roughly square, I get a good looking
arrow head, but my plot isn't zoomed very well.

Ryan

On 4/1/06, Ryan Krauss <ryanlists@...287...> wrote:

I guess I am o.k. I don't know what I was doing wrong at first. I
think I was drawing the arrow off the visible part of the plot. I
seem to get pretty good results from

pylab.arrow(-30,10,10,10,head_width=2,fc='k')

and I can infer some of the options from this line in arrow_demo.py (181-183):

arrow(x_pos, y_pos, x_scale*length, y_scale*length, \
            fc=fc, ec=ec, alpha=alpha, width=width, head_width=head_width, \
            head_length=head_length, **arrow_params)

It would be great though if the docstring was more help:

Help on function arrow in module matplotlib.pylab:

arrow(*args, **kwargs)
    Draws arrow on specified axis from (x,y) to (x+dx,y+dy).
    Addition kwargs: hold = [True|False] overrides default hold state

Ryan

On 3/31/06, John Hunter <jdhunter@...4...> wrote:

    > I am struggling to learn how to use the new fancy arrow.
    > Does anyone have a short example of its use or is there
    > documentation aside from arrow_demo.py?

Hey Ryan,

I'm CC-ing Rob Knight, who wrote the arrow code. Perhaps you can
provide some additional detail about what you are trying to
accomplish, what you've tried, and what you don't understand.

Rob, the arrow_demo.py example Ryan is referring to is the one you
sent with your original contribution, ie

  http://svn.sourceforge.net/viewcvs.cgi/matplotlib/trunk/matplotlib/examples/arrow_demo.py?view=markup&rev=2188

Thanks!
JDH

Rob Knight wrote:

If you want to add an option to do things in viewport coordinates,

suggest adding viewport_coords=False in the parameter list, set to True for viewport. I believe there are hooks to get the transformation between data and viewport coordinates in mpl already,

This isn't as simple as we might like. That's something to keep in mind for future revisions of the API. However, for now, you can use:

matplotlib.collections.LineCollection
matplotlib.collections.PolyCollection
matplotlib.collections.PatchCollection

And a bunch of tricks with transforms.

I've enclosed and example for drawing what I call a Vector Plot. I'd be glad to clean this up and contribute it if people think it's generally useful.

-Chris

VecPlot.py (2.4 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@...259...