Skip to content

Commit

Permalink
BUG: fix set_zlim method with symlog norm
Browse files Browse the repository at this point in the history
  • Loading branch information
neutrinoceros committed Oct 10, 2021
1 parent 8015b41 commit bc667bb
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions yt/visualization/base_plot_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,10 @@ def _init_image(self, data, cbnorm, cblinthresh, cmap, extent, aspect):
cbnorm_cls = matplotlib.colors.Normalize
elif cbnorm == "symlog":
# if cblinthresh is not specified, try to come up with a reasonable default
vmin = float(np.nanmin(data))
vmax = float(np.nanmax(data))
if cblinthresh is None:
cblinthresh = np.nanmin(np.absolute(data)[data != 0])

cbnorm_kwargs.update(dict(linthresh=cblinthresh, vmin=vmin, vmax=vmax))
cbnorm_kwargs.update(dict(linthresh=cblinthresh))
MPL_VERSION = Version(matplotlib.__version__)
if MPL_VERSION >= Version("3.2.0"):
# note that this creates an inconsistency between mpl versions
Expand Down Expand Up @@ -275,35 +273,38 @@ def _init_image(self, data, cbnorm, cblinthresh, cmap, extent, aspect):
if cbnorm == "symlog":
formatter = matplotlib.ticker.LogFormatterMathtext(linthresh=cblinthresh)
self.cb = self.figure.colorbar(self.image, self.cax, format=formatter)
if np.nanmin(data) >= 0.0:
yticks = [np.nanmin(data).v] + list(
zmin = float(self.zmin) if self.zmin is not None else np.nanmin(data)
zmax = float(self.zmax) if self.zmax is not None else np.nanmax(data)

if zmin >= 0.0:
yticks = [zmin] + list(
10
** np.arange(
np.rint(np.log10(cblinthresh)),
np.ceil(np.log10(np.nanmax(data))),
np.ceil(np.log10(zmax)),
)
)
elif np.nanmax(data) <= 0.0:
elif zmax <= 0.0:
yticks = (
list(
-(
10
** np.arange(
np.floor(np.log10(-np.nanmin(data))),
np.floor(np.log10(-zmin)),
np.rint(np.log10(cblinthresh)) - 1,
-1,
)
)
)
+ [np.nanmax(data).v]
+ [zmax]
)
else:
yticks = (
list(
-(
10
** np.arange(
np.floor(np.log10(-np.nanmin(data))),
np.floor(np.log10(-zmin)),
np.rint(np.log10(cblinthresh)) - 1,
-1,
)
Expand All @@ -314,7 +315,7 @@ def _init_image(self, data, cbnorm, cblinthresh, cmap, extent, aspect):
10
** np.arange(
np.rint(np.log10(cblinthresh)),
np.ceil(np.log10(np.nanmax(data))),
np.ceil(np.log10(zmax)),
)
)
)
Expand Down

0 comments on commit bc667bb

Please sign in to comment.