Skip to content

Commit

Permalink
Merge pull request #919 from PlasmaControl/rc/plot_axes
Browse files Browse the repository at this point in the history
Add option to plot axis position to `plot_boundaries`
  • Loading branch information
f0uriest authored Mar 3, 2024
2 parents 50e805d + 3ec9e21 commit ace5dbc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions desc/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -1774,7 +1774,9 @@ def plot_boundary(eq, phi=None, plot_axis=True, ax=None, return_data=False, **kw
return fig, ax


def plot_boundaries(eqs, labels=None, phi=None, ax=None, return_data=False, **kwargs):
def plot_boundaries(
eqs, labels=None, phi=None, plot_axis=True, ax=None, return_data=False, **kwargs
):
"""Plot stellarator boundaries at multiple toroidal coordinates.
Parameters
Expand All @@ -1787,6 +1789,8 @@ def plot_boundaries(eqs, labels=None, phi=None, ax=None, return_data=False, **kw
Values of phi to plot boundary surface at.
If an integer, plot that many contours linearly spaced in [0,2pi).
Default is 1 contour for axisymmetric equilibria or 4 for non-axisymmetry.
plot_axis : bool
Whether to plot the magnetic axis locations. Default is True.
ax : matplotlib AxesSubplot, optional
Axis to plot on.
return_data : bool
Expand All @@ -1808,6 +1812,8 @@ def plot_boundaries(eqs, labels=None, phi=None, ax=None, return_data=False, **kw
* ``color``: list of colors to use for each Equilibrium
* ``ls``: list of str, line styles to use for each Equilibrium
* ``lw``: list of floats, line widths to use for each Equilibrium
* ``marker``: str, marker style to use for the axis plotted points
* ``size``: float, marker size to use for the axis plotted points
Returns
-------
Expand Down Expand Up @@ -1837,6 +1843,8 @@ def plot_boundaries(eqs, labels=None, phi=None, ax=None, return_data=False, **kw
lw = kwargs.pop("lw", None)
xlabel_fontsize = kwargs.pop("xlabel_fontsize", None)
ylabel_fontsize = kwargs.pop("ylabel_fontsize", None)
marker = kwargs.pop("marker", "x")
size = kwargs.pop("size", 36)

phi = (1 if eqs[-1].N == 0 else 4) if phi is None else phi
if isinstance(phi, numbers.Integral):
Expand Down Expand Up @@ -1866,7 +1874,11 @@ def plot_boundaries(eqs, labels=None, phi=None, ax=None, return_data=False, **kw
plot_data["Z"] = []

for i in range(neq):
grid_kwargs = {"NFP": eqs[i].NFP, "theta": 100, "zeta": phi}
# don't plot axis for FourierRZToroidalSurface, since it's not defined.
plot_axis_i = plot_axis and eqs[i].L > 0
rho = np.array([0.0, 1.0]) if plot_axis_i else np.array([1.0])

grid_kwargs = {"NFP": eqs[i].NFP, "theta": 100, "zeta": phi, "rho": rho}
grid = _get_grid(**grid_kwargs)
nr, nt, nz = grid.num_rho, grid.num_theta, grid.num_zeta
grid = Grid(
Expand All @@ -1893,6 +1905,11 @@ def plot_boundaries(eqs, labels=None, phi=None, ax=None, return_data=False, **kw
(line,) = ax.plot(
R[:, -1, j], Z[:, -1, j], color=colors[i], linestyle=ls[i], lw=lw[i]
)
if rho[0] == 0:
ax.scatter(
R[0, 0, j], Z[0, 0, j], color=colors[i], marker=marker, s=size
)

if j == 0:
line.set_label(labels[i])

Expand Down
Binary file modified tests/baseline/test_plot_boundaries.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit ace5dbc

Please sign in to comment.