............................................................................
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").
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
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...
>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
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/ .