# How do I use CurveArrow?

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 close merge delete

Sort by ยป oldest newest most voted

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

more

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?

( 2024-04-06 08:07:43 +0200 )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?

( 2024-04-06 08:10:22 +0200 )edit

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

( 2024-04-06 09:49:50 +0200 )edit