Improve legend loc and bbox_to_anchor documentation (#26620) by amanparganiha · Pull Request #31422 · matplotlib/matplotlib · GitHub
Skip to content

Improve legend loc and bbox_to_anchor documentation (#26620) - #31422

Merged
timhoffm merged 3 commits into
matplotlib:mainfrom
amanparganiha:fix/legend-docs-26620
Mar 30, 2026
Merged

timhoffm merged 3 commits into
matplotlib:mainfrom
amanparganiha:fix/legend-docs-26620

Conversation

@amanparganiha

Copy link
Copy Markdown
Contributor

PR summary

Fixes #26620 — Improves the loc and bbox_to_anchor parameter documentation in the legend module.

  • Why is this change necessary? The current loc documentation uses three separate paragraphs to describe legend positions, which is verbose and harder to scan. The bbox_to_anchor docs don't clearly state it's an advanced option or link to relevant guides.

  • What problem does it solve? Makes legend positioning easier to understand at a glance by adding a visual ASCII grid of all 9 positions, and clarifies the relationship between loc and bbox_to_anchor.

  • What is the reasoning for this implementation? Follows the suggestions in [Doc]: Improve legend loc and bbox_to_anchor documentation #26620 by maintainer @timhoffm.

Changes

  • Parameter loc: Replaced three text paragraphs with a concise explanation and an ASCII visual grid showing all 9 legend positions. Clarified that positions are within a bounding box configurable via bbox_to_anchor.
  • Parameter bbox_to_anchor: Clarified this is an advanced option for free placement. Added cross-references to Figure.legend for outside placement and to the :ref:legend_guide``.

AI Disclosure

I used Claude (Anthropic) for researching the issue and drafting the documentation text. The changes were reviewed and verified by me.

PR checklist

  • "closes [Doc]: Improve legend loc and bbox_to_anchor documentation #26620" is in the body of the PR description
  • [N/A] new and changed code is tested
  • [N/A] "Plotting related" features are demonstrated in an example
  • [N/A] "New Features" and "API Changes" are noted with a directive and release note
  • Documentation complies with general and docstring guidelines

@github-actions

Copy link
Copy Markdown

@timhoffm timhoffm left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR!

Comment thread lib/matplotlib/legend.py Outdated
Comment thread lib/matplotlib/legend.py Outdated
amanparganiha and others added 2 commits March 30, 2026 13:41
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com>
@amanparganiha

Copy link
Copy Markdown
Contributor Author

@timhoffm timhoffm added this to the v3.11.0 milestone Mar 30, 2026
@timhoffm
timhoffm merged commit 7820a63 into matplotlib:main Mar 30, 2026
38 of 41 checks passed
@amanparganiha
amanparganiha deleted the fix/legend-docs-26620 branch April 26, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

[Doc]: Improve legend loc and bbox_to_anchor documentation

2 participants