Re: [Q] Plotting non-continuous function
- To: mathgroup at smc.vnet.net
- Subject: [mg4618] Re: [Q] Plotting non-continuous function
- From: Allan Hayes <hay at haystack.demon.co.uk>
- Date: Wed, 21 Aug 1996 03:25:34 -0400
- Sender: owner-wri-mathgroup at wolfram.com
pherron at GSB-Pound.Stanford.EDU (Michael C. Herron) article <4s4itn$9ud at dragonfly.wolfram.com> wants, amongst other things, to remove vertical asymptotes in Plot. Michael: Here is a way that does this automatically, usage::PlotNV[f,r] = "PlotNV[f,r] gives Plot[f,r] with all segments giving an apparent absolute slope greater than 100 removed.\n, PlotNV[f,r,ms] gives Plot[f,r] with all segments giving an apparent absolute,slope greater than ms removed.\n All the options for Plot may be used." METHOD The method is to split all lines Line[{p,q,r,s, ....}] into a list of segmets {Line[{p,q}], Line[{q,r}], ...} and delete those segments giving "too big a slope". The complication is to decide what "too big a slope" means. I have taken it to mean that its slope looks to be greater than 100 (in the default case). I have also kept PlotRange unaffected by any deletions . CODE PlotNV[f_,r_List,ms:(_?NumberQ):100,o___?OptionQ]:= Block[{pl,pr,rr,ar}, Show[ Block[{$DisplayFunction = Identity}, pl = Plot[f,r,o]; {pr,ar} = FullOptions[pl, {PlotRange, AspectRatio}]; rr = Divide@@Subtract@@Transpose[pr]; DeleteCases[ pl/.Line[p_]:> Partition[p,2,1,Composition[Line,List]], Line[{a_,b_}]/;Abs[1/Divide@@(a-b)] rr ar >ms, Infinity ] ], PlotRange -> pr ] ] EXAMPLES PlotNV[Tan[x],{x,0,7},PlotStyle -> Hue[0]] f[x_] := Which [x<=5,2,True,10] PlotNV[f[x], {x,0,20}, PlotRange -> {-2,10}] Allan Hayes hay at haystack.demon.co.uk ==== [MESSAGE SEPARATOR] ====