Skip to content
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

Remove usage of deprecated matplotlib InsetPosition #5343

Merged
merged 1 commit into from
Jan 6, 2025

Conversation

brimoor
Copy link
Contributor

@brimoor brimoor commented Jan 5, 2025

Resolves #5304

Tested by

In a Jupyter notebook, run the following:

%matplotlib notebook
import fiftyone as fo
import fiftyone.brain as fob
import fiftyone.zoo as foz

dataset = foz.load_zoo_dataset("quickstart")
results = fob.compute_visualization(dataset, brain_key="img_viz")
plot = results.visualize(labels="uniqueness", backend="matplotlib")
plot.show()
session = fo.launch_app(dataset)
session.plots.attach(plot)

Summary by CodeRabbit

  • Refactor
    • Simplified the method for creating inset axes for buttons in the plot interface
    • Improved code readability by using a more direct approach to adding axes

@brimoor brimoor added the bug Bug fixes label Jan 5, 2025
@brimoor brimoor requested a review from a team January 5, 2025 22:41
Copy link
Contributor

coderabbitai bot commented Jan 5, 2025

Walkthrough

The pull request addresses a deprecation issue in the FiftyOne library's matplotlib plotting module. The change replaces the deprecated InsetPosition method with Axes.inset_axes() when creating axes for buttons in the InteractiveCollection class. This modification ensures compatibility with newer versions of matplotlib by using the recommended approach for creating inset axes, specifically addressing the import error caused by the removal of InsetPosition in matplotlib 3.10.0.

Changes

File Change Summary
fiftyone/core/plots/matplotlib.py Replaced self.ax.figure.add_axes with self.ax.inset_axes() in the _init_hud method

Assessment against linked issues

Objective Addressed Explanation
Fix deprecated InsetPosition import
Ensure compatibility with matplotlib 3.10.0+

Suggested labels

cleaning

Suggested reviewers

  • benjaminpkane

Poem

🐰 A rabbit's plot-fixing tale,
Matplotlib's change we now unveil,
InsetPosition, farewell and goodbye,
inset_axes() now makes buttons fly,
Code clean and bright, no more to wail! 📊


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 199872a and 3355cd4.

📒 Files selected for processing (1)
  • fiftyone/core/plots/matplotlib.py (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (6)
  • GitHub Check: test / test-python (ubuntu-latest-m, 3.10)
  • GitHub Check: test / test-app
  • GitHub Check: build / build
  • GitHub Check: lint / eslint
  • GitHub Check: e2e / test-e2e
  • GitHub Check: build
🔇 Additional comments (1)
fiftyone/core/plots/matplotlib.py (1)

1168-1168: LGTM! Good replacement of deprecated matplotlib feature.

The change from InsetPosition to inset_axes() is a good modernization that follows matplotlib's recommended practices. The functionality remains identical while ensuring compatibility with newer matplotlib versions.

Let's verify the matplotlib version compatibility:

✅ Verification successful

Verified: The inset_axes replacement is properly implemented and compatible

The verification shows:

  • The project uses matplotlib 3.5.2 as specified in requirements/common.txt
  • The inset_axes method is used correctly in the button initialization context
  • No other instances of the deprecated InsetPosition remain in the codebase
  • This is the only instance of inset_axes usage, properly replacing the deprecated feature

The change is well-contained and follows matplotlib's modern API, ensuring compatibility with the project's matplotlib version requirements.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check matplotlib version requirements in setup.py or requirements files

# Look for matplotlib version specifications
rg -g '*.txt' -g 'setup.py' -g 'pyproject.toml' 'matplotlib[>=<~=]*'

# Look for any remaining usages of InsetPosition that might need updating
rg 'InsetPosition'

Length of output: 154


Script:

#!/bin/bash
# Let's check for any other instances of inset_axes usage and the context around it
rg -A 3 -B 3 'inset_axes'

# Also check for any imports or references to matplotlib's axes module
rg -A 2 -B 2 'from matplotlib(\.[a-z]+)* import.*[Aa]xes'

Length of output: 606


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@minhtuev
Copy link
Contributor

minhtuev commented Jan 6, 2025

image
I tested the snippet above, it works 👍

Interactive mathplot lib inside Jupyternotebook:
https://www.loom.com/share/1360831177064d548dec9ff0dc95fc6a

Copy link
Contributor

@minhtuev minhtuev left a comment

Choose a reason for hiding this comment

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

Thanks Brian ✅

@brimoor brimoor merged commit 6cdd977 into develop Jan 6, 2025
12 of 14 checks passed
@brimoor brimoor deleted the bugfix/iss-5304 branch January 6, 2025 04:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Deprecated matplotlib InsetPosition
2 participants