8
$\begingroup$

When plotting with Frame->True option, the axis is hidden when it is too close to the boundary of the plot. For example:

Plot[Sin[x], {x, 0, 10}, PlotRange -> {-0.1, 1}, Frame -> True]

X-axis is hidden

But if I increase the range, the x-axis can appear.

Plot[Sin[x], {x, 0, 10}, PlotRange -> {-0.2, 1}, Frame -> True]

X-axis is not hidden

How to force Mathematica to show the X-axis in the first case without changing the plotting range?

$\endgroup$
  • $\begingroup$ I have tried assigning AxesOrigin -> {0, 0} but it doesn't work. $\endgroup$ – Louis Yang Mar 5 '17 at 0:10
  • $\begingroup$ Thanks for the check, couldn't try myself from a phone. $\endgroup$ – Kuba Mar 5 '17 at 12:24
  • $\begingroup$ Inversely related: (32189) $\endgroup$ – Mr.Wizard Mar 10 '17 at 14:09
8
$\begingroup$

We can easily show that this is not a feature of Plot but of Graphics itself:

Graphics[Circle[], Frame -> True, Axes -> True, AxesOrigin -> {0, 0}, 
   PlotRange -> {{0, 1}, {#, 1}}] & /@ {-1/9, -1/9 - 0.00000001}

enter image description here

So it seems that the axis line is suppressed at 1/9 of the range of the plot. This holds in both directions and at other scales:

Graphics[
   {Circle[], Circle[{2, 2}, 2]}, Frame -> True, Axes -> True, 
   AxesOrigin -> {0, 0}, PlotRange -> {2 {#, 1}, 4 {#, 1}}
] & /@ {-1/9, -1/9 - 0.00000001}

enter image description here

I suspect that this was intentionally programmed into Graphics to reduce plot clutter.

I recommend the use of GridLines in its place:

Plot[Sin[x], {x, 0, 10}, PlotRange -> {-0.1, 1}, Frame -> True, 
 GridLines -> {{0}, {0}}, GridLinesStyle -> Black]

enter image description here

$\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.