13

Consider this example, taken from the docs and modified for a larger font size using Style (V10.0):

ListPlot[Table[f, {f, {Sin[x], Cos[x]}}, {x, 0, 2 π, 0.1}],
PlotLegends -> (Style[#, 40] & /@ {"sin(x)", "cos(x)"})]

Mathematica graphics

The plot markers are clearly aligned at the bottom of the legend text, which does not seem optimal.

Is there a way to influence this aligning?

kglr
  • 394,356
  • 18
  • 477
  • 896
Yves Klett
  • 15,383
  • 5
  • 57
  • 124

2 Answers2

15
ListPlot[Table[f, {f, {Sin[x], Cos[x]}}, {x, 0, 2 π, 0.1}],
PlotLegends ->PointLegend[ (Style[#, 40] & /@ {"sin(x)", "cos(x)"}),Alignment->Center]]

enter image description here

Update: As noted by rcollyer in the comments Alignment is an undocumented option for PointLegend. As an alternative, the following old Pane trick works without relying on an undocumented option:

ListPlot[Table[f, {f, {Sin[x], Cos[x]}}, {x, 0, 2  π, 0.1}],
PlotLegends ->(Style[Pane[#, BaselinePosition -> Center],40]& /@ 
              {"sin(x)", "cos(x)"})]
(* same picture *)

Update 2: Works with ListLinePlot and LineLegend combination:

ListLinePlot[Table[f, {f, {Sin[x], Cos[x]}}, {x, 0, 2 π, 0.1}], 
 PlotLegends -> LineLegend[(Style[#, 40] & /@ {"sin(x)", "cos(x)"}), Alignment -> Center]]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896
6

A reasonable workaround is to use SwatchLegend with LegendMarkers set:

ListPlot[
 Table[f, {f, {Sin[x], Cos[x]}}, {x, 0, 2 π, 0.1}],
 PlotLegends -> 
  SwatchLegend[{"sin(x)", "cos(x)"}, LabelStyle -> 40, LegendMarkers -> "Bubble" ]
]

enter image description here

Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
rcollyer
  • 33,976
  • 7
  • 92
  • 191
  • 1
    Thank you! Should the current aligning be considered as buggy in this case? And can we extend the aligning for ListLinePlot legends as well? – Yves Klett Sep 17 '14 at 14:06