20
$\begingroup$

It is easy for me to add arrows to the axes of the a figure by taking advantage of AxesStyle -> Arrowheads[] when the differences between the horizontal and vertical coordinates is small. For instance, by using

Plot[1/x, {x, -20, 20}, AxesStyle -> Arrowheads[{0.0, 0.03}]]

the arrows appear at both the horizontal and vertical axis. However, I don't know how to add arrows to the ones whose differences are big. For example, when the following program is run

Plot[1/x^5, {x, -20, 20}, AxesStyle -> Arrowheads[{0.0, 0.00003}]]

the arrows cannot be seen obviously? I want to know how I can make the arrows to be found evidently just as the previous one?

$\endgroup$
  • $\begingroup$ @rm: graphics might be a better fit; OP's question deals with primitives, as opposed to the plot itself. $\endgroup$ – J. M. is away Oct 5 '12 at 15:22
  • $\begingroup$ @J.M. The choice of primitives is not the issue here... it's just one of padding. Feel free to revert if you think graphics is better. $\endgroup$ – rm -rf Oct 5 '12 at 15:33
24
$\begingroup$
Plot[1/x^5, {x, -20, 20}, AxesStyle -> Arrowheads[{0.0, 0.05}], 
     ImagePadding -> None]

Mathematica graphics

$\endgroup$
  • $\begingroup$ Do you need the first 0.0? $\endgroup$ – cormullion Oct 5 '12 at 15:21
  • $\begingroup$ @cormullion only as a placeholder for specifying for example Arrowheads[{-0.05, 0.05}] later $\endgroup$ – Dr. belisarius Oct 5 '12 at 15:23
  • 4
    $\begingroup$ I know that ImagePadding was needed but I don't see why, nor why the default ImagePadding depends on the parameters of Arrowhead. $\endgroup$ – DavidC Oct 5 '12 at 15:24
  • $\begingroup$ @DavidCarraher I've to think about that. Probably it's due to the time in which the image size is determined (something in the plot scaling may be still unknown). You may post a question :) $\endgroup$ – Dr. belisarius Oct 5 '12 at 15:28
2
$\begingroup$

A way to overcome this problem is drawing arrows separately and combining them with the main plot through the Show function:

PR = {{-20, 20}, {-2.1*10^-4, 2.1*10^-4}};(*PlotRange*)
AO = {0, 0};(*AxesOrigin*)
extX = 3;
extY = 3*10^-5;
lw = 0.003;(*width of arrows*)

PR1 = {{PR[[1, 1]], PR[[1, 2]] + extX}, {PR[[2, 1]], PR[[2, 2]] + extY}};
Show[
   Plot[1/x^5, {x, PR1[[1, 1]], PR1[[1, 2]] - extX/5}, PlotRange -> PR1],

   Graphics[{Thickness[lw], Arrow[{{PR1[[1, 1]], AO[[2]]}, {PR1[[1, 2]], AO[[2]]}}]}],
   Graphics[{Thickness[lw], Arrow[{{AO[[1]], PR1[[2, 1]]}, {AO[[1]], PR1[[2, 2]]}}]}],

   AxesOrigin -> AO,
   PlotRange -> PR,
   PlotRangeClipping -> False,
   ImagePadding -> {{All, 30}, {All, 20}},
   AxesStyle -> Black
]

This is the result:

enter image description here


Comment:

This method helped me make a nice ListPlot of data like this,

lpData1 = {{937.65, 0.00640611}, {3758.83, 0.00668279}, {2966.86, 0.00709205}, {4184.60, 0.00788002}, {7708.82, 0.00729601}, {2582.33, 0.00830046}, {4728.61, 0.00704802}, {2257.23, 0.00701525}, {2886.35, 0.00801342}, {6477.75, 0.00755450}};

ListPlot[lpData1, PlotRange -> {{0, Max[lpData1] + 500}, {0, 0.0093}}, AxesStyle -> Arrowheads[{0.0, 0.05}], ImagePadding -> None] leads to lost axes ticks and numbers near them (corresponding plot); changes of ImagePadding and argument of Arrowheads don't help.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.