I would like to place the legend inside the plot frame. I have been doing a search in the documentation but only found option

ChartLegends -> Placed[{"label", {Center}]

Other options, such as Up, Bottom, Right, place the label outside.

How can I put the legend inside the frame of the plot?

  • $\begingroup$ You refer to "plot" but the only code provided applies to a "chart". You might want to clarify what you are actually trying to accomplish. $\endgroup$
    – Bob Hanlon
    Apr 3 '17 at 19:07
 BarChart[{{4, 5, 6}, {1, 2, 3}},
  ChartStyle -> {"Pastel", None}],
   ColorData["Pastel", #] & /@ {0, 1},
   {"Group A", "Group B"}],
  {0.8, 0.8}]]

enter image description here

EDIT: More simply,

BarChart[{{4, 5, 6}, {1, 2, 3}},
 ChartStyle -> {"Pastel", None},
 ChartLegends -> Placed[
   {{"Group A", "Group B"}, None},
   {0.8, 0.8}]]

enter image description here

EDIT 2: Using SmoothHistogram

  RandomVariate[NormalDistribution[c, 1], 500],
  {c, 0, 5}],
 PlotLegends -> Placed[Range[0, 5], {0.9, 0.7}]]

enter image description here

  • $\begingroup$ Thank you very much for this solution. I also wanted to ask the same question but using PlotLegends option of SmoothHistogram. I have tried this solution but does not work with PlotLegends. Regards. $\endgroup$ Apr 3 '17 at 19:26
  • $\begingroup$ See EDIT 2. When asking a question, you need to post code for minimal working example that demonstrates issue that you are having. $\endgroup$
    – Bob Hanlon
    Apr 3 '17 at 19:52
  • 2
    $\begingroup$ Thank you, the solutions have solved this problem. I use PlotTheme -> "Scientific", ChartStyle -> 96, ChartBaseStyle -> Directive[EdgeForm[None], Opacity[0.25]]in the Histogram then I have put Placed[ SwatchLegend[96, {"No stigmergy", "FPS"}], {0.9, 0.8}]in my code but the color of the legend looks darker (intense) than the plot lines. Do you know how I could match both, plot lines and legend colors?. Thank you for your help. $\endgroup$ Apr 3 '17 at 22:24
  • $\begingroup$ @user1993416 - Post a new question that includes the actual data and code that you are using and the issue that you want resolved. $\endgroup$
    – Bob Hanlon
    Apr 3 '17 at 22:49

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.