Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tidy3d/components/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,8 +918,10 @@ def plot_field_array(

if val == "abs":
cmap = "magma"
eps_reverse = False
else:
cmap = "RdBu"
eps_reverse = True

# plot the field
xy_coord_labels = list("xyz")
Expand All @@ -929,7 +931,13 @@ def plot_field_array(

# plot the simulation epsilon
ax = self.simulation.plot_structures_eps(
freq=freq, cbar=False, alpha=eps_alpha, ax=ax, **{axis_label: position}, **patch_kwargs
freq=freq,
cbar=False,
alpha=eps_alpha,
reverse=eps_reverse,
ax=ax,
**{axis_label: position},
**patch_kwargs,
)

# set the limits based on the xarray coordinates min and max
Expand Down
14 changes: 8 additions & 6 deletions tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -652,8 +652,7 @@ def plot_structures(
params_updater = StructMediumParams(medium=medium, medium_map=medium_map)
kwargs_struct = params_updater.update_params(**kwargs)
if medium == self.medium:
kwargs_struct["edgecolor"] = "white"
kwargs_struct["facecolor"] = "white"
continue
patch = PolygonPatch(shape, **kwargs_struct)
ax.add_artist(patch)
ax = self._set_plot_bounds(ax=ax, x=x, y=y, z=z)
Expand Down Expand Up @@ -683,6 +682,7 @@ def plot_structures_eps( # pylint: disable=too-many-arguments,too-many-locals
z: float = None,
freq: float = None,
cbar: bool = True,
reverse: bool = True,
ax: Ax = None,
**kwargs,
) -> Ax:
Expand All @@ -701,6 +701,8 @@ def plot_structures_eps( # pylint: disable=too-many-arguments,too-many-locals
freq : float = None
Frequency to evaluate the relative permittivity of all mediums.
If not specified, evaluates at infinite frequency.
reverse : bool = True
If ``True``, the highest permittivity is plotted in black; if ``False``: white.
ax : matplotlib.axes._subplots.Axes = None
Matplotlib axes to plot on, if not specified, one is created.
**kwargs
Expand All @@ -725,10 +727,12 @@ def plot_structures_eps( # pylint: disable=too-many-arguments,too-many-locals
medium_shapes = self._filter_structures_plane(self.structures, x=x, y=y, z=z)
for (medium, shape) in medium_shapes:
eps = medium.eps_model(freq).real
params_updater = StructEpsParams(eps=eps, eps_min=eps_min, eps_max=eps_max)
params_updater = StructEpsParams(
eps=eps, eps_min=eps_min, eps_max=eps_max, reverse=reverse
)
kwargs_struct = params_updater.update_params(**kwargs)
if medium == self.medium:
kwargs_struct["edgecolor"] = "white"
continue
patch = PolygonPatch(shape, **kwargs_struct)
ax.add_artist(patch)
if cbar:
Expand Down Expand Up @@ -1043,8 +1047,6 @@ def _filter_structures_plane(
# loop through background_shapes (note: all background are non-intersecting or merged)
for index, (_medium, _shape) in enumerate(background_shapes):

_shape = Box.evaluate_inf_shape(_shape)

# if not intersection, move onto next background shape
if not shape & _shape:
continue
Expand Down
6 changes: 4 additions & 2 deletions tidy3d/components/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,16 @@ class StructEpsParams(PatchParamSwitcher):
eps: float
eps_max: float
eps_min: float
reverse: bool = True

def get_plot_params(self) -> PatchParams:
"""Returns :class:`PatchParams` based on user-supplied args."""
eps_min = min(self.eps_min, 1)
delta_eps = self.eps - eps_min
delta_eps_max = self.eps_max - eps_min + 1e-5
eps_fraction = delta_eps / delta_eps_max
color = 1 - eps_fraction
color = delta_eps / delta_eps_max
if self.reverse:
color = 1 - color
if self.eps == pec_val:
return PatchParams(facecolor="gold", edgecolor="k", lw=1)
return PatchParams(facecolor=str(color), edgecolor=str(color), lw=0)
Expand Down