Skip to content

Document legend's slowness when "best" location is used #12203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/matplotlib/legend.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ def _update_bbox_to_anchor(self, loc_in_canvas):
corner of the legend in axes coordinates (in which case
``bbox_to_anchor`` will be ignored).

The 'best' option can be quite slow for plots with large amounts
of data. Your plotting speed may benefit from providing a specific
location.

bbox_to_anchor : `.BboxBase`, 2-tuple, or 4-tuple of floats
Box that is used to position the legend in conjunction with *loc*.
Defaults to `axes.bbox` (if called as a method to `.Axes.legend`) or
Expand Down
8 changes: 8 additions & 0 deletions tutorials/introductory/usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,14 @@ def my_plotter(ax, data1, data2, param_dict):
# plt.plot(y)
# plt.show()
#
# Legends
# -------
#
# The default legend behavior for axes attempts to find the location
# that covers the fewest data points (`loc='best'`). This can be a
# very expensive computation if there are lots of data points. In
# this case, you may want to provide a specific location.
#
# Using the *fast* style
# ----------------------
#
Expand Down