Plotting arrows at the edges of a curve

i like this post (click again to cancel)
4
i dont like this post (click again to cancel)

How could I plot a plane curve (either the graph of a function or an implicit plot) so that where the curve leaves the bounds of the plot, an arrow in the tangent direction is added?

I'm trying to produce plots for quiz and exam questions that are similar to ones you see in many calculus books where arrows are added to the ends of the curve to indicate that the curve continues in a certain direction "off the screen".

I've searched sage-support, the manual, and the documentation without much success. Perhaps I'm searching for the wrong term. Searching for "arrow" and "plot" or "curve" hasn't gotten me anywhere. I've also looked through examples in the matplotlib gallery, but I don't see any examples of what I want there.

I can imagine writing code myself to add such arrows to a plot, but I'm sure someone has thought about and implemented this before.

asked Feb 19 '11

benjaminfjones gravatar image benjaminfjones
2555 4 36 67
http://bfj7.com/

3 Answers:

i like this answer (click again to cancel)
7
i dont like this answer (click again to cancel) benjaminfjones has selected this answer as correct

Here's a quick hack. With the code given by example (I'm not the best sage/python programmer)

f = x^3; xmin = -1; xmax = 1; small=.001;
fd = f.derivative(x)
P = plot(f, (x, xmin, xmax));
P + arrow((xmin, f(x=xmin)),(xmin-small,f(x=xmin-small)))\
  + arrow((xmax, f(x=xmax)),(xmax+small,f(x=xmax+small)))

x^3

Replace x^3 with cos(x^2) to get cos(x^2) arrow plot

Edit

Here's a similar method for an implicit plot

var("x y")
f = x^2+y^3-2; xmin = -2; xmax = 2; small=.01;
fd = f.derivative(x)/f.derivative(y);
ymin = find_root(f(x=xmin),-2,2); ymax = find_root(f(x=xmax),-2,2);
P = implicit_plot(f, (x,xmin,xmax), (y,-2,2))
(P + arrow((xmin, ymin),(xmin-small,ymin+small*fd(x=xmin,y=ymin))) \
   + arrow((xmax, ymax),(xmax+small,ymax-small*fd(x=xmax,y=ymax))) \
).show(aspect_ratio=1)

implicit arrowed plot

link

posted Feb 21 '11

Simon gravatar image Simon flag of Australia
285 2 7 18
http://www.physics.uwa.ed...

updated Feb 22 '11

Nice! I think either you or @benjaminfjones should open a ticket to add this to Sage :) niles (Feb 21 '11)
I was thinking of something similar, just thought someone might have already implemented it. These plots look great. Thanks! benjaminfjones (Feb 21 '11)
i like this answer (click again to cancel)
1
i dont like this answer (click again to cancel)

I' have thought about this, but I have to admit it was only when I was reading the TikZ/PGF Manual, which remarks that perhaps the reason arrow tips are missing from so many scientific diagrams is simply that people can't figure out how to draw them :)

So I don't know how to do it in Sage, but I'll say that I use TikZ for my quiz/exam diagrams, and maybe this would make sense for you too if you're already texing them. If you've never used it before, here are a couple of examples that I thought were particularly relevant:

These are probably more complicated than what you want to do -- the manual is really a very good place to start. Sorry this doesn't tell you how to get arrow tips in Sage, but maybe this non-answer will provoke someone who does know how to do it :)

link

posted Feb 20 '11

niles gravatar image niles
3725 7 45 104
http://nilesjohnson.net/
i like this answer (click again to cancel)
0
i dont like this answer (click again to cancel)

As far as I know, the plotting in Sage is done by matplotlib. I browsed through the matplotlib docs and couldn't find anything about arrows at the ends of curves. The docs also contain a gallery of examples, and I didn't see any suitable examples. In any case, I think matplotlib is the place to look; if matplotlib can do it, then Sage probably can, but if matplotlib can't then Sage can't.

link

posted Feb 20 '11

John Palmieri gravatar image John Palmieri flag of United States
2970 9 26 67
http://www.math.washingto...

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
Login/Signup to Post

Question tools

Tags:

Stats:

Asked: Feb 19 '11

Seen: 584 times

Last updated: Feb 22 '11

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.