-
Notifications
You must be signed in to change notification settings - Fork 18
Add placement of legend to axes within a figure #418
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
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds the ability to place legends on specific axes within a figure with precise span control over which subplot columns or rows the legend covers. This mirrors the existing functionality for colorbars (from commit 946c33a) and provides consistent API for controlling legend placement.
Key changes:
- Added
span,row,col,rows, andcolsparameters to legend methods for controlling legend placement across subplot grids - Implemented validation logic that enforces correct parameter usage (e.g., vertical legends must use
rowsparameter, horizontal legends must usecols) - Added comprehensive test coverage including validation tests, array handling, and multi-side legend placement
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| ultraplot/tests/test_legend.py | Adds 15 new test cases covering span functionality, parameter validation, and edge cases for legend placement across subplot grids |
| ultraplot/figure.py | Updates legend() method to accept and process span parameters, extracting single axes from arrays when span is specified, mirroring colorbar implementation |
| ultraplot/axes/base.py | Adds span parameters to legend() and _add_legend() method signatures and passes them to _add_guide_panel() for panel creation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
beckermr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The doc strings need updating I think.
|
I think that it already in there see https://github.com/Ultraplot/UltraPlot/blob/a9db8bc12add66cafc6faf553f7bf976ec496e55/ultraplot/figure.py#L381C2-L390C49 |
beckermr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah you are correct. Sorry and LGTM!
Closes #417
This approach takes a similar approach to 946c33a to add the option to add legends to a subset that is not on the outside.
Here is a minimal example