0
$\begingroup$

I want to put a point in the legend, which is the easiest way?

My code is:

Plot[x^2, {x, 0, 2}, 
 Epilog -> {Directive[Red, PointSize[Large]], Point[{1, 1}]}, 
 PlotLegends -> {"x^2"}]

This gives me the legend of the parabola but if I add another entry it does not print the point in the legend. What should I add?

Thanks so much in advance

$\endgroup$
3
  • $\begingroup$ Legended[Plot[x^2, {x, 0, 2}, Epilog -> {Directive[Red, PointSize[Large]], Point[{1, 1}]}, PlotLegends -> {"x^2"}], PointLegend[{Red}, {{1, 1}}]] $\endgroup$
    – Bob Hanlon
    Commented Nov 7, 2022 at 20:08
  • $\begingroup$ Are you wanting one legend entry that is a blue line with a red dot in it or are you wanting two legend entries, one that is a blue line and one that is a red dot? $\endgroup$ Commented Nov 7, 2022 at 21:21
  • 1
    $\begingroup$ I want two items in the legend, a blue line and a dot. So 2 legend entries. I triesd @BobHanlon suggestion and it works but if you have a bit of text the point is not placed in the mid of the blue line in the legend. I would like to have a result like in Matlab where everything is aligned $\endgroup$ Commented Nov 7, 2022 at 21:40

2 Answers 2

1
$\begingroup$
plot1 = Plot[x^2, {x, 0, 2}, PlotLegends -> {"x^2"}];
plot2 = ListPlot[{{1, 1}}, PlotStyle -> Red, 
   PlotLegends -> {"A Red Dot"}];
Show[plot1, plot2]

enter image description here

$\endgroup$
0
$\begingroup$

Epilog puts graphics primitives after the plot is drawn. The legend has to be put together manually.

Plot[x^2, {x, 0, 2}
 , Frame -> True
 , ImageSize -> 400
 , Epilog -> {AbsolutePointSize[6], Red, Point@{1, 1}}, 
 PlotLegends -> Placed[LineLegend[{Blue, Blue}
    , {"\!\(\*SuperscriptBox[\(x\), \(2\)]\)", "Red dot"}
    , LegendLayout -> {"Column", 1}
    (*,LegendFunction\[Rule](Framed[#
    ,Background\[Rule]GrayLevel[0.9]
    ,RoundingRadius\[Rule]4]&)*)
    , LegendMarkers -> {"",
      Graphics[{Red, Disk[]}]}], {1, 0.5}]]

enter image description here

$\endgroup$

Your Answer

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

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