Skip to content

Commit 9bdbb75

Browse files
committed
Refactored ExoIris.plot_setup method.
1 parent 0897c66 commit 9bdbb75

File tree

1 file changed

+22
-51
lines changed

1 file changed

+22
-51
lines changed

exoiris/exoiris.py

Lines changed: 22 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -491,65 +491,36 @@ def print_parameters(self) -> None:
491491
"""Print the model parameterization."""
492492
self._tsa.print_parameters(1)
493493

494-
def plot_setup(self, figsize: tuple[float, float] | None =None, xscale: str | None = None, xticks: Sequence | None = None) -> Figure:
494+
def plot_setup(self, figsize: tuple[float, float] | None = None,
495+
ax: matplotlib.axes.Axes | None = None,
496+
xscale: str | None = None, xticks: Sequence | None = None,
497+
yshift: float = 0.1, mh:float = 0.08, side_margin: float = 0.05,
498+
lw: float = 0.5, c='k') -> Figure:
495499
"""Plot the model setup with limb darkening knots, radius ratio knots, and data binning.
496-
497-
Parameters
498-
----------
499-
figsize
500-
The size of the figure in inches.
501-
xscale
502-
The scale of the x-axis. If provided, the x-axis scale of all the subplots will be set to this value.
503-
xticks
504-
The list of x-axis tick values for all the subplots. If provided, the x-axis ticks of all the subplots will
505-
be set to these values.
506-
507-
Returns
508-
-------
509-
Figure
510-
The matplotlib Figure object that contains the created subplots.
511-
512500
"""
513-
using_ldtk = isinstance(self._tsa.ldmodel, LDTkLD)
501+
if ax is None:
502+
fig, ax = subplots(figsize=figsize, constrained_layout=True)
503+
else:
504+
fig = ax.figure
514505

515-
if not using_ldtk:
516-
figsize = figsize or (13, 4)
517-
fig, axs = subplots(3, 1, figsize=figsize, sharex='all', sharey='all')
518-
axl, axk, axw = axs
506+
ndata = self.data.size
519507

520-
axl.vlines(self._tsa.ld_knots, 0.1, 0.5, ec='k')
521-
axl.text(0.01, 0.90, 'Limb darkening knots', va='top', transform=axl.transAxes)
522-
else:
523-
figsize = figsize or (13, 2*4/3)
524-
fig, axs = subplots(2, 1, figsize=figsize, sharex='all', sharey='all')
525-
axk, axw = axs
526-
axl = None
527-
528-
axk.vlines(self._tsa.k_knots, 0.1, 0.5, ec='k')
529-
axk.text(0.01, 0.90, 'Radius ratio knots', va='top', transform=axk.transAxes)
530-
for ds in self.data:
531-
axw.vlines(ds.wavelength, 0.1, 0.5, ec='k')
532-
axw.text(0.01, 0.90, 'Wavelength bins', va='top', transform=axw.transAxes)
533-
534-
if not using_ldtk:
535-
sb.despine(ax=axl, top=False, bottom=True, right=False)
536-
sb.despine(ax=axk, top=True, bottom=True, right=False)
537-
else:
538-
sb.despine(ax=axk, top=False, bottom=True, right=False)
508+
for i, d in enumerate(self.data):
509+
ax.vlines(d.wavelength, ymin=i*yshift, ymax=i*yshift+mh, colors=c, lw=lw)
510+
511+
i = ndata + 1
512+
ax.vlines(self._tsa.ld_knots, ymin=i*yshift, ymax=i*yshift+mh, colors=c, lw=lw)
539513

540-
sb.despine(ax=axw, top=True, bottom=False, right=False)
541-
setp(axs, xlim=(self.data.wlmin-0.02, self.data.wlmax+0.02), yticks=[], ylim=(0, 0.9))
542-
setp(axw, xlabel=r'Wavelength [$\mu$m]')
543-
setp(axs[0].get_xticklines(), visible=False)
544-
setp(axs[0].get_xticklabels(), visible=False)
545-
setp(axs[1].get_xticklines(), visible=False)
546-
setp(axs[-1].get_xticklines(), visible=True)
514+
i = ndata + 3
515+
ax.vlines(self.k_knots, ymin=i*yshift, ymax=i*yshift+mh, colors=c, lw=lw)
547516

548517
if xscale:
549-
setp(axs, xscale=xscale)
518+
setp(ax, xscale=xscale)
550519
if xticks is not None:
551-
[ax.set_xticks(xticks, labels=xticks) for ax in axs]
552-
fig.tight_layout()
520+
ax.set_xticks(xticks, labels=xticks)
521+
522+
setp(ax, yticks=[], xlim=(self.data.wlmin-side_margin, self.data.wlmax+side_margin), xlabel='Wavelength [$\mu$m]')
523+
ax.set_yticks(concatenate([arange(ndata), arange(ndata+1, ndata+4, 2)])*yshift+0.5*mh, labels=[n.replace("_", " ") for n in self.data.names] + ["Limb darkening knots", "Radius ratio knots"])
553524
return fig
554525

555526
def fit_white(self, niter: int = 500) -> None:

0 commit comments

Comments
 (0)