Skip to content

Commit

Permalink
API Forward kwargs from results reader plot to matplotlib
Browse files Browse the repository at this point in the history
Passing label is not allowed since we label based on dictionary values
passed for y and right quantities.

Closes CORE-GATECH-GROUP#422

Related to CORE-GATECH-GROUP#433 and CORE-GATECH-GROUP#417
  • Loading branch information
drewejohnson committed Apr 15, 2021
1 parent 6bbd9da commit 1c2d1cd
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions serpentTools/parsers/results.py
Expand Up @@ -715,7 +715,7 @@ def _cleanMetadata(self):
@magicPlotDocDecorator
def plot(self, x, y=None, right=None, sigma=3, ax=None, legend=None,
ncol=None, xlabel=True, ylabel=None, logx=False, logy=False,
loglog=False, rightlabel=None):
loglog=False, rightlabel=None, **kwargs):
"""
Plot quantities over time
Expand Down Expand Up @@ -756,6 +756,11 @@ def plot(self, x, y=None, right=None, sigma=3, ax=None, legend=None,
rlabel: str or None
If given and passing values to ``right``, use this to label
the y-axis.
{kwargs} : pyplot plot or errorbar depending on if ``sigma`` evaluates
to ``True``. Will be passed for both right and left plots. Passing
``"label"`` to label a single plot is not allowed. Instead, pass
a dictionary for ``y`` and/or ``right``. Values will be used to
label a given quantity.
Returns
-------
Expand All @@ -781,6 +786,9 @@ def plot(self, x, y=None, right=None, sigma=3, ax=None, legend=None,
if xlabel is True:
xlabel = RESULTS_PLOT_XLABELS[x]

if "label" in kwargs:
raise KeyError("Passing label as kwargs is not supported")

if len(y) == 1 and ylabel is None:
for ylabel in y.values():
break # just need the first one
Expand All @@ -789,7 +797,7 @@ def plot(self, x, y=None, right=None, sigma=3, ax=None, legend=None,

ax = ax or gca()

self._plot(x, y, ax, sigma)
self._plot(x, y, ax, sigma, **kwargs)

if right is None:
formatPlot(ax, logx=logx, logy=logy, loglog=loglog,
Expand All @@ -805,7 +813,7 @@ def plot(self, x, y=None, right=None, sigma=3, ax=None, legend=None,
colors = colors[len(y):] + colors[:len(y)]
other.set_prop_cycle(cycler('color', colors))

self._plot(x, right, other, sigma)
self._plot(x, right, other, sigma, **kwargs)

# formatting
if logy is None or isinstance(logy, bool):
Expand Down Expand Up @@ -836,7 +844,7 @@ def plot(self, x, y=None, right=None, sigma=3, ax=None, legend=None,

return ax, other

def _plot(self, x, y, ax, sigma):
def _plot(self, x, y, ax, sigma, **kwargs):
"""Simple, unformatted plot with dictionary of keys"""
# get plot data
xvals = self.resdata[x][:, 0]
Expand All @@ -849,12 +857,15 @@ def _plot(self, x, y, ax, sigma):

# grab second column for uncertainty
if sigma and ydata.shape[1] > 1:
ax.errorbar(xvals, ydata[:, 0], label=label,
yerr=ydata[:, 0] * sigma * ydata[:, 1],
)
ax.errorbar(
xvals,
ydata[:, 0],
label=label,
yerr=ydata[:, 0] * sigma * ydata[:, 1],
**kwargs,
)
else:
ax.errorbar(xvals, ydata[:, 0], label=label,
)
ax.plot(xvals, ydata[:, 0], label=label, **kwargs)

@staticmethod
def _expandPlotIterables(y, tail=''):
Expand Down

0 comments on commit 1c2d1cd

Please sign in to comment.