3
$\begingroup$

I want to design the plot legends independent of the plot style I use in ListLinePlot. So I do:

colors = ColorData[97, "ColorList"]; fontsize = 20; leg = LineLegend[{colors[[5]], {Black, Dotted}}, {Style["simulation", FontFamily -> Times, fontsize, SingleLetterItalics -> False], Style["experiment", FontFamily -> Times, fontsize, SingleLetterItalics -> False]}, Spacings -> {0.4, 0.08}, LegendLayout -> {"Column", 1}, LegendMarkerSize -> {22, 10}, LegendFunction -> (Framed[#, FrameStyle -> Directive[Black, Thickness[0.5]], RoundingRadius -> 5, Background -> White, FrameMargins -> -1] &)] 

This shows exactly what I am looking for but when I set the option Joined as False for a list in the ListLinePlot, the LineLegend changes automatically and insert a marker. Here is my setting for ListLinePlot:

plotbend = ListLinePlot[{Range[0, 10], Range[0, 10]}, PlotStyle -> {colors[[5]], {Dotted, Black}}, Frame -> True, AspectRatio -> 1.1, Joined -> {True, False}, PlotMarkers -> None, BaseStyle -> {FontFamily -> Times, FontSize -> fontsize}, FrameStyle -> Black, FrameLabel -> {Style[ "Normalized curvature, \!\(\*FractionBox[\(\[Kappa]\), \ SubscriptBox[\(\[Kappa]\), \(0\)]]\)", FontFamily -> Times, FontSize -> fontsize], Style["Normalized bending moment, \!\(\*FractionBox[\(M\), \ SubscriptBox[\(M\), \(0\)]]\)", FontFamily -> Times, FontSize -> fontsize]}, ImageSize -> 360, PlotLegends -> Placed[leg, {0.73, 0.14}]] 

Is it possible to make the LineLegend totally independent?

I am using Windows 10 and Mathematica 13.0.1.0.

$\endgroup$
4
  • $\begingroup$ What is colors[[5]]? And what $Version are you using? For my version 12.2.0, it shows Spacings in red color. $\endgroup$ Commented Mar 6, 2024 at 12:52
  • $\begingroup$ @Syed please see the edited post $\endgroup$ Commented Mar 6, 2024 at 12:58
  • 1
    $\begingroup$ use Legended[ListLinePlot[...], Placed[leg, {0.73, 0.14}]] $\endgroup$ Commented Mar 6, 2024 at 13:18
  • $\begingroup$ @kglr Thanks, that does the job. $\endgroup$ Commented Mar 6, 2024 at 13:37

2 Answers 2

6
$\begingroup$

You can use Legended:

Legended[First @ plotbend, Placed[leg, {0.73, 0.14}]] 

enter image description here

$\endgroup$
4
$\begingroup$

I am not sure that I have understood you correctly. If yes, I can propose a workaround. The idea is to add a third list Range[0, 10]. For the first two you specify Joint->True, for the third Joint->False. Further, you specify the legend for the first two, and Legend->None for the third. Try this:

colors = ColorData[97, "ColorList"]; fontsize = 20; leg = LineLegend[{colors[[5]], {Black, Dotted}}, {Style["simulation", FontFamily -> Times, fontsize, SingleLetterItalics -> False], Style["experiment", FontFamily -> Times, fontsize, SingleLetterItalics -> False], None}, Spacings -> {0.4, 0.08}, LegendLayout -> {"Column", 1}, LegendMarkerSize -> {22, 10}, LegendFunction -> (Framed[#, FrameStyle -> Directive[Black, Thickness[0.5]], RoundingRadius -> 5, Background -> White, FrameMargins -> -1] &)]; plotbend = ListLinePlot[{Range[0, 10], Range[0, 10], Range[0, 10]}, PlotStyle -> {colors[[5]], colors[[5]], {Dotted, Black}}, Frame -> True, AspectRatio -> 1.1, Joined -> {True, True, False}, PlotMarkers -> None, BaseStyle -> {FontFamily -> Times, FontSize -> fontsize}, FrameStyle -> Black, FrameLabel -> {Style[ "Normalized curvature, \!\(\*FractionBox[\(\[Kappa]\), \ SubscriptBox[\(\[Kappa]\), \(0\)]]\)", FontFamily -> Times, FontSize -> fontsize], Style["Normalized bending moment, \!\(\*FractionBox[\(M\), \ SubscriptBox[\(M\), \(0\)]]\)", FontFamily -> Times, FontSize -> fontsize]}, ImageSize -> 360, PlotLegends -> Placed[leg, {0.73, 0.14}]] 

returning the following:

enter image description here

Hope it helps.

$\endgroup$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.