Combining legends in mathematica Grid[]

Viewed 144

I am trying to plot 2 figures that both share identical legends in a grid in Mathematical. Here is an example of the code:

Grid[{{Plot[{x + 1, 2 x + 1}, {x, 0, 10}, 
PlotStyle -> {{RGBColor[0.880722, 0.611041, 0.142051], 
   Dashed}, {RGBColor[0.880722, 0.611041, 0.142051], colors}}, 
PlotLegends -> {a, b}, ImageSize -> 400]},
{Plot[{-x + 10, -2 x + 10}, {x, 0, 10}, 
PlotStyle -> {{RGBColor[0.880722, 0.611041, 0.142051], 
   Dashed}, {RGBColor[0.880722, 0.611041, 0.142051], colors}}, 
PlotLegends -> {a, b}, ImageSize -> 400]}}]

code output

I want to only have one legend, instead of two yet I can't find a clean way to do it with legend since there is a dashed line.

1 Answers

Also added ImagePadding to align the y axes.

Legended[
 Grid[{{Plot[{x + 1, 2 x + 1}, {x, 0, 10},
     PlotStyle -> {{RGBColor[0.880722, 0.611041, 0.142051],
        Dashed}, {RGBColor[0.880722, 0.611041, 0.142051], colors}},
     ImageSize -> 400,
     ImagePadding -> {{14, Automatic}, {Automatic, Automatic}}]},
   {Plot[{-x + 10, -2 x + 10}, {x, 0, 10}, 
     PlotStyle -> {{RGBColor[0.880722, 0.611041, 0.142051],
        Dashed}, {RGBColor[0.880722, 0.611041, 0.142051], colors}},
     ImageSize -> 400,
     ImagePadding -> {{14, Automatic}, {Automatic, Automatic}}]}}],
 Placed[LineLegend[{{RGBColor[0.880722, 0.611041, 0.142051],
     Dashed}, RGBColor[0.880722, 0.611041, 0.142051]}, {a, b}], Below]]
Related