Draw perfect metals (ε = -∞) in dark red in plot2D - #3303
Merged
Merged
Conversation
stevengj
reviewed
Sep 4, 2026
stevengj
reviewed
Sep 4, 2026
stevengj
approved these changes
Sep 4, 2026
…liasing bug for index_parameters of plot1D
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Context
mp.metalandmp.perfect_electric_conductorare defined asMedium(epsilon=-inf)(python/meep.i:1825-1826), and that-infsurvives as a large finite-1e20all the way throughgeom_epsilon::chi1p1→Simulation.get_epsilon_grid.plot_eps— the functionplot2Dcalls to draw the geometry (python/visualization.py:599-732) — passes that array straight toax.imshowand, whencolorbar=True, straight intompl.colors.Normalize(np.amin(eps_data), np.amax(eps_data)). The consequences of this are:vmin = -inf, so the colorbar is meaningless and every finite dielectric collapses onto one end of the scale.safe_masked_invalidmasks the-infpixels and draws them with the colormap's "bad" color, which defaults to fully transparent — metal renders as blank background rather than as a material (see first image below).levels=np.unique(eps_data)includes-infas a contour level.Changes
python/visualization.pypec_color: "darkred"key indefault_eps_parameters(dropped byfilter_dictbefore reachingimshow, like the other non-imshow dicts).plot_epsnow masks metallic pixels (~np.isfinite(eps) | (eps <= -mp.inf)) and paints them viacmap.set_bad(pec_color)on acopy.copyof the colormap, soimshowautoscales over the finite permittivities only.vmin/vmaxnow come from the unmasked values, with a guard for an all-metal plane.np.unique(eps_data.compressed())so-1e20is no longer emitted as a contour level.eps_parameters = default_eps_parametershanded out the module-level dict itself, which the new code would have mutated — nowcopy.deepcopy._get_colormap()(handles str orColormap, matplotlib ≥3.5 or older) and used it in_add_colorbar; required because aColormapinstance is now passed there, andmpl.cm.get_cmapis removed in matplotlib 3.11. This also clears the deprecation warning the old cell emitted.Verification
test_plot2D_pec(clim finite and equal to (1, 12), bad color =darkred, mask non-empty, defaults unmutated, user override honored) andtest_plot2D_pec_contour.Here is an example involving a cleaved multilayer stack in which the substrate is a perfect metal. Metallic/PEC regions render as a distinct dark red, and the color scale (image and colorbar) is driven only by the finite permittivity values.