I use the following codes to define and plot three piecewise functions.
list1 = Join[
Table[{(j - 1)/2^1, (j - 1)/2^1 <= E^x < j/2^1}, {j, 1,
1*2^1}], {{1, E^x >= 1}}];
list2 = Join[
Table[{(j - 1)/2^2, (j - 1)/2^2 <= E^x < j/2^2}, {j, 1,
2*2^2}], {{2, E^x >= 2}}];
list3 = Join[
Table[{(j - 1)/2^3, (j - 1)/2^3 <= E^x < j/2^3}, {j, 1,
3*2^3}], {{3, E^x >= 3}}];
p1 = Piecewise[list1];
p2 = Piecewise[list2];
p3 = Piecewise[list3];
Plot[p1, {x, -3, 3}, AspectRatio -> Automatic]
Plot[p2, {x, -3, 3}, AspectRatio -> Automatic]
Plot[p3, {x, -3, 3}, AspectRatio -> Automatic]
p1 and p2 just come out fine, while p3 is messy, with end points of each horizontal lines connected by vertical lines.
Thank you!
Answer
Using @Rojo's answer to my question here you don't need to know a priori where the exclusions are:
plot = Plot[p3, {x, -3, 3}, PlotPoints -> 1000];
pp = With[{multiplier = {AspectRatio, PlotRange} /.
AbsoluteOptions[plot, {AspectRatio, PlotRange}] /. {ar_, pl_} :>
ar Divide @@ Subtract @@@ Reverse /@ pl},
(plot //.
Line[{a___, {x1_, y1_}, {x2_, y2_}, b___}] /;
Abs[(y1 - y2)/(x1 - x2)] > 10/multiplier :> {Line[{a, {x1, y1}}],
Line[{{x2, y2}, b}]})
];
Show[pp, AspectRatio -> Automatic]
Comments
Post a Comment