Skip to content

Add F.plot(...) for one-line PyVista field visualization#1176

Merged
RemDelaporteMathurin merged 25 commits into
mainfrom
copilot/basic-functionality-plotting-fields
Jul 16, 2026
Merged

Add F.plot(...) for one-line PyVista field visualization#1176
RemDelaporteMathurin merged 25 commits into
mainfrom
copilot/basic-functionality-plotting-fields

Conversation

Copilot AI commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Description

Summary

This PR adds a lightweight plotting API for species fields so users can generate PyVista visuals in one line, including multi-species and subdomain-aware cases.

  • API surface
    • Added public F.plot(...) entrypoint (src/festim/plot.py, exported via src/festim/__init__.py).
  • Core behavior
    • Supports single species and list input (auto subplot layout).
    • Supports subdomain=... for mixed-domain/discontinuous workflows.
    • Supports filename=... for screenshot output and show_edges=True shortcut.
    • Forwards extra mesh args via **kwargs to plotter.add_mesh(...).
  • Robustness
    • Clear errors for invalid field types, missing post-processing solutions, and missing optional pyvista dependency.
  • Tests
    • Added focused unit tests in test/test_plot.py covering API behavior, edge cases, and error paths.

Related Issues

Handled by automatic issue linking in the PR system.

Motivation and Context

Plotting fields with PyVista currently requires repetitive boilerplate (vtk_mesh, grid wiring, plotter setup). This change introduces a small wrapper to make field visualization immediate while preserving control through optional arguments.

Type of Change

  • 🐛 Bug fix (non-breaking change which fixes an issue)
  • ✨ New feature (non-breaking change which adds functionality)
  • 💥 Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • 🔨 Code refactoring (no functional changes, no API changes)
  • 📝 Documentation update
  • ✅ Test update (adding missing tests or correcting existing tests)
  • 🔧 Build/CI configuration change

Testing

  • All existing tests pass locally (pytest)
  • I have added new tests that prove my fix is effective or that my feature works

Code Quality Checklist

  • My code follows the code style of this project (Ruff formatted: ruff format .)
  • My code passes linting checks (ruff check .)
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas

Documentation

  • I have updated the documentation accordingly (if applicable)
  • I have added docstrings to new functions/classes following the project conventions

Breaking Changes

None.

Screenshots/Examples

import festim as F

H = F.Species("H")
D = F.Species("D")

F.plot(H)                              # default quick view
F.plot(H, subdomain=vol1)              # mixed-domain: specific subdomain
F.plot([H, D], show_edges=True)        # automatic subplots
F.plot(H, filename="concentration.png")  # save screenshot

Additional Notes

This PR keeps scope intentionally narrow: one public plotting helper plus focused tests around that API surface.

@codecov

codecov Bot commented Jun 23, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.91525% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.79%. Comparing base (3dde3af) to head (d3d46b7).

Files with missing lines Patch % Lines
src/festim/plotting.py 94.82% 3 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1176   +/-   ##
=======================================
  Coverage   94.79%   94.79%           
=======================================
  Files          46       47    +1     
  Lines        3437     3496   +59     
=======================================
+ Hits         3258     3314   +56     
- Misses        179      182    +3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI changed the title [WIP] Add basic functionality for plotting fields with pyvista Add F.plot(...) for one-line PyVista field visualization Jun 23, 2026
@RemDelaporteMathurin
RemDelaporteMathurin marked this pull request as ready for review June 24, 2026 13:03
@RemDelaporteMathurin

Copy link
Copy Markdown
Collaborator

@ck768 @jhdark @hhy2022 would one of you mind having a look at these modifications?

Comment thread src/festim/plotting.py
Comment thread src/festim/plotting.py Outdated
Comment thread src/festim/plotting.py
Comment thread src/festim/plotting.py
Comment thread src/festim/plotting.py Outdated
Comment thread src/festim/plotting.py

@jhdark jhdark left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Just some minor changes from me

Comment thread src/festim/plotting.py

from festim.species import Species

DEFAULT_TITLE_FONT_SIZE = 12

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is only used in one place, dont think its needed

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would keep it here as 1. we may use it in other places 2. it helps keep the "config" variables easily accessible

@RemDelaporteMathurin
RemDelaporteMathurin merged commit 9a69f1d into main Jul 16, 2026
16 of 21 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.

3 participants