4
$\begingroup$

This question already has an answer here:

I wanted to plot a function involving Floor, here is my code:

epsilon = 0.1;
f[t_] = Floor[t/epsilon];
Plot[{f[t]}, {t, 0, 5}]

it gives me the following, which has smaller bars as t increases: enter image description here

I know that I can plot Floor with DiscretePlot, as suggested here, but I would like to understand, why Plot cannot handle it correctly. Thanks!

$\endgroup$

marked as duplicate by Mr.Wizard Apr 15 '15 at 16:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

4
$\begingroup$

You need to specify more PlotPoints

epsilon = 0.1;
f[t_] = Floor[t/epsilon];

Plot[{f[t]}, {t, 0, 5},
 PlotPoints -> 250,
 ImageSize -> 500]

enter image description here

epsilon = 0.5;
f[t_] = Floor[t/epsilon];

Plot[{f[t]}, {t, 0, 5},
 ColorFunction -> "Rainbow",
 PlotPoints -> 250,
 PlotStyle -> Thickness[0.01],
 PlotTheme -> "Detailed",
 ImageSize -> 500]

enter image description here

epsilon = 0.5;
f[t_] = Floor[t/epsilon];

Plot[{f[t]}, {t, 0, 5},
 Filling -> Axis,
 Frame -> True,
 FrameTicks -> {{All, None}, {Range[0, 5, 0.5], None}},
 GridLines -> {Range[0, 5, 0.5], Range[0, 10, 1]},
 PlotPoints -> 250,
 PlotStyle -> Thickness[0.001],
 ImageSize -> 500]

enter image description here

$\endgroup$
  • $\begingroup$ thanks, that solves the problem. but do you have an intuitive understanding why mathematica decides to make the bars smaller? So, why does it work better for small t as for large t? $\endgroup$ – NicoDean Oct 5 '14 at 16:57
  • $\begingroup$ @NicoDean I don't understand it either. With too few PlotPoints you just get unpredictable results. I don't even see a pattern "within" this unpredictability. $\endgroup$ – eldo Oct 5 '14 at 17:13
  • 2
    $\begingroup$ The bar length is determined by where the adaptive sampling for Plot selects the plot points. This is affected by the initial sampling points set by the option PlotPoints. $\endgroup$ – Bob Hanlon Oct 5 '14 at 19:26

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