3

I am plotting a table of data using ListPlot in Mathematica. I notice that there are a few asymptotes on the graph which I do not want it to be plotted (i.e. the straight lines between the curves). What should I do to remove the straight lines?

3 Answers3

3

Perhaps:

t = Table[Tan[i], {i, -Pi, Pi, .01}];
ListPlot[#, Joined -> True] & /@ {t, t /. x_ /; Abs@x > 10 -> None}

enter image description here

Edit

More robust:

t = Table[Tan[i], {i, -Pi, Pi, .01}];
ao = AbsoluteOptions[ListPlot[t, Joined -> True],PlotRange]/. {_ -> {_,x_}} ->x;
ListPlot[t /. x_ /; (x < ao[[1]] || x > ao[[2]]) -> None,  Joined -> True]
Dr. belisarius
  • 60,527
  • 15
  • 115
  • 190
3

A method from Mark McClure's post here: How to annotate multiple datasets in ListPlots

t = Table[Tan[i], {i, -Pi, Pi, .01}];
plot = ListLinePlot[t];
DeleteCases[plot, Line[_?(Length[#] < 4 &)], Infinity]
Community
  • 1
  • 1
Chris Degnen
  • 8,443
  • 2
  • 23
  • 40
0
t = Table[Tan[i], {i, -Pi, Pi, .01}];
plot = ListLinePlot[t];

Using Position

Position[plot, Line[___], Infinity]

{{1, 1, 3, 2}, {1, 1, 3, 3}, {1, 1, 3, 4}, {1, 1, 3, 5}, {1, 1, 3, 6}}

Using Part:

plot[[1, 1, 3, 5 ;; 6]] = Sequence[]; Show[plot]
681234
  • 4,214
  • 2
  • 35
  • 42