I have a Manipulate
-based figure in which I'd like to place a compact legend in the upper left corner (within the figure's frame). But by default, the items in the legend are spaced too far apart, and have a font that's too big (and different from the font used for the axes and other labels):
How do I control the spacing and font size for my plot legend? I've tried all the answers I've found here that seem relevant, but I fear that even if I hit on the potentially right one, it isn't clear where to apply the solution in the context of my code.
Ideally, I'd like a solution that simplifies the code as a whole, or at least doesn't make it more complex. I've long passed the point I often reach in Mathematica where I think: "I should have just done this in Python!"
sigmoid[z_]:= E^z/(E^z+1)
relu[z_]:=Max[{0, #}]&/@z
softplus[z_]:=Log[1+E^z]
Manipulate[
total=E^rng/saturation;
Show[{
Plot[{E^z/total}, {z, -rng, Log[saturation*total](*==rng*)}, PlotRange->{{-rng, rng}, {0, prng}},
PlotLegends->Placed[{StringForm["Softmax (`1`%)", NumberForm[saturation*100, {3, 1}]]}, {Left, Top}], PlotStyle->Blue,
Epilog->{Text[Style[N[E^rng/total, 4]], {rng+.3, E^rng/total}, {-0.5, 0}]}],
Plot[{sigmoid@z}, {z, -rng, rng}, PlotRange->{{-rng, rng}, {0, prng}},
PlotLegends->Placed[{"Sigmoid"}, {Left, Top}], PlotStyle->Orange],
Plot[{relu@z}, {z, -rng, rng}, PlotRange->{{-rng, rng}, {0, prng}},
PlotLegends->Placed[{"ReLU"}, {Left, Top}], PlotStyle->Purple],
Plot[{softplus@z}, {z, -rng, rng}, PlotRange->{{-rng, rng}, {0, prng}},
PlotLegends->Placed[{"Softplus"}, {Left, Top}], PlotStyle->Green]
}, FrameLabel->{"z", "a(z)"}, AxesOrigin->{-rng, 0}, Frame->True,
Prolog->{GrayLevel[.95], Line[{{0, 0}, {0, prng}}], Dashed, Line[{{-rng, 1.0}, {rng, 1.0}}]},
PlotRangeClipping->False, ImagePadding->{{Automatic, 45}, {Automatic, Automatic}}],
{{rng, 5, "Logit (z) range"}, 1, 10},
{{saturation, 1, "Logit concentration"}, 1, 1/n, 0.001}, (* Activation, a(z), fraction in highest *)
Delimiter,
{{n, 10, "Classes (has no effect)"}, 1, 50, 1, Visible->False},
{{prng, 1.1, "Activation (a) scale range"}, 1.0, 2*rng}]
PlotLegends
with something like thisPlaced[LineLegend[{Red}, {Style["Softplus", FontSize -> 10]}, LegendMargins -> 0], {Left, Top}]
? $\endgroup$