1
$\begingroup$
Plot[Floor[Sin[x]], {x, -Pi, Pi}, PlotLabel -> Floor[Sin[x]],  Frame -> True, GridLines -> Automatic,  GridLinesStyle -> Directive[LightGray, Dashed],  FrameTicks -> {Automatic, {Table[x, {x, {-Pi, 0, Pi}}], None}},  ExclusionsStyle -> {Dotted, Red}, PlotRange -> {{-Pi, Pi}, {-1, 1}}]

which gives enter image description here

While I expect something like this, espeacially when x=Pi/2, for example, should be 1.

enter image description here

$\endgroup$
2
$\begingroup$

It misses it due to sampling. You can see this by asking to explicitly sample Pi/2

Plot[Floor[Sin[x]], {x, -Pi, Pi},
 PlotPoints -> {50, {Pi/2}},
 PlotLabel -> Floor[Sin[x]],
 Frame -> True,
 GridLines -> Automatic,
 GridLinesStyle -> Directive[LightGray, Dashed],
 FrameTicks -> {Automatic, {Table[x, {x, {-Pi, 0, Pi}}], None}},
 ExclusionsStyle -> {Dotted, Red},
 PlotRange -> {{-Pi, Pi}, {-1, 1.1}}]

Mathematica graphics

Just adding more sample points did not help, it kept missing Pi/2. One way around this is to make 2 plots and use Show

f[x_] := If[Mod[x, Pi/2] != 0, Null, Sin[x]]
data = Table[{x, f[x]}, {x, -Pi, Pi, Pi/10}];
p1 = ListPlot[data, PlotStyle -> Red];

p2 = Plot[Floor[Sin[x]], {x, -Pi, Pi},
   PlotLabel -> Floor[Sin[x]],
   Frame -> True,
   GridLines -> Automatic,
   GridLinesStyle -> Directive[LightGray, Dashed],
   FrameTicks -> {Automatic, {Range[-Pi, Pi, Pi/2], None}},
   ExclusionsStyle -> {Dotted, Red},
   PlotRange -> {{-Pi, Pi}, {-1, 1.1}}];
Show[p2, p1]

Mathematica graphics

May be there is a better way without using 2 plots, but I could not figure it out.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.