Re: How to make 2D axis with arrows?
- To: mathgroup at smc.vnet.net
- Subject: [mg28946] Re: How to make 2D axis with arrows?
- From: drnews at NOSPAM--Scientificarts.com (David Reiss)
- Date: Sat, 19 May 2001 22:28:05 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
In article <9e024m$2v6 at smc.vnet.net>, Jose Capco
<jcapco at mathematik.uni-ulm.de> wrote:
> Dear NG,
>
> I wish to know how one may able to plot a function, with arrows in the axis.
> Should I try the trick by the Graphics`Arrows` or is there some other way?
> (Also, how can I know what fonts are can/cannot be used .. is there any font
> list in Mathematica? I wish to try different fonts for AxesLabel and
> PlotLabel). Thanks in advance.
>
> Sincerely,
> Jose Capco
The following is something I did for someone as a quick
consulting project once. Consider it as presented for
free under the GNU public license... Enjoy.
Function definition: ToArrowAxes
The following, when executed will load the Graphics`Arrow` package and create
the complete definition for the ToArrowAxes function
ClearAll[ToArrowAxes];
Needs["Graphics`Arrow`"];
Options[ToArrowAxes]=Options[Arrow];
ToArrowAxes::usage=
"ToArrowAxes[graphic] takes the two-dimensional graphic given by \
\"graphic\" and places arrows at the ends of the axes. If the original \
graphic does not have axes then ToArrowAxes creates them. \n\n\
ToArrowAxes[graphic, fraction] makes the length of the arrows add to the \
length of the axes by the fraction \"fraction\" of graphic's original \
size.The default value of \"fraction\" is 1/20. \n\nToArrowAxes[graphic, \
fraction, opts] and ToArrowAxes[graphic, opts] pass the Arrow options to the \
arrows.";
ToArrowAxes::whoops=
"The first argument to ToArrowAxes must be a two-dimensional graphic with \
the Head Graphics.";
ToArrowAxes[pl_,(frac:(_?NumberQ):1/20),opts___?OptionQ]/;
Head[pl]===Graphics||Message[ToArrowAxes::whoops]:=
Module[{x0,y0,xi,xf,yi,yf,xdelta,ydelta,xiarrow,xfarrow,yiarrow,yfarrow,
prim,gopts},
{{xi,xf},{yi,yf}}=PlotRange/.AbsoluteOptions[pl,PlotRange];
{x0,y0}=AxesOrigin/.AbsoluteOptions[pl,AxesOrigin];
xdelta=(xf-xi)frac;
ydelta=(yf-yi)frac;;
xiarrow=Arrow[{xi,y0}, {xi-xdelta,y0},opts];
xfarrow=Arrow[{xf,y0}, {xf+xdelta,y0},opts];
yiarrow=Arrow[{x0,yi}, {x0,yi-ydelta},opts];
yfarrow=Arrow[{x0,yf}, {x0,yf+ydelta},opts];
Show[
Graphics[{xiarrow,xfarrow,yiarrow,yfarrow},
PlotRange\[Rule]{{xi-xdelta,xf+xdelta},{yi-ydelta,yf+ydelta}}],
FullGraphics[
pl/.Graphics[prim:{___},gopts_]:>
Graphics[prim,Axes\[Rule]True,gopts]],
DisplayFunction\[Rule]$DisplayFunction]
];
Examples of use: ToArrowAxes
pl1 = Plot[x\^2\ Sin[x], {x, \(-2\), 4}, PlotRange \[Rule] All];
ToArrowAxes[pl1];
ToArrowAxes[pl1,1/4];
ToArrowAxes[pl1,1/4, HeadCenter\[Rule]0];
ToArrowAxes[pl1,1/4, HeadCenter\[Rule].5];
--
) Scientific Arts: http://www.scientificarts.com
) Creative Services and Consultation for the Applied
) and Pure Sciences:: David Reiss: dreiss at !SPAMscientificarts.com
) [Remove the !SPAM to send email]