Skip to content

Commit 24669a5

Browse files
committed
Refactor interactive fitting: remove unused fitting figure function and add visibility setter for widgets
1 parent d8e5093 commit 24669a5

2 files changed

Lines changed: 4 additions & 34 deletions

File tree

anyplotlib/widgets.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ def visible(self) -> bool:
220220
"""``True`` if the widget is rendered; ``False`` if hidden."""
221221
return self._data.get("visible", True)
222222

223+
@visible.setter
224+
def visible(self, value: bool) -> None:
225+
self.show() if value else self.hide()
226+
223227
def show(self) -> None:
224228
"""Show the widget. Does not fire ``on_changed`` callbacks."""
225229
self._data["visible"] = True

tests/test_widgets.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -832,40 +832,6 @@ def _two_gaussians(x, a1, mu1, s1, a2, mu2, s2):
832832
return _gaussian(x, a1, mu1, s1) + _gaussian(x, a2, mu2, s2)
833833

834834

835-
def _make_fitting_figure():
836-
"""Build the same setup as plot_interactive_fitting.py."""
837-
from scipy.optimize import curve_fit
838-
839-
x = np.linspace(0, 10, 200)
840-
TRUE_P = [
841-
dict(amp=1.0, mu=3.2, sigma=0.55),
842-
dict(amp=0.75, mu=6.8, sigma=0.80),
843-
]
844-
COLORS = ["#ff6b6b", "#69db7c"]
845-
rng = np.random.default_rng(42)
846-
signal = sum(_gaussian(x, **p) for p in TRUE_P) + rng.normal(0, 0.03, len(x))
847-
848-
INIT_P = [
849-
dict(amp=1.0, mu=3.0, sigma=0.6),
850-
dict(amp=0.7, mu=7.0, sigma=0.9),
851-
]
852-
853-
fig, ax = apl.subplots(1, 1, figsize=(600, 300))
854-
plot = ax.plot(signal, x_axis=x, color="#adb5bd")
855-
856-
comp_lines = [
857-
plot.add_line(_gaussian(x, **p), x_axis=x, color=c, label=f"comp {i+1}")
858-
for i, (p, c) in enumerate(zip(INIT_P, COLORS))
859-
]
860-
861-
fit_line = plot.add_line(
862-
sum(_gaussian(x, **p) for p in INIT_P), x_axis=x,
863-
color="#ffd43b", linestyle="dashed", label="fit",
864-
)
865-
866-
return fig, plot, comp_lines, fit_line, x, signal, INIT_P, COLORS, curve_fit
867-
868-
869835
class _GaussianController:
870836
"""Mirror of GaussianController from plot_interactive_fitting.py."""
871837

0 commit comments

Comments
 (0)