6
$\begingroup$

I am using PlotLegends in a Plot command to label each line of my plot (it has 4 different functions plotted) but the legend is split in two lines. I would like it two appear in a single line so it has the same appearance as the other plots displayed next to it. Is there a way to do that? I guess reducing the font size would be an option but I don't know how to do it.

I don't know if this is relevant, but afterwards I export the plot to an EPS file using the command

Export["swp_c0.eps", c0plt] 

so maybe increasing the resolution might solve my problem.

UPDATE

I reduced the font size and still couldn't get it in one line. However, when I changed my legend labels from scientific notation (10^-2, using the -2 as a superscript) to fixed point notation (0.01) it worked (with the reduced font size). Here there is the final result so I managed to get it working. However, I would like, if possible, to understand what was the problem.

Plot how I want it (using fixed point notation).

$\endgroup$
3
  • $\begingroup$ PlotLegends -> LineLegend["Expressions", LegendLayout -> "Row"] ? $\endgroup$ Commented Mar 15, 2016 at 18:22
  • 1
    $\begingroup$ It doesn't work. Using "Column" displays them as a column but using "Row" doesn't change anything. $\endgroup$ Commented Mar 15, 2016 at 18:27
  • $\begingroup$ Can you post more details... maybe your plot as is $\endgroup$ Commented Mar 15, 2016 at 18:28

2 Answers 2

11
$\begingroup$

You can use the option setting LegendLayout -> {"Row", 1} inside LineLegend to have all legends in a single row:

Plot[Evaluate[Sin[# x] & /@ Range[7]], {x, 0, 2 Pi}, PlotLegends -> Placed[LineLegend["Expressions", LegendLayout -> {"Row", 1}], Above]] 

enter image description here

Or, use a custom function as the setting for this option to organize legends in a Grid with a single row:

Plot[Evaluate[Sin[# x] & /@ Range[7]], {x, 0, 2 Pi}, PlotLegends -> Placed[LineLegend["Expressions", LegendLayout -> (Grid[{Flatten@Riffle[#, Spacer[3]]}] &)], Above]] 

Mathematica graphics

$\endgroup$
1
$\begingroup$

Place the legends Above | Top or Below | Bottom, e.g.,

Plot[{Sin[x], Cos[x]}, {x, 0, 2 Pi}, PlotLegends -> Placed["Expressions", Above]] 

enter image description here

$\endgroup$
1
  • $\begingroup$ If you run InputForm@Plot[...][[2]], you'll notice that this sets LegendLayout -> "Row". :) $\endgroup$ Commented Mar 15, 2016 at 18:51

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.