Skip to content

Optional matplotlib dependency#311

Merged
MassimoCimmino merged 3 commits intoMassimoCimmino:masterfrom
axelstudios:task/refactor-matplotlib
Apr 7, 2025
Merged

Optional matplotlib dependency#311
MassimoCimmino merged 3 commits intoMassimoCimmino:masterfrom
axelstudios:task/refactor-matplotlib

Conversation

@axelstudios
Copy link
Contributor

@axelstudios axelstudios commented Mar 18, 2025

This PR refactors all matplotlib imports to be lazily imported with graceful error-handling to separate core functionality from visualization.

Pygfunction can now be installed with optional matplotlib support:

  • pip install pygfunction
  • pip install pygfunction[plot]

Attempting to call a function like borefield.visualize_field() without the plot extra will result in the error:

ImportError: Matplotlib is required for plotting. Install it with pip install pygfunction[plot]

It also fixes a small handful of typos, and updates the minimum matplotlib version for compatibility with NumPy 2.0.

@axelstudios axelstudios force-pushed the task/refactor-matplotlib branch from 8e96aff to 3555f72 Compare March 28, 2025 14:20
@axelstudios axelstudios changed the title Remove matplotlib dependency overhead Optional matplotlib dependency Mar 28, 2025
@MassimoCimmino
Copy link
Owner

Thank you @axelstudios.

This looks great. I will open an issue to report the changes in the changelog and go through the files one last time before merging.

This seems like it is completely backwards compatible. We can plan for a v2.3 release shortly after.

Your previous changes had the plotting functionality moved outside of the different modules. It could be a good idea to implement a plotting module. This could allow to have the try / except import of matplotlib in a single place, perhaps in __init__ to effectively make the functionality disappear to the user that does not have matplotlib installed. Anyways, this is something I will consider for v3.0 later on.

Would you mind appearing on the front page of the project in the 'all contributors' list?

@MassimoCimmino MassimoCimmino linked an issue Apr 3, 2025 that may be closed by this pull request
@axelstudios
Copy link
Contributor Author

Would you mind appearing on the front page of the project in the 'all contributors' list?

Not at all, that sounds great 🎉

@MassimoCimmino MassimoCimmino merged commit dafaefa into MassimoCimmino:master Apr 7, 2025
10 checks passed
@MassimoCimmino
Copy link
Owner

@all-contributors
please add @axelstudios for code.

@allcontributors
Copy link
Contributor

@MassimoCimmino

I've put up a pull request to add @axelstudios! 🎉

@axelstudios axelstudios deleted the task/refactor-matplotlib branch April 8, 2025 19:37
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.

Make matplotlib dependency optional

2 participants