Question: How to avoid vertical asymptotes when plotting a piecewise?

I need to plot this piecewise function

Maple plots it correctly but its sampling seems to use the points between and hence it also shows vertical asymptotes, like this

Is there a way to tell plot not to show the vertical asymtotes? These should not show. Here is the same exact function in Mathematica, and this is what I want in Maple

f[x_] := Piecewise[{
   {2*x - Tan[x], -7/4*Pi < x < -3/2*Pi},
   {2*x - Tan[x], -3/2*Pi < x < -5/4*Pi},
   {2*x - Tan[x], -3/4*Pi < x < -1/2*Pi},
   {2*x - Tan[x], -1/2*Pi < x < -1/4*Pi},
   {2*x - Tan[x], 1/4*Pi < x < 1/2*Pi},
   {2*x - Tan[x], 1/2*Pi < x < 3/4*Pi},
   {2*x - Tan[x], 5/4*Pi < x < 3/2*Pi},
   {2*x - Tan[x], 3/2*Pi < x < 7/4*Pi},
   {True, None}}]

Plot[f[x], {x, -2 Pi, 2 Pi}]

 

Here is Maple worksheet with all the maple code. I tried adding 'adaptive'=true,'discont'=true but these made no difference.

f_decreasing := x -> piecewise(-7/4*Pi < x and x < -3/2*Pi, 2*x - tan(x), -3/2*Pi < x and x < -5/4*Pi, 2*x - tan(x), -3/4*Pi < x and x < -1/2*Pi, 2*x - tan(x), -1/2*Pi < x and x < -1/4*Pi, 2*x - tan(x), 1/4*Pi < x and x < 1/2*Pi, 2*x - tan(x), 1/2*Pi < x and x < 3/4*Pi, 2*x - tan(x), 5/4*Pi < x and x < 3/2*Pi, 2*x - tan(x), 3/2*Pi < x and x < 7/4*Pi, 2*x - tan(x),true,[])

f_decreasing := proc (x) options operator, arrow; piecewise(-(7/4)*Pi < x and x < -(3/2)*Pi, 2*x-tan(x), -(3/2)*Pi < x and x < -(5/4)*Pi, 2*x-tan(x), -(3/4)*Pi < x and x < -(1/2)*Pi, 2*x-tan(x), -(1/2)*Pi < x and x < -(1/4)*Pi, 2*x-tan(x), (1/4)*Pi < x and x < (1/2)*Pi, 2*x-tan(x), (1/2)*Pi < x and x < (3/4)*Pi, 2*x-tan(x), (5/4)*Pi < x and x < (3/2)*Pi, 2*x-tan(x), (3/2)*Pi < x and x < (7/4)*Pi, 2*x-tan(x), true, []) end proc

plot(f_decreasing(x),x=-2*Pi..2*Pi,'adaptive'=true,'discont'=true,'color'="blue");

 

 

Download plot_piecewise_march_25_2026.mw

Please Wait...