0
$\begingroup$

I have a plot and I have customized its legend; I want to place the legend top horizontal. How to do that?

I have tried placing it as follows, but it is not working.

style1 = PlotStyle -> {Black, Thickness[0.004], 
    AbsoluteDashing[{2, 7}]};
style2 = PlotStyle -> {Black, Thickness[0.004], 
    AbsoluteDashing[{8, 20}]};
style3 = PlotStyle -> {Black, Thickness[0.004], 
    AbsoluteDashing[{4, 18, 40}]};
style4 = PlotStyle -> {"LineColor" -> None};

legend = LineLegend[
   Directive[#2] & @@@ {style1, style2, style3, style4}, {Text[
     Style["\!\(\*SubscriptBox[\(β\), \(1\)]\),", 40]], 
    Text[Style["\!\(\*SubscriptBox[\(β\), \(2\)]\),", 40]], 
    Text[Style["\!\(\*SubscriptBox[\(β\), \(2\)]\),", 40]], 
    Text[Style["FEM", 40]]}, LegendLayout -> {"Row", 1}, 
   LegendMarkers -> {None, None, None, {"○", 40}}];

fig = ListLogLinearPlot[
   Select[RandomReal[{0, π}, {5000, 2}], 
    IntervalMemberQ[Interval[Sort[eqns[First@#]]], Last@#] &], 
   PlotStyle -> Darker@Green, Frame -> True];
fig = Legended[fig, Placed[legend, Above]];
fig = Style[fig, GraphicsBoxOptions -> {ImageSize -> 1000}]
$\endgroup$
4
  • $\begingroup$ won't something like PlotLegends -> Placed[legend, {.5, .9}] inside the ListLogLinearPlot work? $\endgroup$
    – Rupesh
    Commented Jun 15, 2020 at 12:45
  • $\begingroup$ @Rupesh Only texts are coming but lines are not coming, instead of lines black dots are appearing $\endgroup$
    – acoustics
    Commented Jun 15, 2020 at 12:59
  • $\begingroup$ Please provide the definitions for eqns so the problem can be reproduced. $\endgroup$ Commented Jun 15, 2020 at 14:51
  • $\begingroup$ "but this is not working" - please be specific as to what is not working, or include a picture of the output. Unless there is an obvious flaw in the output, we cannot guess what you would consider a good result, and you do not provide full definitions to run your code. $\endgroup$
    – MarcoB
    Commented Jun 15, 2020 at 16:19

1 Answer 1

1
$\begingroup$

As Rupesh suggested

{style1, style2, style3} =
  {Black, Thickness[0.004], AbsoluteDashing[#]} & /@
   {{2, 7}, {8, 20}, {4, 18, 40}};
style4 = {Black};

legend = LineLegend[
   Directive @@@ {style1, style2, style3, style4},
   Text[Style[#, 40]] & /@
    {Subscript[β, 1], Subscript[β, 2], Subscript[β, 2], "FEM"},
   LegendLayout -> {"Row", 1},
   LegendMarkers -> {None, None, None, {"○", 40}}];

SeedRandom[2]

fig =
 ListLogLinearPlot[
  Sort /@ RandomReal[{0, π}, {4, 5, 2}],
  PlotStyle -> Directive @@@ {style1, style2, style3, style4},
  PlotMarkers -> {None, None, None, {"○", 40}},
  Joined -> {True, True, True, False},
  Frame -> True,
  ImageSize -> 1000,
  PlotLegends -> Placed[legend, {.5, .95}]]

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.