7
$\begingroup$

Why is Mathematica plotting a horizontal line at $y=2$ in the following example:

ListPlot[Table[i,{i,1,10}],Frame->True,GridLines->None]

Output

How to get rid of this line?

$\endgroup$
10
  • $\begingroup$ Try restarting your kernel. It doesn't plot a line like that for me. If the problems persist, please tell us what operating system and version of Mathematica you are using. $\endgroup$
    – C. E.
    Commented Sep 12, 2013 at 14:08
  • 2
    $\begingroup$ @Anon It does in Mathematica 7 but it doesn't in newer versions. $\endgroup$
    – Artes
    Commented Sep 12, 2013 at 14:09
  • 3
    $\begingroup$ Does including Axes -> {False, True} or AxesOrigin -> {0, 0} have the desired effect (I am using Mma 7)? $\endgroup$
    – user1066
    Commented Sep 12, 2013 at 14:15
  • 2
    $\begingroup$ @TomD Sounds like you should turn that into an answer. $\endgroup$
    – Szabolcs
    Commented Sep 12, 2013 at 14:26
  • 1
    $\begingroup$ @TomD is correct, but it is much simpler to use Axes -> False since I doubt you want the y-axis. However, there are plots I've made where both frame and axes are used. $\endgroup$
    – rcollyer
    Commented Sep 12, 2013 at 14:39

1 Answer 1

12
$\begingroup$

TL;DR

What you see is the x axis, it is not the GridLine so Axes->False is the fix.

Or rather it is what you have missed because by default Axes->True and it was just a coincidence that it was observed only for V7 users.


The reason why others do not see this in newer versions is only this that the Automatic AxesOrigin is generated in different place.

To reproduce this behaviour in V9 other simply need to add this:

ListPlot[Table[i, {i, 1, 10}], Frame -> True, GridLines -> None, 
                               AxesOrigin -> {0, 2}]

enter image description here

$y$ axis is overlayed by Frame so it is "not" visible.


It could be quite confusing because with Frame->True you can't put Ticks on axes so single line do not look like and axis at all.

Even if one set FrameTicks->None... interesting, but it is different issue so let's not talk about it here.

ListPlot[Table[i, {i, 1, 10}], Frame -> True, GridLines -> None, 
                               FrameTicks -> None, AxesOrigin -> {2, 2}, 
                               Ticks -> True]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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