On 04/15/2010 04:35 AM, zieglerk wrote:
Hi,

I'm preparing some function plots for a presentation and would finally
like to add labels and arrows to the axes.  I achieve the latter by

sage: p = plot(sin(x), -3, 3)
sage: p.show(axes_labels=['$x$', '$y$'])

But oddly, there seems to be no option for the show-method of a plot
to add arrows to the axes.  Is it that uncommon?  Anyways, I added
arrows "by hand"

sage: p = plot(sin(x), -3, 3)
sage: p += arrow((3,0), (3.5,0))
sage: p.show(axes_labels=['$x$', '$y$'])

This naive approach, can't work, of course.  Since now, two things
happen:
1. the arrow clearly does not run til (3.5,0).  It seems to end at
(3.4,0) -- assuming the printed coordinate system is correct.  The
same happens, if I specify

...
sage: p += arrow((3,0), (3.5,0), arrowshorten=0)

which seems to be the default.  On the other hand arrowshorten=-10
gives me an arrow running til about (3.5,0).  But that's just the
minor problem.
2. The coordinate system gets extended past the arrow.  Which makes
sense, of course, since the coordinate systems seems to get printed
last -- for the complete plot including the arrow.  I almost got a
hold of it using axes_pad=0

sage: p = plot(sin(x), -3, 3)
sage: p += arrow((3,0), (3.5,0), arrowshorten=-15)
sage: p.show(axes_labels=['$x$', '$y$'], axes_pad=0)

But, still the coordinate axis extends a little beyond the arrow --
contrary to axes_pad=0?!

A possible solution would be, of course, to give up the coordinate
system entirely and draw the two coordinate axes as arrows.  Drawback:
I do not want to redo the ticks and labels by hand.

Another possible solution would be, to somehow change the order:  plot
function, draw coordinate system for the plotted function, draw arrow
and keep coordinate system from before.  Drawback:  I do not know how
to do it -- or even if it's possible.

I also tried to get this done in the universe of matplotlib, but there
also seems to be no need for an arrow at the end of an axis.  There
webpage lists the command "arrow" to "add an arrow to the axes", but
the description
http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.arrow
and especially the example suggest, that by "axes" they mean a line
and these arrows have no method for ticks or labels.

I'd be glad, if somebody with more experience in plotting could help.


This could help:

p = plot(sin(x), -3, 3)
p += line([(3.5,0),(3.5,0)],marker='>',markersize=7,color='black')
p += line([(0,1.01),(0,1.01)],marker='^',markersize=7,color='black')
p.show(axes_labels=['$x$', '$y$'])

Notice that I'm just drawing a line of a single point to get just the marker to show up. It's a bit of a kludge, but it works. You might still have to adjust the axes_pad argument.

Your points above certainly should be looked into. I'll try to look into them in a month when I have some time.

Thanks,

Jason

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

To unsubscribe, reply using "remove me" as the subject.

Reply via email to