When I create plots, I usually make a legend box which I then manually have to place within the plot using the Placed[] option. However, since it is manual, it means that I always need to adjust it or I will risk covering a part of the plot, something that often happens when I batch produce plots. I would therefore like to have an Automatic option, similar to the "best" placement type in Python matplotlib, that puts the legend within the plot, but not covering anything. If I simply use "Automatic", Mathematica will place the legend outside of the plot to the right, but this is often a waste of space.
Example:
ListPlot[{
Table[{i, Sin[i]}, {i, 0, 10}],
Table[{i, Cos[i]}, {i, 0, 10}]
}
, ImageSize -> 1000,
Joined -> True, PlotMarkers -> Automatic,
PlotLegends ->
Placed[LineLegend[
Map[Style[#, FontSize -> 24,
FontFamily -> "TimesNewRoman"] &, {"sin", "cos"}],
Spacings -> {0.15, -0.2},
LegendFunction -> (Framed[#, RoundingRadius -> 5,
FrameStyle -> Gray, Background -> White] &)]
, Scaled[{0.87, 0.75}]]
]
I guess that one option would be to make a custom function that, from the input data, determines the plot range, finds the biggest empty space in the plot, and then uses these coordinates for the Placed[] option. However, I think that this will require a lot of tweaking, to accomodate for 1) a varying number of entries in the legend and 2) the feature in Mathematica where the shape of the legend box can vary depending on placement and number of entries.
It would also not be very "pretty" to simply use the biggest white space -- often the upper right corner is large enough even though it might not be the biggest white space, and when it is large enough, it should take precedence.