6

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?

Kuba
  • 136,707
  • 13
  • 279
  • 740
pawel_winzig
  • 1,577
  • 1
  • 12
  • 21
  • 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. – C. E. Sep 12 '13 at 14:08
  • 2
    @Anon It does in Mathematica 7 but it doesn't in newer versions. – Artes Sep 12 '13 at 14:09
  • @Anon: Its 8.0.0.0, Linux x86 (64-bit). This problem is always there, kernel restart does not help. – pawel_winzig Sep 12 '13 at 14:12
  • 3
    Does including Axes -> {False, True} or AxesOrigin -> {0, 0} have the desired effect (I am using Mma 7)? – user1066 Sep 12 '13 at 14:15
  • @TomD: it works, thank you! – pawel_winzig Sep 12 '13 at 14:19
  • 2
    @TomD Sounds like you should turn that into an answer. – Szabolcs Sep 12 '13 at 14:26
  • 1
    @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. – rcollyer Sep 12 '13 at 14:39
  • @rcollyer were you able to put FrameTicks and Ticks simultaneously? – Kuba Sep 12 '13 at 15:08
  • @Kuba I never tried that as I was using them effectively as GridLines, so Ticks did not matter. However, trying Plot[{x, x^2}, {x, -1, 1}, Frame -> True, Axes -> True, Ticks -> {Range[-1, 1, 0.25], Range[-1, 1, 0.25]} ] reveals that, no it seems you can't. :P – rcollyer Sep 12 '13 at 15:11
  • @rcollyer Yes I know and I was thinking lately why. That's not obvious so if one forget to Axes->False the axes are not well recognizable :) – Kuba Sep 12 '13 at 15:14

1 Answers1

11

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

Kuba
  • 136,707
  • 13
  • 279
  • 740