3

So, I got this code:

Plot[Piecewise[{{3, x <= 0}, {x^2 + 1, x > 0}}], {x, -2, 2}, 
 PlotStyle -> {Purple}, Axes -> False, Frame -> True]

and I want to add full dot at 0 from the left and partial at 0 from the right. I hope you know what I mean. Thank you.

Janukalado
  • 33
  • 3

3 Answers3

4

You can construct the desired marker using Disk and Circle:

halfdisk[color1_, color2_: White] := {Thickness[0.1], 
   EdgeForm[color1], color2,  Disk[{0, 0}, 1],
   color1, Disk[{0, 0}, 1, {π/2, -(π/2)}], Circle[{0, 0}]};

and use it with Inset as Epilog option in Plot:

epilog = {Inset[Graphics@halfdisk[Purple, Purple], {0, 1}, Automatic, Scaled[.05]],
      Inset[Graphics@halfdisk[Purple], {0, 3}, Automatic, Scaled[.05]]};

Plot[Piecewise[{{3, x <= 0}, {x^2 + 1, x > 0}}], {x, -2, 2}, 
  PlotStyle -> Purple, Axes -> False, Frame -> True, 
  Epilog -> epilog]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
2

Something like this?

f[x_] := Piecewise[{{3, x <= 0}, {x^2 + 1, x > 0}}]
rval = Limit[f[x], x -> 0, Direction -> -1];
Plot[
 f[x],
 {x, -2, 2},
 PlotStyle -> {Purple},
 Axes -> False,
 Frame -> True,
 Epilog -> {
   {PointSize[0.03], Purple, Point@{0, f[0]}},
   {PointSize[0.03], Purple, Point@{0, rval}},
   {White, PointSize[0.02], Point@{0, rval}}
 }
]

enter image description here

NonDairyNeutrino
  • 7,810
  • 1
  • 14
  • 29
0
fn = Piecewise[{{3, x <= 0}, {x^2 + 1, x > 0}}];

p1 = Plot[fn, {x, -2, 2}, PlotStyle -> {Purple}, Axes -> False, Frame -> True];

p2 = ListPlot[{{0, Limit[fn, x -> 0, Direction -> #]}} & /@ {1, -1}, PlotStyle -> Purple,
     PlotMarkers -> (Graphics[#, ImageSize -> 10] & /@ {Disk[{0, 0}, 1], DiskSegment[{0, 0}, 1, {Pi/2, 3 Pi/2}]} )];

Show[p1, p2]

enter image description here

Suba Thomas
  • 8,716
  • 1
  • 17
  • 32