Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Check for histogram_lut vmin/vmax eager callbacks #846

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions fastplotlib/tools/_histogram_lut.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,23 @@ def _make_colorbar(self, edges_flanked) -> ImageGraphic:
return cbar

def _get_vmin_vmax_str(self) -> tuple[str, str]:
if self.vmin < 0.001 or self.vmin > 99_999:
vmin_str = f"{self.vmin:.2e}"
else:
vmin_str = f"{self.vmin:.2f}"

if self.vmax < 0.001 or self.vmax > 99_999:
vmax_str = f"{self.vmax:.2e}"
else:
vmax_str = f"{self.vmax:.2f}"
# https://docs.dask.org/en/latest/generated/dask.array.Array.compute.html
lazy_callbacks = ["compute"]

def as_float(x) -> float:
for name in lazy_callbacks:
meth = getattr(x, name, None)
if callable(meth):
x = meth()
break
return float(x)

vmin = as_float(self.vmin)
vmax = as_float(self.vmax)

vmin_str = f"{vmin:.2e}" if vmin < 1e-3 or vmin > 9.9999e4 else f"{vmin:.2f}"
vmax_str = f"{vmax:.2e}" if vmax < 1e-3 or vmax > 9.9999e4 else f"{vmax:.2f}"

return vmin_str, vmax_str

Expand Down