Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Mathematica Asymptotes Suppressed

39 views
Skip to first unread message

Phil Larson

unread,
Apr 12, 2001, 2:36:21 AM4/12/01
to
Is there an easy way to suppress vertical asymptotes in a Mathematica plot?

............................................................................
Phil Larson, Secondary Mathematics Author
Bob Jones University Press
1430 Wade Hampton Boulevard, Suite 207
Greenville, SC 29609
www.bjup.com
864-242-5100 x 4316; 864-298-0268 (fax)
............................................................................

Opinions expressed are my own.

"What is today a matter of academic speculation begins tomorrow to move armies and pull down empires" (J. Gresham Machen in "Christianity and Culture").


BobH...@aol.com

unread,
Apr 14, 2001, 1:31:53 AM4/14/01
to
Needs["Graphics`Graphics`"];

Plot[Tan[x], {x, 0, 2Pi}, Ticks -> {PiScale, Automatic}];

DisplayTogether[
Table[Plot[Tan[x], {x, k*Pi/2, (k+1)*Pi/2},
Ticks -> {PiScale, Automatic}, PlotRange -> {-47, 47}], {k,
0, 3}]];


Bob Hanlon

Allan Hayes

unread,
Apr 14, 2001, 1:37:19 AM4/14/01
to
Phil,

Avoiding vertical lines at discontinuites

We often wish to avoid the sort of spurious vertical features shown in

plt=Plot[Tan[x], {x, -2Pi, Pi}];

Using Split we can write a function that operates on Graphics objects and
splits lines at points where the absolute slope gets big,

DeleteVerticals[gr_Graphics, slopeMax_]:=
gr/.Line[lst_] :>
Map[Line,
Split[lst,Abs[Divide@@ Reverse[#1 -#2]]<slopeMax &],
1];

Show[DeleteVerticals[plt, 10000]]

We can use the perceived slope

DeleteVerticals2[gr_Graphics, slopeMax_]:=
gr/.Line[lst_] :>
Module[{xmin,xmax,ymin,ymax,ar,scl},
(*get the plot range and the aspect ratio used*)
{{{xmin,xmax},{ymin,ymax}},ar} =
Last/@AbsoluteOptions[gr,{PlotRange,AspectRatio}];
(*
multiplying by scl converts a slope in user coordinates to the \
slope as seen - see note below*)
scl= ar (xmax-xmin)/(ymax-ymin);
Map[Line,
Split[lst,Abs[Divide@@ Reverse[#1 -#2]] scl <slopeMax &],
1]];

Test this on the previous plot.

Show[DeleteVerticals2[plt, 200]]

--
Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
h...@haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Phil Larson" <PLa...@bju.edu> wrote in message
news:9b3id5$3...@smc.vnet.net...

Tom Burton

unread,
Apr 14, 2001, 1:43:59 AM4/14/01
to
On 12 Apr 2001 02:36:21 -0400, in comp.soft-sys.math.mathematica you wrote:

>Is there an easy way to suppress vertical asymptotes in a Mathematica plot?
>

Given, e.g.,

p = Plot[Tan[x], {x, 0, 4}]

here is a *moderately* easy way:

p2 = With[
{r = Last[PlotRange /.
AbsoluteOptions[p]]},
p /. Line[pts_] :>
Line /@ Select[Split[
pts, #2[[2]] <
r[[2]] && #2[[2]] >
r[[1]] & ],
Length[#1] > 1 & ]]

The idea here is to split the plotted line into segments all of whose points are within the vertical range of the plot.

Then

Show[p2]

This technique is not robust. Needs tweaking for log-vertical plots. It will fail with PlotRange->All. Etc, etc. ;)


Tom Burton

tgar...@prodigy.net.mx

unread,
Apr 14, 2001, 2:00:19 AM4/14/01
to
Mathematica constructs the plot of a continuous function by joining line
segments between successive points of the function in an adaptive manner (
i.e., by determining automatically the points to be sampled according to the
slope of the function). The vertical asymptotes are then a natural result of
the plotting process. This is so because there comes a moment when it has to
join a point on the positive side (possibly very far up) with a point on the
negative side, possibly very far down. This then looks like an asymptote, when
in fact it is only a particular line segment in the plot. So, if you want to
get rid of it you must first find it in the graph. What I would do is first
look at the FullForm of the graphic and extract the line segments thereof.
Take as an example the function Tan[x] in the interval 0 to Pi.

In[1]:=
a=Plot[Tan[x],{x,0,Pi}];

If you look at FullForm[a] you will get the complete description of the plot (
I omit the output in this message)

In[2]:=
b=FullForm[a]

Here you have, among other things, a list of the points which are to be joined
with line segments. Then you will have to work separately with the points on
the positive side and with those on the negative side. Select the set of
points on the positive side with Cases (this is a tricky function, since it
works with patterns, but once you get used to it you'll find it a very
powerful tool), and then the set on the negative side. Plot each set
separately, and then show them together:

In[3]:=
c1=Cases[b,List[x_,y_/;y>0],Infinity];
c2=Cases[b,List[x_,y_/;y<0],Infinity];

In[4]:=
d1=ListPlot[c1,PlotJoined->True,DisplayFunction->Identity];
d2=ListPlot[c2,PlotJoined->True,DisplayFunction->Identity];
Show[d1,d2,DisplayFunction->$DisplayFunction];

You no longer see any asymptotes in your graph. This gives you the general idea, and you'll have to adapt it to your particular problem.

Tomas Garza
Mexico City

Original Message:
-----------------
From: Phil Larson PLa...@bju.edu
Subject: Mathematica Asymptotes Suppressed


Is there an easy way to suppress vertical asymptotes in a Mathematica plot?

...........................................................................


Phil Larson, Secondary Mathematics Author
Bob Jones University Press
1430 Wade Hampton Boulevard, Suite 207
Greenville, SC 29609
www.bjup.com
864-242-5100 x 4316; 864-298-0268 (fax)
...........................................................................

Opinions expressed are my own.

"What is today a matter of academic speculation begins tomorrow to move armies and pull down empires" (J. Gresham Machen in "Christianity and Culture").


--------------------------------------------------------------------
Mail2Web - Check your email from the web at
http://www.mail2web.com/ .


0 new messages