Jak dodać tytuł do PlotLegends?
Chcę dodać tytuł do legendy fabuły, której używam. Dostaję tutaj rozwiązanie , które mówi, aby użyć PlotLegends -> SwatchLegend[{0, 3.3, 6.7, 10, 13, 17, 20}, LegendLabel -> "mu"]. Ale chcę też umieścić legendy tam, gdzie chcę, aby ich używać PlotLegends -> Placed[Range[1, 6, 1], {0.2, 0.3}].
Jak mogę zrobić jedno i drugie?
Edycja: Jak udzielono odpowiedzi, owijanie działa, ale nadal jest problem, tj. Moja działka wygląda tak:
Gdzie chcę nazwać legendy jako „H”. Ale kiedy robię to ze Swatchlegend, wygląda to tak:
Chcę zachować te same markery i kolory. Co powinienem zrobić?
Odpowiedzi
Prawdopodobnie szukasz PointLegend, ale powinieneś podać więcej szczegółów, aby inni mogli odtworzyć twoje wyniki.
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]]
Możesz zawijać Umieszczone wokół legendy. Oto przykład zmodyfikowany na podstawie dokumentacji SwatchLegend:
Plot[{Sin[x], Cos[x]}, {x, 0, 5},
PlotLegends -> Placed[SwatchLegend[{"first", "second"},
LegendLabel -> "legend title"], {0.2, 0.3}]]
Możesz użyć PlotLegends - > Placed[labels, Top, Labeled[#, legendlabel, Top] &].
Korzystając z przykładowych danych wejściowych z odpowiedzi Tima Laski:
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] &]]
Możesz dodatkowo upiększyć wygląd, używając trzeciego argumentu 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}}] &]]