       Re: avoid spurious vertical segment in step function plot

• To: mathgroup at smc.vnet.net
• Subject: [mg23338] Re: avoid spurious vertical segment in step function plot
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Thu, 4 May 2000 02:59:08 -0400 (EDT)
• References: <8elmsq\$sie@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Murray,
Here is two ways based on Split.

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

gr = Plot[UnitStep[x], {x, -1, 1}, Frame -> True,
PlotRange -> {-.1, 1.1}, Axes -> False]

Show[DeleteVerticals[gr, 10]];

gr = Plot[UnitStep[x], {x, -1, 1}, Frame -> True,
PlotRange -> {-.1, 1.1}, Axes -> False];

We often need to experiment to avoid cutting out steep sections that we want
to retain (thought sometives the dotted forms can be useful)

gr = Plot[UnitStep[x], {x, -1, 1}, Frame -> True,
PlotRange -> {-.1, 1.1}, Axes -> False]

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

Show[DeleteVerticals[gr2, 100]];

Show[DeleteVerticals[gr2, 30000]];

Here is a version that uses peceived slope. I may be easier to use but it is
affected by chabges in the asspect ratio

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]];

Show[DeleteVerticals2[gr2, 200]];

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

"Murray Eisenberg" <murray at math.umass.edu> wrote in message
news:8elmsq\$sie at smc.vnet.net...
> Several packages available from MathSource deal with eliminating the
> spurious parts of plots of discontinuous functions across vertical
> asymptotes.
>
> Is there some simple way of dealing with the similar problem of
> eliminating the spurious vertical line segment in plotting a function
> with jumps -- for example, in the following?
>
>   Plot[UnitStep[x], {x, -1, 1}]
>
> --
> Murray Eisenberg                     murray at math.umass.edu
> Mathematics & Statistics Dept.       phone 413 549-1020 (H)
> Univ. of Massachusetts                     413 545-2859 (W)
> Amherst, MA 01003-4515
>

```

• Prev by Date: RE:
• Next by Date: Re: RE: [Q] Equation solving?
• Previous by thread: Re: avoid spurious vertical segment in step function plot
• Next by thread: RE: avoid spurious vertical segment in step function plot