Skip to content

Conversation

@cvanelteren
Copy link
Collaborator

An issue popped up in #309 where if locations are changed for legends they are not synced with _legend_dict. This PR fixes this by override the set_loc function of legend.

Why was this an issue? UltraPlot allows for updating the styling of legends when a legend already exists on at that location. Since the internal reference is used, a sync issue appears if for whatever reason the legend is moved.

@cvanelteren
Copy link
Collaborator Author

needs tests

@cvanelteren cvanelteren requested a review from Copilot August 1, 2025 14:25

This comment was marked as outdated.

cvanelteren and others added 2 commits August 1, 2025 16:28
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@cvanelteren cvanelteren requested a review from Copilot August 1, 2025 14:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Contributor

Copilot AI left a 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 fixes a synchronization issue where _legend_dict becomes out of sync when legend locations are changed after creation. The fix involves creating a custom Legend class that overrides the set_loc method to update the internal dictionary when the location changes.

  • Creates a custom Legend wrapper class that inherits from matplotlib's Legend
  • Overrides the set_loc method to sync location changes with _legend_dict
  • Updates all references throughout the codebase to use the new custom Legend class

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
ultraplot/legend.py Introduces new Legend class with overridden set_loc method for syncing location changes
ultraplot/axes/base.py Updates imports and references to use the custom Legend class instead of matplotlib's Legend
Comments suppressed due to low confidence (1)

ultraplot/legend.py:33

  • The variable name type shadows the built-in type function. Consider renaming it to legend_type or similar.
            where, type = old_loc

cvanelteren and others added 3 commits August 1, 2025 16:31
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@codecov
Copy link

codecov bot commented Aug 1, 2025

Codecov Report

❌ Patch coverage is 94.59459% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
ultraplot/legend.py 90.47% 0 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@cvanelteren cvanelteren requested a review from beckermr August 1, 2025 15:30
@beckermr beckermr merged commit 8f2cdde into Ultraplot:main Aug 2, 2025
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants