FancyArrowPatch without annotate

This new FancyArrow stuff looks great, but I’m having trouble getting it to work. All of the gallery examples I see seem to only use it thru an ‘annotate’ call. I just want to draw these arrows directly.

I tried the following, but it just draws a plain line:

ax = gca()
c = matplotlib.patches.FancyArrowPatch((0.2, 0.2), (0.5, 0.5), arrowstyle="->")
ax.add_patch©

I also tried uisng call on an ArrowStyle instance:

a = matplotlib.patches.ArrowStyle.Fancy(head_length=.4, head_width=.4, tail_width=.4)
pth = matplotlib.path.Path( [[.3,.1],[.7,.5]] )
a(pth,1,1)

This gives an error. (it looks like it tries to access path.codes[:], which from what I can tell shouldn’t be accessed directly - so maybe this is a bug?).

Any hints on how to draw FancyArrow?

thanks,
Ken

Ken,

This new FancyArrow stuff looks great, but I'm having trouble getting it to
work. All of the gallery examples I see seem to only use it thru an
'annotate' call. I just want to draw these arrows directly.

I tried the following, but it just draws a plain line:

ax = gca()
c = matplotlib.patches.FancyArrowPatch((0.2, 0.2), (0.5, 0.5),
arrowstyle="->")
ax.add_patch(c)

This is a correct way indeed.
I believe that you considered it as a plain line because the arrow
head is too small.
You need to adjust the mutation_scale parameter. Try

c = matplotlib.patches.FancyArrowPatch((0.2, 0.2), (0.5, 0.5),
arrowstyle="->", mutation_scale=20.)

Maybe the defaults need to be changed.

I also tried uisng __call__ on an ArrowStyle instance:

a = matplotlib.patches.ArrowStyle.Fancy(head_length=.4, head_width=.4,
tail_width=.4)
pth = matplotlib.path.Path( [[.3,.1],[.7,.5]] )
a(pth,1,1)

This gives an error. (it looks like it tries to access path.codes[:], which
from what I can tell shouldn't be accessed directly - so maybe this is a
bug?).

This method is not intended to be called directly by user. Currently,
the first argument of the __call__ method should be a path with
path.codes != None. It can be a straight line, but still you have to
explicitly set its codes. Futhemore, some arrow classes (Simple, Fancy
and Wedge) only accept a single segment of cubic bezier line.
FancyArrowPatch internally uses ConnectionStyle class to create
bezier cuve. Take a look if you're interested in.

IHTH,

-JJ

···

On Wed, Dec 17, 2008 at 1:14 AM, Ken Schutte <kts.lists@...287...> wrote:

Any hints on how to draw FancyArrow?

thanks,
Ken

------------------------------------------------------------------------------
SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada.
The future of the web can't happen without you. Join us at MIX09 to help
pave the way to the Next Web now. Learn more and register at
http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Great. Is there a way to draw filled in arrow heads?

I’m thinking of arrows like those made by graphviz, such as,
http://www.graphviz.org/Gallery/directed/fsm.html

The closest I can seem to get is like this,
c = matplotlib.patches.FancyArrowPatch((0.2, 0.2), (0.5, 0.5),
arrowstyle=“simple”, linewidth=0.1, fc=‘k’,mutation_scale=20.)

(a) I don’t know if this is possible if the whole arrow is implemented as a single polygon (i.e. to draw line with a triangle head), and (b) I’m a bit confused about the kwargs to the different things like axes.arrow, FancyArrowPatch, ArrowStyle, etc. (for example, arrow takes ‘headwidth’, but FancyArrowPatch does not.).

Thanks a lot,
Ken

···

On Wed, Dec 17, 2008 at 1:49 AM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

This is a correct way indeed.

I believe that you considered it as a plain line because the arrow

head is too small.

You need to adjust the mutation_scale parameter. Try

c = matplotlib.patches.FancyArrowPatch((0.2, 0.2), (0.5, 0.5),

arrowstyle="->", mutation_scale=20.)

Maybe the defaults need to be changed.

This is a correct way indeed.
I believe that you considered it as a plain line because the arrow
head is too small.
You need to adjust the mutation_scale parameter. Try

c = matplotlib.patches.FancyArrowPatch((0.2, 0.2), (0.5, 0.5),
arrowstyle="->", mutation_scale=20.)

Maybe the defaults need to be changed.

Great. Is there a way to draw filled in arrow heads?

I'm thinking of arrows like those made by graphviz, such as,
http://www.graphviz.org/Gallery/directed/fsm.html

The closest I can seem to get is like this,
c = matplotlib.patches.FancyArrowPatch((0.2, 0.2), (0.5, 0.5),
arrowstyle="simple", linewidth=0.1, fc='k',mutation_scale=20.)

(a) I don't know if this is possible if the whole arrow is implemented as a
single polygon (i.e. to draw line with a triangle head), and (b) I'm a bit
confused about the kwargs to the different things like axes.arrow,
FancyArrowPatch, ArrowStyle, etc. (for example, arrow takes 'headwidth',
but FancyArrowPatch does not.).

(a) As of now, there is no arrowclass that meets your need. The arrow
is implemented as a single path, and it IS still possible to draw a
line+a triangle. But, the artist only has a single "fill" mode and it
is impossible to fill only a part of the path. It may be relatively
easy to support. I'll take a look into it.

(b) The FancyArrowPatch was very recently introduced and it's argument
is not consistent with previous ones (Arrow,FancyArrow, YAArrow).
Unlike other classes, FancyArrowPatch itself does not know how to draw
an arrow. It delegates it to ArrowStyle. So, If you want to use
FancyArrowPatch, "headwidth" should be given to ArrowStyle not to
FancyArrowPatch itself. I agree this can be a bit confusing, but all
the arrow-related parameters should be given to the style class.

Take a look at "annotation_demo2.py" and see how it specifies the
arrowstyle (and also connectionstyle). The 'arrowprops' parameter in
the annotate function is mostly consumed by FancyArrowPatch class.

Regards,

-JJ

···

On Wed, Dec 17, 2008 at 9:09 AM, Ken Schutte <kts.lists@...287...> wrote:

On Wed, Dec 17, 2008 at 1:49 AM, Jae-Joon Lee <lee.j.joon@...287...> wrote:

Thanks a lot,
Ken

Thanks for the reply. I will be taking a look at the code, and if I come up with anything useful, I can post it. (It might be nice if eventually there were extra styles, e.g. “-|>”, “<|-|>” for single lines with solid arrowheads).

Ken

···

On Wed, Dec 17, 2008 at 1:07 PM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

On Wed, Dec 17, 2008 at 9:09 AM, Ken Schutte <kts.lists@…287…> wrote:

On Wed, Dec 17, 2008 at 1:49 AM, Jae-Joon Lee <lee.j.joon@…287…> wrote:

This is a correct way indeed.

I believe that you considered it as a plain line because the arrow

head is too small.

You need to adjust the mutation_scale parameter. Try

c = matplotlib.patches.FancyArrowPatch((0.2, 0.2), (0.5, 0.5),

arrowstyle="->", mutation_scale=20.)

Maybe the defaults need to be changed.

Great. Is there a way to draw filled in arrow heads?

I’m thinking of arrows like those made by graphviz, such as,

http://www.graphviz.org/Gallery/directed/fsm.html

The closest I can seem to get is like this,

c = matplotlib.patches.FancyArrowPatch((0.2, 0.2), (0.5, 0.5),

arrowstyle=“simple”, linewidth=0.1, fc=‘k’,mutation_scale=20.)

(a) I don’t know if this is possible if the whole arrow is implemented as a

single polygon (i.e. to draw line with a triangle head), and (b) I’m a bit

confused about the kwargs to the different things like axes.arrow,

FancyArrowPatch, ArrowStyle, etc. (for example, arrow takes ‘headwidth’,

but FancyArrowPatch does not.).

(a) As of now, there is no arrowclass that meets your need. The arrow

is implemented as a single path, and it IS still possible to draw a

line+a triangle. But, the artist only has a single “fill” mode and it

is impossible to fill only a part of the path. It may be relatively

easy to support. I’ll take a look into it.

(b) The FancyArrowPatch was very recently introduced and it’s argument

is not consistent with previous ones (Arrow,FancyArrow, YAArrow).

Unlike other classes, FancyArrowPatch itself does not know how to draw

an arrow. It delegates it to ArrowStyle. So, If you want to use

FancyArrowPatch, “headwidth” should be given to ArrowStyle not to

FancyArrowPatch itself. I agree this can be a bit confusing, but all

the arrow-related parameters should be given to the style class.

Take a look at “annotation_demo2.py” and see how it specifies the

arrowstyle (and also connectionstyle). The ‘arrowprops’ parameter in

the annotate function is mostly consumed by FancyArrowPatch class.

Regards,

-JJ

This is now added in the trunk.

-JJ

···

On Wed, Dec 17, 2008 at 1:19 PM, Ken Schutte <kts.lists@...287...> wrote:

It might be nice if eventually there were extra styles, e.g. "-|>", "<|-|>"
for single lines with solid arrowheads