9
$\begingroup$

How can I use this type of marker for this?

enter image description here

Plot[{x + 3, x^2 + 1}, {x, -5, 5}, PlotStyle -> Thickness[0.01],
 Epilog -> {Red, PointSize[0.03], Point[{2, 5}]}]

I would be nice if the colors are added automatically from the two curves.

enter image description here

$\endgroup$

3 Answers 3

12
$\begingroup$
f1[x_] := x + 3
f2[x_] := 1 + x^2

meshStyle = (# /. Point[x_] :> 
   Map[Inset[PieChart[{1, 1}, SectorOrigin -> Bottom], 
      #, Center,  Scaled[.1]] &, x] &);

Plot[{f1[x], f2[x]}, {x, -5, 5}, 
 PlotStyle -> Thickness[0.01], 
 MeshFunctions -> {f1[#] - f2[#] &}, 
 Mesh -> {{0}}, 
 MeshStyle -> meshStyle]

enter image description here

$\endgroup$
9
$\begingroup$
  • We can define PlotMarkers by any Graphics object and using ListPlot to add such markers of points.

  • We using MeshFunctions to get the intersection points of two curves.

  • The AspectRatio can be any ratio,here we set AspectRatio -> 1/2.

Clear[f, g, hemipoint, plot, indexes, meshs];
hemipoint = 
  Graphics[{{ColorData[97][1], 
     Disk[{0, 0}, 1, {π/2, 2 π - π/2}]}, {ColorData[97][
      2], Disk[{0, 0}, 1, {-π/2, π/2}]}}, ImageSize -> 20];
f[x_] = x + 3;
g[x_] = x^2 + 1;
plot = Plot[{f[x], g[x]}, {x, -5, 5}, PlotStyle -> Thickness[0.01], 
   Mesh -> {{0}}, MeshFunctions -> {f[#] - g[#] &}, MeshStyle -> None];
pts = Cases[plot, 
    GraphicsComplex[pts_, rest__] :> pts, ∞][[1]];
indexes = Cases[plot, Point[index_] :> index, ∞];
meshs = pts[[#]] & /@ indexes;
Show[plot, ListPlot[{meshs[[1, 2]]}, PlotMarkers -> hemipoint], 
 AspectRatio -> 1/2]

enter image description here

  • Define two types of PlotMarkers.
Clear[hemipoint1,hemipoint2,plot,indexes,meshs];
hemipoint1 = 
  Graphics[{{ColorData[97][1], 
     Disk[{0, 0}, 1, {π/2, 2 π - π/2}]}, {ColorData[97][
      2], Disk[{0, 0}, 1, {-π/2, π/2}]}}, ImageSize -> 20];
hemipoint2 = 
  Graphics[{{ColorData[97][2], 
     Disk[{0, 0}, 1, {π/2, 2 π - π/2}]}, {ColorData[97][
      1], Disk[{0, 0}, 1, {-π/2, π/2}]}}, ImageSize -> 20];
f[x_] = x + 3;
g[x_] = x^2 + 1;
plot = Plot[{f[x], g[x]}, {x, -5, 5}, PlotStyle -> Thickness[0.01], 
  Mesh -> {{0}}, MeshFunctions -> {f[#] - g[#] &}, MeshStyle -> None];
pts = Cases[plot, 
    GraphicsComplex[pts_, rest__] :> pts, ∞][[1]];
indexes = Cases[plot, Point[index_] :> index, ∞];
meshs = pts[[#]] & /@ indexes;
Show[plot, 
 ListPlot[{{meshs[[1, 2]]}, {meshs[[1, 1]]}}, 
  PlotMarkers -> {hemipoint1, hemipoint2}], AspectRatio -> 1/2]

enter image description here

$\endgroup$
7
$\begingroup$

It's not so easy to do this automatically, and you have to account for the aspect ratio of your plot, without which you end up with a squashed marker. Here's my attempt for manual points and colour selection:

marker[pos_, radius_, col1_, col2_] :=
 With[{d = Disk[pos, radius, {-Pi/2, Pi/2}]},
  {EdgeForm[Black], col1, d, col2, Rotate[d, Pi, pos]}]

xrange = {-5, 5};
yrange = {-5, 30};
aspect = Subtract @@ yrange/Subtract @@ xrange;
markerRadius = 0.3;
Plot[{x + 3, x^2 + 1}, {x, xrange[[1]], xrange[[2]]}, 
 PlotRange -> {xrange, yrange}, PlotStyle -> Thickness[0.01], 
 Epilog -> { 
   marker[{2, 5}, markerRadius*{1, aspect}, 
    RGBColor[0.368417`, 0.506779`, 0.709798`], 
    RGBColor[0.880722`, 0.611041`, 0.142051`]]}, AspectRatio -> 1]

plot marker

$\endgroup$
2
  • $\begingroup$ Thanks, it is much more complex than I though even without automatically adding colors. It works great but does not work when I use it like this Show[plot1, plot_with_marker]. How can I fix this? $\endgroup$
    – hana
    Jan 19 at 22:18
  • $\begingroup$ And how to make the marker circle even with any AspectRatio? $\endgroup$
    – hana
    Jan 19 at 22:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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