Skip to content

Commit

Permalink
Merge pull request #385 from neutrinoceros/bug/consistent_returns
Browse files Browse the repository at this point in the history
BUG: make `Plotable.plot` return unconditionally
  • Loading branch information
neutrinoceros authored Dec 16, 2024
2 parents 2aeacaf + f73e566 commit 3e90907
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions nonos/api/analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
from nonos.logging import logger

if TYPE_CHECKING:
from matplotlib.artist import Artist
from matplotlib.axes import Axes
from matplotlib.figure import Figure

Expand Down Expand Up @@ -53,7 +54,7 @@ def plot(
unit_conversion=None,
nbin=None, # deprecated
**kwargs,
):
) -> "Artist":
if nbin is not None:
warnings.warn(
"The nbin parameter has no effect and is deprecated",
Expand All @@ -65,6 +66,7 @@ def plot(
if log:
data = np.log10(data)

artist: Artist
if self.dimension == 2:
self.akey = self.dict_plotable["abscissa"]
self.okey = self.dict_plotable["ordinate"]
Expand All @@ -81,7 +83,7 @@ def plot(
vmax = kwargs.pop("vmax") if "vmax" in kwargs else np.nanmax(data)
kw.update({"vmin": vmin, "vmax": vmax})

im = ax.pcolormesh(
artist = im = ax.pcolormesh(
self.avalue,
self.ovalue,
data,
Expand Down Expand Up @@ -120,8 +122,6 @@ def plot(
trf, subs=list(range(1, int(trf.base)))
)
cb_axis.set_minor_locator(locator)
else:
return im
elif self.dimension == 1:
vmin = kwargs.pop("vmin") if "vmin" in kwargs else np.nanmin(data)
vmax = kwargs.pop("vmax") if "vmax" in kwargs else np.nanmax(data)
Expand All @@ -130,7 +130,7 @@ def plot(
if "norm" in kwargs:
logger.info("norm has no meaning in 1D.")
kwargs.pop("norm")
ax.plot(self.avalue, data, **kwargs)
artist = ax.plot(self.avalue, data, **kwargs)[0]
ax.set_ylim(ymin=vmin)
ax.set_ylim(ymax=vmax)
ax.set_xlabel(self.akey)
Expand All @@ -144,6 +144,8 @@ def plot(
if filename is not None:
fig.savefig(f"{filename}.{fmt}", bbox_inches="tight", dpi=dpi)

return artist


class Coordinates:
"""Coordinates class from x1, x2, x3"""
Expand Down

0 comments on commit 3e90907

Please sign in to comment.