0
$\begingroup$

I have a plot as below:-

lg1 = {GraphicsRow[{Blue, "- Type A"}], GraphicsRow[{Orange, "- Type B"}]};
plot1 = ListPlot[{{{4, 1}, {3, 6}, {3, 4}}, {{4, 7}, {8, 5}, {2, 6}}}, PlotRange -> All];
Legended[plot1, lg1]

enter image description here

As you can see, the legend is very "loose". I want to to be more compact. In fact I can change lg1 to lg1 = Column@{"Blue - Type A", "Orange - Type B"}, but then the color will become text as below:-

enter image description here

How can I keep the color and make it more compact? Many thanks!

$\endgroup$
  • 1
    $\begingroup$ Use an option from within ListPlot such as: ListPlot[{{{4, 1}, {3, 6}, {3, 4}}, {{4, 7}, {8, 5}, {2, 6}}}, PlotRange -> All, PlotLegends -> {"Type A", "Type B"}] $\endgroup$ – bobthechemist Jul 6 '18 at 23:09
  • $\begingroup$ Thanks for reply. But for this case, Legended is needed to be at the outer most layer. In my real case, there is a show between the Legended and the plots (there are several plots), and the legend needs to be dynamic as well. Thus the Legended cannot just be input as a plot option. $\endgroup$ – H42 Jul 6 '18 at 23:15
3
$\begingroup$

GraphicsRow is introducing lots of space. If you're going to construct the legend manually, I suggest using Row instead, which gives a much more compact result:

lg1 = {Row[{Blue, "- Type A"}], Row[{Orange, "- Type B"}]};
plot1 = ListPlot[{{{4, 1}, {3, 6}, {3, 4}}, {{4, 7}, {8, 5}, {2, 6}}},
    PlotRange -> All];
Legended[plot1, lg1]

enter image description here

Also, the use of Show shouldn't necessarily be an issue for Legended or PlotLegends. The dynamics might not either, but it may depend on what your specific usage is.

$\endgroup$
1
$\begingroup$
Row[{ListPlot[{{{4, 1}, {3, 6}, {3, 4}}, {{4, 7}, {8, 5}, {2, 6}}}, 
   PlotRange -> All], 
  Grid[{{Blue, "- Type A"}, {Orange, "- Type B"}}]}]

fig1

$\endgroup$

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.