4
$\begingroup$

I apologize if this question already has an answer, but my search has yielded no results, and I can't seem to figure out what's wrong with my code, so I thought I'd ask here. I'm using Mathematica 10:

In[51]:= $Version Out[51]= "10.0 for Microsoft Windows (64-bit) (September 9, 2014)"

Consider the following code:

ListPlot[ #^2 & /@ Range@10000,AxesStyle -> ConstantArray[{Arrowheads@0.01, 20}, 2]]

The problem I'm experiencing is with the arrowheads obscuring most of the ticks on both axes, that is, they are cutoff after a certain number (not exactly sure which one though). However, when I reduce the size of the arrowheads, to say 0.005, they're no longer obscured at the previous number, but after a larger number. Likewise, when I increase the size, the ticks are obscured even earlier on the axes. I've tried to explicitly state the ticks, but the same thing happens. Also, exporting the plot to pdf or png doesn't resolve the issue so I'm guessing it's a graphics issue. Is this working as intended and am I missing something obvious (in that case, is there a workaround so the ticks aren't obscured), or is it a bug?

EDIT: here's the picture (with bigger arrowheads the ticks are completely removed)
Not working as expected

EDIT 2: this one's a response to kguler's answer, but it's too long for a comment:
The first method works, but it's not exactly what I had in mind, I'd just like one arrow on the end of each axis, but I've managed to adapt the code accordingly. There's still one thing bugging me though, here's the code:
Module[ {range = {{0, 100000}, {0, 10^9}}, a = 20}, Plot[x^2, {x, 0, 100000}, PlotStyle -> {Red, Thick}, ImageSize -> 800, Epilog -> {(Arrowheads[Join[{0}, ConstantArray[.03, 1]]]), Arrow /@ ({{{0, 0}, range[[2]] + range[[2]]/a}, {{0, 0}, Reverse[range[[1]]] + Reverse[range[[1]]]/a}})}, PlotRange -> range, ImagePadding -> {{50, 40}, {40, 40}}, PlotRangeClipping -> False, AxesLabel -> {Style["x", Large], Style["y", Large]}] ]
The output is (scaled for convenience):
more buggy behavior

As you can see, the arrows are overlapping the AxesLabel, any way to fix this without Overlay or some other trick (such as setting ImageSize smaller and then using Magnify)?

$\endgroup$
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$ – bbgodfrey May 9 '15 at 14:26
  • 1
    $\begingroup$ Would you be able to add an image of your unsatisfactory output? $\endgroup$ – MarcoB May 9 '15 at 14:44
  • $\begingroup$ @kguler with your code I just get arrowheads instead of the tick marks and with no labels, I'd like to have both the labels and the tick marks. Of course, I could just not use the arrowheads, but I'd like to have them to make the graph prettier. $\endgroup$ – blueshift May 9 '15 at 15:01
  • $\begingroup$ This also happens in version8, so I'll remove the version-10 tag. I think it's a bug. $\endgroup$ – Jens May 9 '15 at 23:19
5
$\begingroup$

Update: Based on OP's update

I'd just like one arrow on the end of each axis...

the task is simpler than assumed in my original answer:

Module[{range = {{0, 100000}, {0, 10^9}}}, 
 Plot[x^2, {x, 0, 100000}, PlotStyle -> {Red, Thick}, 
  ImageSize -> 500, 
  Epilog -> {Arrowheads[.03], Arrow[{Scaled[{0, 0}], Scaled[{1, 0}]}],
     Arrow[{Scaled[{0, 0}], Scaled[{0, 1}]}]}, PlotRange -> range, 
  ImagePadding -> {{50, 40}, {40, 40}}, PlotRangeClipping -> False, 
  AxesLabel -> {Style["x", Large], Style["y", Large]}]]

Version 9.0.1.0 for Windows 8 (64-bit)

Mathematica graphics

Version 10.1.0 for Linux (Wolfram Programming Cloud):

Mathematica graphics

Also, modification of the second approach in the original post

range = {{0, 100000}, {0, 10^9}};
plt = Plot[x^2, {x, 0, 100000}, PlotStyle -> {Red, Thick}, 
   ImageSize -> 500, PlotRangeClipping -> False, PlotRange -> range, 
   AxesLabel -> {Style["x", Large], Style["y", Large]}];
axes = Graphics[{Arrowheads[.03], 
    Arrow[{Scaled[{0, 0}], Scaled[{1, 0}]}], 
    Arrow[{Scaled[{0, 0}], Scaled[{0, 1}]}]}];

Show[plt, axes]

gives the same picture as above.


Original post:

Confirmed the issue in Version 9.0.1.0 for Windows 8 (64-bit) an in Version 10.1.0 for Linux x86 (64-bit) on Wolfram Programming Cloud.

A work-around: Add the arrows using Epilog

ListPlot[#^2 & /@ Range@10000, 
 Epilog -> {(Arrowheads[Join[{0}, ConstantArray[.03, 10]]]),
   Arrow /@ ({{{0, 0}, {0, 10^8}}, {{0, 0}, {10000, 0}}})}]

Mathematica graphics

ListPlot[#^2 & /@ Range@10000, PlotRangeClipping -> False, 
 Epilog -> {(Arrowheads[Join[{0}, ConstantArray[.07, 5]]]),
   Arrow /@ ({{{0, 0}, {0, 10^8}}, {{0, 0}, {10000, 0}}})}]

Mathematica graphics

Another: Generate the arrows using Graphics and overlay it with ListPlot using Show

lp = ListPlot[#^2 & /@ Range@10000];
axes = Graphics[{(Arrowheads[Join[{0}, ConstantArray[.03, 10]]]),
    Arrow /@ (Thread[{#, {##2}}, List, {2}] & @@ (Tuples[PlotRange[lp]][[;; 3]]))}];

Show[lp, axes]
(* same picture *)
$\endgroup$
  • $\begingroup$ Alright, the first solution works quite well, I totally forgot about Scaled. The second solution is also nice, but I'll stick to the first one since this one seems to overlay the plot over the arrows, not the other way around. In any case, good work. $\endgroup$ – blueshift May 12 '15 at 19:33

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.