2
$\begingroup$

I have the following example code and would like to make the lines in the legend longer - how can that be done?

Is there another possibility to plot such a legend when using Show?

Needs["PlotLegends`"];
SeedRandom[314];
data1 = RandomReal[10000, 100];
data2 = RandomReal[10000, 100];
plot1 = ListLogLogPlot[data1, PlotStyle -> {Red}, Joined -> True, 
   PlotRange -> Full];
plot2 = ListLogLogPlot[data2, PlotStyle -> {Green}, Joined -> True, 
   PlotRange -> Full];

ShowLegend[
 Show[plot1, plot2, Frame -> True, 
  FrameLabel -> {{"data1,data2", ""}, {"x", ""}}, 
  BaseStyle -> {FontWeight -> "Bold", FontSize -> 20, 
    FontFamily -> "Calibri"}, ImageSize -> 800, 
  ImagePadding -> {{All, All}, {All, 
     50}}], {{{Graphics@{Red, Line[{{0, 0}, {0.9, 0}}]}, 
    "data1"}, {Graphics@{Green, Line[{{0, 0}, {0.9, 0}}]}, "data2"}}, 
  LegendPosition -> {-0.7, -0.4}, LegendSize -> {0.2, 0.1}, 
  LegendShadow -> None, LegendTextSpace -> 10, 
  BaseStyle -> {FontWeight -> "Bold", FontSize -> 10, 
    FontFamily -> "Calibri"}}]

enter image description here

$\endgroup$
  • $\begingroup$ I am confused though, you put the line lengths into the code by hand with this method. If you change the two spots where you write Line[{{0, 0}, {0.9, 0}}] to Line[{{0, 0}, {4, 0}}] then the lines are longer. $\endgroup$ – Jason B. Apr 6 '16 at 12:53
  • $\begingroup$ somehow in my case it does not work (MMA 10.4.0 64bit, Win 10 Pro 64bit) $\endgroup$ – mrz Apr 6 '16 at 15:26
4
$\begingroup$

Okay, so the mantra around here is "Don't use the PlotLegends package."
Keep repeating that until you can resist the urge.

Here I'll just use Inset to place a LineLegend inside the frame, and I'll use the options for LineLegend to make the lines ridiculously long for example,

Show[plot1, 
 plot2,
  Frame -> True, 
   FrameLabel -> {{"data1,data2", ""}, {"x", ""}}, 
   BaseStyle -> {FontWeight -> "Bold", FontSize -> 20, 
       FontFamily -> "Calibri"},
  ImageSize -> 800, 
   ImagePadding -> {{All, All}, {All,  50}},
 Epilog -> Inset[
   LineLegend[{Red, Green}, {"data1", "data2"}, 
    LegendFunction -> Framed, LegendMarkerSize -> {100, 10}],
   Scaled[{.2, .2}]]]

enter image description here

$\endgroup$
  • $\begingroup$ Perfect ... thank you $\endgroup$ – mrz Apr 6 '16 at 12:59

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.