3
$\begingroup$

Faced the problem. Here is code:

data = Sort[
Sin[(b - a)*RandomVariate[UniformDistribution[{0, 1}], n] + a]];
ScriptCapitalD = EmpiricalDistribution[data];
Plot[CDF[ScriptCapitalD, x], {x, 0, 1}, PlotStyle -> Orange, ExclusionsStyle -> {Dashed}]

And it plots this: enter image description here

How can i add points on the leftside of each peace of it? Here is example of what i want:enter image description here

Could you please help me? Thanks. Sorry for my english.

$\endgroup$
5
$\begingroup$

Perhaps you could add point to each line segment after the plot is generated:

SeedRandom[4];
data = Sort[Sin[2*RandomVariate[UniformDistribution[{0, 1}], 12] + 0]];
ScriptCapitalD = EmpiricalDistribution[data];
Plot[CDF[ScriptCapitalD, x], {x, 0, 1}, PlotStyle -> Orange, 
  ExclusionsStyle -> None, Frame -> True] /. 
 Line[p_] :> {PointSize[0.015], Point[First@p], Line[p]}

Mathematica graphics

$\endgroup$
  • $\begingroup$ Thanks a lot, but look: i.imgur.com/D12kb8n.png Is it bug or i have to fix it? I mean, it should go up to point (1, 1). $\endgroup$ – instajke May 13 '15 at 20:00
  • $\begingroup$ And one more question: how can i add horizontal lines [y = 0, {x, -Inf, 0}] and [y = 1, {x, 1, +Inf}]? $\endgroup$ – instajke May 13 '15 at 20:08
  • $\begingroup$ @instajke The same issue came up here earlier today: mathematica.stackexchange.com/q/83375 - The simplest fix is to make the plot domain {x, 0, 1.001} and perhaps set PlotRange -> All. $\endgroup$ – Michael E2 May 13 '15 at 20:09
  • $\begingroup$ @Micahel E2, i meant this: i.imgur.com/5G78tqt.png $\endgroup$ – instajke May 13 '15 at 20:16
  • $\begingroup$ @instajke Like this?: Show[Plot[CDF[ScriptCapitalD, x], {x, -1, 2}, PlotStyle -> Orange, ExclusionsStyle -> None, Frame -> True] /. Line[p_] :> {PointSize[0.015], Point[First@p], Line[p]}, PlotRange -> {{-0.02, 1.02}, All}] -- Plot more than you need and then chop it off with Show using a restricted PlotRange. It gets rid of the dot at the origin, which I assumed you wanted. $\endgroup$ – Michael E2 May 13 '15 at 20:22
6
$\begingroup$
SeedRandom[123]
n = 15; a = 0; b = 2;
data = Sort[Sin[RandomVariate[UniformDistribution[{a, b}], n]]];

Yo can also specify the PlotStyle setting to add Point primitives to Lines:

Plot[CDF[EmpiricalDistribution[data], y], {y, 0, 1}, Filling -> None, 
 PlotStyle -> ({Orange, Thick, #, PointSize[.0125], 
     Point[#[[1]]] & @@ #} &), ImageSize -> 500, PlotRange -> {0, 1}]

Mathematica graphics

You can also use, perhaps more transparently, PlotStyle -> ({Orange, Thick, #, PointSize[.0125], # /. Line -> Composition[Point, First]} &).

Alternatively,

Plot[CDF[EmpiricalDistribution[data], y], {y, 0, 1}, Filling -> None, 
 PlotStyle -> ({Orange, Thick, #, PointSize[.0125], 
     Point[#[[1]]] & @@ #, PointSize[.005], White, 
     Point[#[[1]]] & @@ #} &), ImageSize -> 500, PlotRange -> {0, 1}]

Mathematica graphics

See also: 1, 2, 3, 4, and 5 for additional examples.

$\endgroup$
  • 1
    $\begingroup$ That is great. I've often wanted PlotStyle to accept a function, but have never seen it in the docs. That should be better known. Is there a guide to usage somewhere? Does it work on 3D plots? (+1) $\endgroup$ – Michael E2 May 13 '15 at 20:14
  • 1
    $\begingroup$ @MichaelE2, it is not in docs. My discovery of it was a pure accident -- wishful thinking ("wouldn't it be great if something worked this way") -> try a few cases -> pleasantly surprised that in some cases it does work:) It does not work in all cases one would wish it to work. It appeared in several posts on this site over the last few years (I think the earliest is in an answer by Simon Woods or rcollyer) . I will dig up the links and add to the post. $\endgroup$ – kglr May 13 '15 at 20:29
  • $\begingroup$ Maybe it could be added here: mathematica.stackexchange.com/q/809 $\endgroup$ – Michael E2 May 13 '15 at 20:48
  • $\begingroup$ @MichaelE2, I put the relevant links I could find there. $\endgroup$ – kglr May 13 '15 at 22:23

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.