Re: Plotting w/o artifacts at discontinuities
- To: mathgroup@smc.vnet.net
- Subject: [mg12161] Re: [mg12082] Plotting w/o artifacts at discontinuities
- From: Bob Hanlon <BobHanlon@aol.com>
- Date: Mon, 27 Apr 1998 01:46:45 -0400
Try something like this. This won't work for every function, but it will handle simple expressions like your example. discPlot[func_, {x_, xmin_, xmax_}, opts___] := Module[{poles, ranges, nbr, p}, poles = x /. Solve[1/func == 0, x]; ranges = ({x, #1[[1]], #1[[2]]} & ) /@ Partition[Flatten[{xmin, Select[poles, xmin < #1 < xmax & ], xmax}], 2, 1]; nbr = Length[ranges]; Table[p[k] = Plot[func, Evaluate[ranges[[k]], opts], DisplayFunction -> Identity], {k, nbr}]; Show[Table[p[k], {k, nbr}], DisplayFunction -> $DisplayFunction]; ]; discPlot[1/((1 + x)*(x - 1)*(x - 1/2)), {x, -2, 1}, AxesLabel -> {"x", None}] discPlot[1/(x^2+3x+1), {x, -3, 0}] Bob Hanlon In a message dated 4/25/98 4:25:13 AM, bic@cgl.ucsf.EDU wrote: >I would like to be able to get plots that do not have artifacts from >discontinuities without having to know where the problem[s] will be in >advance. > >For example, I would like to be able to say > Plot[1/(1+x), {x,-2,1}] >and get a graph without the vertical line at x==-1. Though > p1=Plot[1/(1+x), {x,-2,-1}, DisplayFunction->Identity]; > p2=Plot[1/(1+x), {x,-1,1}, DisplayFunction->Identity]; > Show[p1,p2, DisplayFunction->$DisplayFunction]; does the trick, it >requires my anticipation of the problem at x==1.