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
43 changes: 34 additions & 9 deletions tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,14 @@ def background_structure(self) -> Structure:
@equal_aspect
@add_ax_if_none
def plot(
self, x: float = None, y: float = None, z: float = None, ax: Ax = None, **patch_kwargs
self,
x: float = None,
y: float = None,
z: float = None,
ax: Ax = None,
source_alpha: float = None,
monitor_alpha: float = None,
**patch_kwargs,
) -> Ax:
"""Plot each of simulation's components on a plane defined by one nonzero x,y,z coordinate.

Expand All @@ -585,6 +592,10 @@ def plot(
position of plane in y direction, only one of x, y, z must be specified to define plane.
z : float = None
position of plane in z direction, only one of x, y, z must be specified to define plane.
source_alpha : float = None
Opacity of the sources. If ``None``, uses to Tidy3d default.
Copy link
Contributor

Choose a reason for hiding this comment

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

"uses Tidy3D default"? (Also next line)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

oops, just saw these. thanks. will fix

monitor_alpha : float = None
Opacity of the monitors. If ``None``, uses to Tidy3d default.
ax : matplotlib.axes._subplots.Axes = None
Matplotlib axes to plot on, if not specified, one is created.

Expand All @@ -595,8 +606,8 @@ def plot(
"""

ax = self.plot_structures(ax=ax, x=x, y=y, z=z)
ax = self.plot_sources(ax=ax, x=x, y=y, z=z)
ax = self.plot_monitors(ax=ax, x=x, y=y, z=z)
ax = self.plot_sources(ax=ax, x=x, y=y, z=z, alpha=source_alpha)
ax = self.plot_monitors(ax=ax, x=x, y=y, z=z, alpha=monitor_alpha)
ax = self.plot_symmetries(ax=ax, x=x, y=y, z=z)
ax = self.plot_pml(ax=ax, x=x, y=y, z=z)
ax = self._set_plot_bounds(ax=ax, x=x, y=y, z=z)
Expand All @@ -611,6 +622,8 @@ def plot_eps( # pylint:disable=too-many-arguments
z: float = None,
freq: float = None,
alpha: float = None,
source_alpha: float = None,
monitor_alpha: float = None,
ax: Ax = None,
) -> Ax:
"""Plot each of simulation's components on a plane defined by one nonzero x,y,z coordinate.
Expand All @@ -630,6 +643,10 @@ def plot_eps( # pylint:disable=too-many-arguments
alpha : float = None
Opacity of the structures being plotted.
Defaults to the structure default alpha.
source_alpha : float = None
Opacity of the sources. If ``None``, uses to Tidy3d default.
Copy link
Contributor

Choose a reason for hiding this comment

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

"uses Tidy3D default"? (Also next line)

monitor_alpha : float = None
Opacity of the monitors. If ``None``, uses to Tidy3d default.
ax : matplotlib.axes._subplots.Axes = None
Matplotlib axes to plot on, if not specified, one is created.

Expand All @@ -640,8 +657,8 @@ def plot_eps( # pylint:disable=too-many-arguments
"""

ax = self.plot_structures_eps(freq=freq, cbar=True, alpha=alpha, ax=ax, x=x, y=y, z=z)
ax = self.plot_sources(ax=ax, x=x, y=y, z=z)
ax = self.plot_monitors(ax=ax, x=x, y=y, z=z)
ax = self.plot_sources(ax=ax, x=x, y=y, z=z, alpha=source_alpha)
ax = self.plot_monitors(ax=ax, x=x, y=y, z=z, alpha=monitor_alpha)
ax = self.plot_symmetries(ax=ax, x=x, y=y, z=z)
ax = self.plot_pml(ax=ax, x=x, y=y, z=z)
ax = self._set_plot_bounds(ax=ax, x=x, y=y, z=z)
Expand Down Expand Up @@ -871,7 +888,9 @@ def _plot_shape_structure_eps(

@equal_aspect
@add_ax_if_none
def plot_sources(self, x: float = None, y: float = None, z: float = None, ax: Ax = None) -> Ax:
def plot_sources(
self, x: float = None, y: float = None, z: float = None, alpha: float = None, ax: Ax = None
) -> Ax:
"""Plot each of simulation's sources on a plane defined by one nonzero x,y,z coordinate.

Parameters
Expand All @@ -882,6 +901,8 @@ def plot_sources(self, x: float = None, y: float = None, z: float = None, ax: Ax
position of plane in y direction, only one of x, y, z must be specified to define plane.
z : float = None
position of plane in z direction, only one of x, y, z must be specified to define plane.
alpha : float = None
Opacity of the sources, If ``None`` uses Tidy3d default.
ax : matplotlib.axes._subplots.Axes = None
Matplotlib axes to plot on, if not specified, one is created.

Expand All @@ -891,13 +912,15 @@ def plot_sources(self, x: float = None, y: float = None, z: float = None, ax: Ax
The supplied or created matplotlib axes.
"""
for source in self.sources:
ax = source.plot(x=x, y=y, z=z, ax=ax)
ax = source.plot(x=x, y=y, z=z, alpha=alpha, ax=ax)
ax = self._set_plot_bounds(ax=ax, x=x, y=y, z=z)
return ax

@equal_aspect
@add_ax_if_none
def plot_monitors(self, x: float = None, y: float = None, z: float = None, ax: Ax = None) -> Ax:
def plot_monitors(
self, x: float = None, y: float = None, z: float = None, alpha: float = None, ax: Ax = None
) -> Ax:
"""Plot each of simulation's monitors on a plane defined by one nonzero x,y,z coordinate.

Parameters
Expand All @@ -908,6 +931,8 @@ def plot_monitors(self, x: float = None, y: float = None, z: float = None, ax: A
position of plane in y direction, only one of x, y, z must be specified to define plane.
z : float = None
position of plane in z direction, only one of x, y, z must be specified to define plane.
alpha : float = None
Opacity of the sources, If ``None`` uses Tidy3d default.
ax : matplotlib.axes._subplots.Axes = None
Matplotlib axes to plot on, if not specified, one is created.

Expand All @@ -917,7 +942,7 @@ def plot_monitors(self, x: float = None, y: float = None, z: float = None, ax: A
The supplied or created matplotlib axes.
"""
for monitor in self.monitors:
ax = monitor.plot(x=x, y=y, z=z, ax=ax)
ax = monitor.plot(x=x, y=y, z=z, alpha=alpha, ax=ax)
ax = self._set_plot_bounds(ax=ax, x=x, y=y, z=z)
return ax

Expand Down
2 changes: 1 addition & 1 deletion tidy3d/components/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def include_kwargs(self, **kwargs) -> "PlotParams":
"""Update the plot params with supplied kwargs."""
new_plot_params = self.copy(deep=True)
for key, value in kwargs.items():
if key not in ("type",):
if key not in ("type",) and value is not None:
setattr(new_plot_params, key, value)
return new_plot_params

Expand Down