Skip to content

Commit

Permalink
Predictive explorer: add option to fix y_lims (#648)
Browse files Browse the repository at this point in the history
* Predictive explorer: add option to fix y_lims

* fix linting issues
  • Loading branch information
aleicazatti authored Feb 21, 2025
1 parent 4aad654 commit 9bd36b9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
18 changes: 18 additions & 0 deletions preliz/internal/plot_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,24 @@ def get_textboxes(signature, model):
disabled=False,
)

textboxes["__set_ylim__"] = Checkbox(
value=False, description="set ylim", disabled=False, indent=False
)

textboxes["__y_min__"] = FloatText(
value=-10,
step=0.1,
description="y_min",
disabled=False,
)

textboxes["__y_max__"] = FloatText(
value=10,
step=0.1,
description="y_max",
disabled=False,
)

textboxes["__resample__"] = ToggleButton(
value=True,
description="Resample",
Expand Down
11 changes: 11 additions & 0 deletions preliz/ppls/agnostic.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,16 @@ def looper(*args, **kwargs):
else:
auto = False

y_min = kwargs.pop("__y_min__", None)
y_max = kwargs.pop("__y_max__", None)
set_ylim = kwargs.pop("__set_ylim__", False)
if not set_ylim:
y_min = None
y_max = None
auto_ylim = True
else:
auto_ylim = False

if engine == "preliz":
results = []
for _ in range(iterations):
Expand Down Expand Up @@ -264,6 +274,7 @@ def looper(*args, **kwargs):

_, ax = plt.subplots()
ax.set_xlim(x_min, x_max, auto=auto)
ax.set_ylim(y_min, y_max, auto=auto_ylim)
if plot_func is None:
plot_repr(results, kind_plot, references, iterations, ax)
else:
Expand Down
10 changes: 9 additions & 1 deletion preliz/predictive/predictive_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ def predictive_explorer(
textboxes = get_textboxes(signature, model)
new_fmodel = ppl_plot_decorator(fmodel, samples, kind_plot, references, plot_func, engine)
out = interactive_output(new_fmodel, textboxes)
default_names = ["__set_xlim__", "__x_min__", "__x_max__", "__resample__"]
default_names = [
"__set_xlim__",
"__x_min__",
"__x_max__",
"__set_ylim__",
"__y_min__",
"__y_max__",
"__resample__",
]
default_controls = [textboxes[name] for name in default_names]
params_controls = [v for k, v in textboxes.items() if k not in default_names]

Expand Down

0 comments on commit 9bd36b9

Please sign in to comment.