Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to avoid asymptotes when I ListPlot a table of data using Mathematica?

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?

like image 769
Choong Pak Shen Avatar asked Feb 18 '26 15:02

Choong Pak Shen


2 Answers

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]
like image 143
Chris Degnen Avatar answered Feb 21 '26 13:02

Chris Degnen


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]
like image 26
Dr. belisarius Avatar answered Feb 21 '26 15:02

Dr. belisarius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!