Como colocar um título em PlotLegends?

Sep 12 2020

Quero dar um título às lendas do enredo que estou usando. Eu tenho uma solução aqui que diz para usar PlotLegends -> SwatchLegend[{0, 3.3, 6.7, 10, 13, 17, 20}, LegendLabel -> "mu"]. Mas também quero colocar as lendas onde quero usar PlotLegends -> Placed[Range[1, 6, 1], {0.2, 0.3}].

Como posso fazer as duas coisas?

Edit: Como a resposta foi dada, o empacotamento funciona, mas ainda há um problema, ou seja, meu enredo fica assim:

Onde eu quero nomear as lendas como "H". Mas quando eu faço aquela coisa do Swatchlegend, fica assim:

Quero manter os marcadores e cores iguais. O que devo fazer?

Respostas

4 TimLaska Sep 12 2020 at 02:01

Você provavelmente está procurando PointLegend, mas deve fornecer mais detalhes para que outras pessoas possam reproduzir seus resultados.

mu = {0, 3.3, 6.7, 10, 13, 17, 20};
pl = PointLegend[mu, LegendLabel -> "mu", LegendFunction -> "Frame", 
   LegendLayout -> "Row", LegendMarkers -> Automatic];
fns = Table[n^(1/p), {p, 7}, {n, 10}];
ListLinePlot[fns, PlotMarkers -> Automatic, 
 PlotLegends -> Placed[pl, Top]]

3 tad Sep 12 2020 at 02:29

Você pode envolver em torno da legenda. Aqui está um exemplo modificado da documentação SwatchLegend:

Plot[{Sin[x], Cos[x]}, {x, 0, 5}, 
   PlotLegends -> Placed[SwatchLegend[{"first", "second"}, 
LegendLabel -> "legend title"], {0.2, 0.3}]]

3 kglr Sep 12 2020 at 08:16

Você pode usar PlotLegends - > Placed[labels, Top, Labeled[#, legendlabel, Top] &].

Usando o exemplo de entrada da resposta de Tim Laska:

mu = {0, 3.3, 6.7, 10, 13, 17, 20};
fns = Table[n^(1/p), {p, 7}, {n, 10}];

ListLinePlot[fns, PlotMarkers -> Automatic, 
 PlotLegends -> Placed[mu, Top, Labeled[#, Style["mu", 16], Top] &]]

Você pode embelezar ainda mais a aparência usando o terceiro argumento de Placed:

ListLinePlot[fns, PlotMarkers -> Automatic, 
 PlotLegends -> Placed[mu, Top, Panel @ Labeled[#, Style["mu", 16], Top] &]]

ListLinePlot[fns, PlotMarkers -> Automatic, 
 PlotLegends ->  Placed[mu, Top, 
   Framed[#, FrameStyle -> Directive[Thin, Gray], 
       RoundingRadius -> 5, ImageMargins -> 5] & @
     Labeled[#, Style[Row[{Spacer[5], "mu"}], 24, "Section"], {{Top, Left}}] &]]