¿Cómo poner un título a PlotLegends?

Sep 12 2020

Quiero poner un título a las leyendas de la trama que estoy usando. Obtengo una solución aquí que dice usar PlotLegends -> SwatchLegend[{0, 3.3, 6.7, 10, 13, 17, 20}, LegendLabel -> "mu"]. Pero también quiero colocar las leyendas donde quiero usarlas PlotLegends -> Placed[Range[1, 6, 1], {0.2, 0.3}].

¿Cómo puedo hacer ambas cosas?

Editar: como se dio la respuesta, la envoltura funciona, pero todavía hay un problema, es decir, mi trama se ve así:

Donde quiero nombrar las leyendas como "H". Pero cuando hago eso Swatchlegend, se vuelve así:

Quiero mantener los marcadores y colores iguales. ¿Qué tengo que hacer?

Respuestas

4 TimLaska Sep 12 2020 at 02:01

Probablemente lo esté buscando PointLegend, pero debe proporcionar más detalles para que otros puedan reproducir sus 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

Puede envolver Colocado alrededor de la leyenda. Aquí hay un ejemplo modificado de la documentación 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

Puede utilizar PlotLegends - > Placed[labels, Top, Labeled[#, legendlabel, Top] &].

Usando la entrada de ejemplo de la respuesta 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] &]]

Puede embellecer aún más la apariencia utilizando el tercer 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}}] &]]