# Why won't my function plot?

If I define

g[z_] := Which[
0 <= z <= 0.9,     5*(Min[0.1, z] - Max[0, z - 1]),
0.9 <= z <= 1.1,   5*(Min[0.1, z] - Max[0, z - 1]) + 5*(Min[1, z] - Max[0.9, z - 1]),
1.1 <= z <= 2,                                       5*(Min[1, z] - Max[0.9, z - 1]),
True,              0
]


and plot using

Plot[g[z], {z, 0, 2}]


I get

while if I plot using

ListPlot[{#, g[#]} & /@ (Range[1000]/500), PlotRange -> All, Joined -> True]


I get

which is what I expect.

Why does Plot fail to plot my function as expected?

-
Plot[g[z], {z, 0, 1.2}] looks fine. Weird... –  Silvia Mar 30 at 0:35
The probability tag is for questions involving probability functions in MMA, which didn't present here, thus IMO it's not a proper tag here. –  Silvia Mar 30 at 0:39
Options[Plot[g[z], {z, 0, 2}], PlotRange] returns PlotRange -> {{0., 2.}, {0.5, 0.5}} so it is shrinking the vertical range. Reporting it. –  rcollyer Mar 30 at 0:42
Plot[g[z], {z, 0, 2}, PlotRange -> Full] works also –  Nasser Mar 30 at 0:49
Or PlotRange -> All. But do consider Piecewise for mathematical expressions. Which is for programming. –  Szabolcs Mar 30 at 1:08

Plot[g[z], {z, 0, 2}, PlotRange -> {{0, 2}, All}]


-
Perfect. Should that have been obvious to me? Where is this stuff documented? –  raxacoricofallapatorius Mar 30 at 0:32
@raxacoricofallapatorius I don't think it's obvious. Actually I'd think this is a possible bug. +1 btw –  Silvia Mar 30 at 0:34
@Silvia: I'm glad it's not something I missed. Another one of those bugs. –  raxacoricofallapatorius Mar 30 at 0:35
In fact, Plot[g[z], {z, 0, 2}, PlotRange -> All] will work. I think it a bug, too. –  m_goldberg Mar 30 at 0:46