How can I use this type of marker for this?
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.
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityHow can I use this type of marker for this?
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.
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]
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]
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]
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]
Show[plot1, plot_with_marker]
. How can I fix this?
$\endgroup$