Re: Dotted Lines at Discontinuities
- To: mathgroup at smc.vnet.net
- Subject: [mg73335] Re: Dotted Lines at Discontinuities
- From: Bob Hanlon <hanlonr at cox.net>
- Date: Tue, 13 Feb 2007 06:52:41 -0500 (EST)
- Reply-to: hanlonr at cox.net
I am not a professor/educator. Send your questions to MathGroup, not to me. Use a dummy function name temporarily. plotDisc[args___]:=Module[{p,temp}, p=(Plot[args,DisplayFunction->Identity]//. (Line[{s___,{x1_,y1_},{x2_,y2_},e___}]/; (Abs[(y2-y1)/(x2-x1)]>10||Sign[y1]!=Sign[y2])):> Sequence[Line[{s,{x1,y1}}], AbsoluteDashing[{5,5}],temp[{{x1,y1},{x2,y2}}], AbsoluteDashing[{}],Line[{{x2,y2},e}]])/.temp->Line; Show[p,DisplayFunction->$DisplayFunction]]; g=UnitStep[x-3]+UnitStep[x-5]-3UnitStep[x-6]; plotDisc[g,{x,0,10},PlotStyle->Red]; Bob Hanlon ---- Mr Ajit Sen <senra99 at yahoo.co.uk> wrote: > Dear Prof Hanlon, > > I refer to the nice code you posted in Mathgroup > (Sun 17 Sept 2006), whereby the vertical lines at > discontinuities are removed: > > plotDisc[args___] := Module[{p}, > p = Plot[args, DisplayFunction -> Identity] //. > (Line[{s___, {x1_, y1_}, {x2_, y2_}, > e___}]/; > (Abs[(y2-y1)/(x2-x1)] > 10^3 && > Sign[y1] != Sign[y2])):> > Sequence[Line[{s, {x1, y1}}], Line[{{x2, > y2}, e}]]; > Show[p, DisplayFunction -> $DisplayFunction]]; > > My problem is I'd like to have them in, but as > dotted lines instead. At the moment I'm using your > code with some slight modifications (e.g. 10 instead > of 10^3, || instead of && ) and then include the > dotted lines one by one. Thus for the function > > g = UnitStep[x - 3] + UnitStep[x - 5] - > 3UnitStep[x - 6] , > > I am doing it as follows : > > p=plotDisc[g,{x,0,10}] > p1=Graphics[{Red, AbsoluteDashing[{5,10}], > Line[{{3,0},{3,1}}]}] > p2=Graphics[{Red, AbsoluteDashing[{5,10}], > Line[{{5,1},{5,2}}]}] > p3=Graphics[{Red, AbsoluteDashing[{5,10}], > Line[{{6,2},{6,-1}}]}] > > Show[p,p1,p2,p3] > > This works fine but I think there should be a neater > way to go about it for arbitrary discontinuous > functions. I tried to put > > Graphics[{Red, AbsoluteDashing[{5,10}], > Line[{{x1,y1},{x1,y2}}]}] > > before the last line in your code, but that just > didn't work ! > > I would be most grateful if you could please help me > out on this. > > Thank you very much in advance. > > Ajit Sen.