fix(tidy3d): FXC-3655 Fix the color computation for plot_eps #2896
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refactors the color mapping logic in plot_eps to align with standard Matplotlib semantics and removes the temporary fix which inverts at two places in code.
What changed
Set the (inverted) cmap color directly as facecolor and choose right cmap in
_pcolormesh_shape_custom_medium_structure_epsGreptile Overview
Updated On: 2025-10-15 12:29:14 UTC
Greptile Summary
This PR refactors the color mapping logic in the
plot_epsfunctionality to fix color computation inconsistencies and align with standard Matplotlib semantics. The changes introduce a centralized_get_colormap()helper function to handle colormap selection based on thereverseparameter, eliminating code duplication across multiple plotting functions. The refactor removes temporary workarounds that manually inverted colors through mathematical operations (eps_min + eps_max - eps) and replaces them with proper matplotlib colormap usage. The most significant change is in the structure epsilon plotting parameters, where complex color computation logic is replaced with standard matplotlib normalization and colormap application, directly setting RGBA tuples as facecolor values. These changes ensure consistent color mapping behavior across different epsilon visualization functions while leveraging matplotlib's built-in colormap functionality.Changed Files
tidy3d/components/scene.py_get_colormap()helper function, removing manual color inversion hacks, and implementing proper matplotlib colormap usage for epsilon visualizationtests/test_components/test_scene.pyConfidence score: 4/5
tidy3d/components/scene.pyfor the color value clamping logic and ensure all epsilon visualization functions handle edge cases properlySequence Diagram
sequenceDiagram participant User participant Scene participant Matplotlib as mpl participant ColorMap as cmap participant PlotParams User->>Scene: plot_eps(reverse=False/True) Scene->>Scene: _get_structure_eps_plot_params() Scene->>Scene: _get_colormap(reverse) alt reverse is False Scene->>cmap: STRUCTURE_EPS_CMAP else reverse is True Scene->>cmap: STRUCTURE_EPS_CMAP_R end Scene->>mpl: colors.Normalize(vmin, vmax) Scene->>Scene: medium._eps_plot(freq) Scene->>mpl: norm(eps_medium) Scene->>cmap: get_cmap(cmap_name) Scene->>cmap: cmap(color_value) Scene->>PlotParams: copy(facecolor=rgba) PlotParams-->>Scene: updated plot_params Scene->>Scene: plot_shape(shape, plot_params) Scene-->>User: rendered plot