From eb9e51f0fd5303adbede080119c6bdc86e36921c Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Sat, 13 Dec 2025 17:47:51 +0100 Subject: [PATCH 1/2] DOC: Improve docs of legend loc=best Closes #29319. --- lib/matplotlib/legend.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index 8f43f89de5f9..eab729579053 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -303,8 +303,13 @@ def _update_bbox_to_anchor(self, loc_in_canvas): _loc_doc_best = """ The string ``'best'`` places the legend at the location, among the nine locations defined so far, with the minimum overlap with other drawn - artists. This option can be quite slow for plots with large amounts of - data; your plotting speed may benefit from providing a specific location. + artists. This currently takes into account most, but not all, artists + added to the Axes via plotting functions. In particular it does not consider + inset axes or moved titles or axis labels. + + The computation of the best position can be expensive for plots with large + amounts of data. If speed becomes a concern, you may may benefit from + providing a specific location. """ _legend_kw_axes_st = ( From 4cbd2393a3fb46b45b68ca52fc60a70e1bd83aab Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Tue, 16 Dec 2025 10:23:49 +0100 Subject: [PATCH 2/2] Update lib/matplotlib/legend.py Co-authored-by: Ruth Comer <10599679+rcomer@users.noreply.github.com> --- lib/matplotlib/legend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index eab729579053..876725fbc4f6 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -305,7 +305,7 @@ def _update_bbox_to_anchor(self, loc_in_canvas): locations defined so far, with the minimum overlap with other drawn artists. This currently takes into account most, but not all, artists added to the Axes via plotting functions. In particular it does not consider - inset axes or moved titles or axis labels. + inset axes, titles, or axis labels. The computation of the best position can be expensive for plots with large amounts of data. If speed becomes a concern, you may may benefit from