Skip to content

Commit

Permalink
Fixed an issue where plots for multi-key fits where not rendered corr…
Browse files Browse the repository at this point in the history
…ectly

This addresses one comment in #10
  • Loading branch information
ckoerber committed Oct 11, 2021
1 parent 646e8bc commit e756c0b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
43 changes: 43 additions & 0 deletions example/multi_key_example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Example script for fit with multiple keys.
See also https://github.com/ckoerber/lsqfit-gui/issues/10
"""
import lsqfit
import gvar as gv
import numpy as np

from lsqfitgui import run_server

XX = dict(
d1=np.array([1, 2, 3, 4]),
d2=np.array([1, 2, 3, 4]),
d3=np.array([1, 2, 3, 4]),
d4=np.array([1, 2, 3, 4]),
d5=np.array([5, 6, 7, 8]),
)

YY = dict(
d1=["1.154(10)", "2.107(16)", "3.042(22)", "3.978(29)"],
d2=["0.692(10)", "1.196(16)", "1.657(22)", "2.189(29)"],
d3=["0.107(10)", "0.030(16)", "-0.027(22)", "-0.149(29)"],
d4=["0.002(10)", "-0.197(16)", "-0.382(22)", "-0.627(29)"],
d5=["1.869(10)", "2.198(16)", "2.502(22)", "2.791(29)"],
)
PRIOR = gv.gvar(dict(a="0(1)", s1="0(1)", s2="0(1)", s3="0(1)", s4="0(1)", s5="0(1)"))


def fitfcn(x, p):
"""Return linear fit function.
$$f(x; a, s_n) = a + s_n * x$$
"""
return {key: p["a"] + p[f"s{key[1:]}"] * x[key] for key in x}


def main():
"""Run lsqfitgui server for multi-linear fit."""
run_server(lsqfit.nonlinear_fit(data=(XX, YY), fcn=fitfcn, prior=PRIOR))


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion lsqfitgui/plot/fit.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def plot_fit(fit, fig: Optional[Figure] = None):
)
plot_band(
fig,
x_fit if isinstance(x_fit, dict) else x_fit,
x_fit[key] if isinstance(x_fit, dict) else x_fit,
y_min_fit[key],
y_mean_fit[key],
y_max_fit[key],
Expand Down

0 comments on commit e756c0b

Please sign in to comment.