Ask Your Question
0

How do I use CurveArrow?

asked 2024-04-03 20:37:23 +0100

Nate Eldredge gravatar image

I would like to plot a parametric equation with an arrow along it, to verify that the orientation is correct. I found CurveArrow which looks like what I want, but I can't figure out how to use it.

I did

from sage.plot.arrow import CurveArrow
t=var('t')
p = parametric_plot((2*cos(-t), sin(-t)), (t, 0, 2*pi))
a = CurveArrow(p, options={})

which succeeds with no errors. However, I am not sure how to actually display the plot with the arrow. Evaluating a just prints CurveArrow from (2.0, -0.0) to (2.0, 2.4492935982947064e-16). I also tried a.show(), resulting in AttributeError: 'CurveArrow' object has no attribute 'show', and I tried (p+a).show(), resulting in TypeError: other (=CurveArrow from (2.0, -0.0) to (2.0, 2.4492935982947064e-16)) must be a Graphics objects.

I'm using Sage 10.3 on MacOS under Jupyter.

Bonus: it looks like this would just plot one arrow at the beginning or ending point of the curve. Is there a simple way to plot several arrows at various points along the curve?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2024-04-04 09:42:40 +0100

rburing gravatar image

updated 2024-04-06 09:48:08 +0100

This primitive class gets used when the arrow2d function is called with a path keyword argument, so you should call that function instead of trying to use the class directly.

The arrow2d documentation refers to the bezier_path documentation for how to specify the path argument. Example:

sage: parametric_pts = [(2*cos(-t), sin(-t)) for t in srange(0, 2*pi, step=0.01)]
sage: arrow2d(path=[[p] for p in parametric_pts])

parametric arrow

edit flag offensive delete link more

Comments

Okay, arrow2d(path=p) returns Graphics object consisting of 1 graphics primitive, but arrow2d(path=p).show() fails with a long error ending in KeyError: 236. If I do p.add_primitive(a), it succeeds, but then p.show() fails with KeyErrror: 'width', as though I have to specify a lot of options instead of having them defaulted?

Nate Eldredge gravatar imageNate Eldredge ( 2024-04-06 08:07:43 +0100 )edit

The KeyError: 236 is from /private/var/tmp/sage-10.3-current/local/var/lib/sage/venv-python3.11.1/lib/python3.11/site-packages/matplotlib/path.py:406 which reads extra_vertices = NUM_VERTICES_FOR_CODE[code] - 1. As if it's confused about how many vertices the path has, or something like that?

Nate Eldredge gravatar imageNate Eldredge ( 2024-04-06 08:10:22 +0100 )edit

I added an example. I'm not sure how to make p.add_primitive(a) work, there may be a bug there.

rburing gravatar imagerburing ( 2024-04-06 09:49:50 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2024-04-03 20:37:23 +0100

Seen: 210 times

Last updated: Apr 06