Skip to content

Conversation

@marcorudolphflex
Copy link
Contributor

@marcorudolphflex marcorudolphflex commented Nov 25, 2025

Enables the support of custom colormaps in field visualizations.
Usage example:

fig, axes = plt.subplots(1, 3, figsize=(12, 4))
sim_data.plot_field(
    "adjoint_fld_2",
    "Ex",
    val="real",
    z=0.0,
    ax=axes[0],
    cmap=None,
)
axes[0].set_title("Default colormap")

sim_data.plot_field(
    "adjoint_fld_2",
    "Ex",
    val="real",
    z=0.0,
    ax=axes[1],
    cmap="cividis",
)
axes[1].set_title("Custom 'cividis' colormap")

custom_cmap = mcolors.LinearSegmentedColormap.from_list("two", ["green", "blue"])
sim_data.plot_field(
    "adjoint_fld_2",
    "Ex",
    val="real",
    z=0.0,
    ax=axes[2],
    cmap=custom_cmap,
)
axes[2].set_title("Custom user colormap")
plt.show()
image

Greptile Overview

Greptile Summary

Adds support for custom colormaps in field visualization methods across the codebase. Users can now pass a cmap parameter (either a string colormap name or a matplotlib Colormap object) to plot_field methods, which overrides the default colormap inferred from the field type.

Key Changes:

  • Added cmap parameter to plot_field, plot_field_monitor_data, and plot_scalar_array methods in AbstractYeeGridSimulationData
  • Extended support to specialized simulation data classes: ModeSimulationData, HeatChargeSimulationData, ModeSolver, and RectangularDielectric
  • Implemented proper fallback logic: custom cmap overrides default colormap inferred from cmap_type
  • Added comprehensive tests for both string colormap names and custom Colormap objects
  • Updated CHANGELOG.md with user-facing feature description

Issues Found:

  • Import ordering issue in mode_solver.py: import statement appears immediately after TYPE_CHECKING block without proper separation

Confidence Score: 4/5

  • Safe to merge with one minor syntax fix for import ordering
  • The implementation is well-structured and comprehensive, with proper parameter passing through the call chain, good test coverage, and appropriate documentation. However, there is one import ordering issue in mode_solver.py where an import statement is incorrectly placed immediately after a TYPE_CHECKING block, which should be fixed before merging.
  • Pay attention to tidy3d/components/mode/mode_solver.py - fix import ordering issue on line 82-84

Important Files Changed

File Analysis

Filename Score Overview
tests/test_data/test_sim_data.py 5/5 Added test for custom colormap parameter with string and LinearSegmentedColormap
tidy3d/components/data/sim_data.py 5/5 Added cmap parameter to all plot methods with proper handling and fallback to defaults
tidy3d/components/mode/mode_solver.py 3/5 Added cmap parameter to plot_field method; import ordering issue detected
tidy3d/components/tcad/data/sim_data.py 5/5 Added cmap parameter with proper fallback to 'coolwarm' default and TYPE_CHECKING import

Sequence Diagram

sequenceDiagram
    participant User
    participant plot_field
    participant plot_field_monitor_data
    participant plot_scalar_array
    participant XarrayPlot
    
    User->>plot_field: plot_field(monitor_name, field_name, cmap="viridis")
    Note over plot_field: Accept cmap parameter<br/>(str or Colormap object)
    plot_field->>plot_field: load_field_monitor(monitor_name)
    plot_field->>plot_field_monitor_data: plot_field_monitor_data(..., cmap=cmap)
    Note over plot_field_monitor_data: Process field data<br/>and infer cmap_type
    plot_field_monitor_data->>plot_scalar_array: plot_scalar_array(..., cmap_type=cmap_type, cmap=cmap)
    Note over plot_scalar_array: Determine default_cmap<br/>from cmap_type if cmap is None
    plot_scalar_array->>plot_scalar_array: cmap_to_use = default_cmap if cmap is None else cmap
    plot_scalar_array->>XarrayPlot: field_data.plot(..., cmap=cmap_to_use)
    XarrayPlot-->>User: Returns matplotlib axes with field visualization
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

8 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@marcorudolphflex marcorudolphflex force-pushed the FXC-4260-allow-users-to-swap-custom-cmaps-in-field-visualization branch from e667d29 to d24e11d Compare November 25, 2025 11:42
@github-actions
Copy link
Contributor

Diff Coverage

Diff: origin/develop...HEAD, staged and unstaged changes

  • tidy3d/components/data/sim_data.py (83.3%): Missing lines 829
  • tidy3d/components/mode/data/sim_data.py (100%)
  • tidy3d/components/mode/mode_solver.py (100%)
  • tidy3d/components/tcad/data/sim_data.py (100%)
  • tidy3d/plugins/waveguide/rectangular_dielectric.py (100%)

Summary

  • Total: 11 lines
  • Missing: 1 line
  • Coverage: 90%

tidy3d/components/data/sim_data.py

Lines 825-833

  825             vmax = np.pi
  826             center = False
  827             eps_reverse = False
  828         else:
! 829             default_cmap = None
  830 
  831         cmap_to_use = default_cmap if cmap is None else cmap
  832 
  833         # plot the field

Copy link
Collaborator

@yaugenst-flex yaugenst-flex left a comment

Choose a reason for hiding this comment

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

Nice!

@yaugenst-flex yaugenst-flex added this pull request to the merge queue Nov 25, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to no response for status checks Nov 25, 2025
@daquinteroflex daquinteroflex added this pull request to the merge queue Nov 25, 2025
@daquinteroflex daquinteroflex removed this pull request from the merge queue due to a manual request Nov 25, 2025
@daquinteroflex daquinteroflex merged commit b3206f1 into develop Nov 25, 2025
83 of 86 checks passed
@daquinteroflex daquinteroflex deleted the FXC-4260-allow-users-to-swap-custom-cmaps-in-field-visualization branch November 25, 2025 19:16
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.

5 participants