[plotter] make it possible to fit even if yerr_kind is None

This commit is contained in:
Noe Brucy
2021-02-03 19:25:15 +01:00
parent 7aa08c1394
commit 92d6c66af5
+2 -2
View File
@@ -1130,7 +1130,7 @@ class Plotter(Aggregator, BaseProcessor):
Add an overlay : fit a curve, linear or powerlaw Add an overlay : fit a curve, linear or powerlaw
""" """
if kind == "linear": if kind == "linear":
if yerr is None: if yerr is None or np.sum(np.abs(yerr)) == 0:
(a, b, rho, _map_rule, stderr) = linregress(x, y) (a, b, rho, _map_rule, stderr) = linregress(x, y)
self._log( self._log(
"Linear fit y = {} x + {} with R^2 = {} and error is {}".format( "Linear fit y = {} x + {} with R^2 = {} and error is {}".format(
@@ -1153,7 +1153,7 @@ class Plotter(Aggregator, BaseProcessor):
label = r"Linear fit with slope ${:.3g}$".format(a) label = r"Linear fit with slope ${:.3g}$".format(a)
plt.plot(x, a * x + b, label=label, **kwargs) plt.plot(x, a * x + b, label=label, **kwargs)
elif kind == "power_law": elif kind == "power_law":
if yerr is None: if yerr is None or np.sum(np.abs(yerr)) == 0:
(a, b, rho, _map_rule, stderr) = linregress(np.log10(x), np.log10(y)) (a, b, rho, _map_rule, stderr) = linregress(np.log10(x), np.log10(y))
self._log( self._log(
"Power law fit y = x^({}) * {} with R^2 = {} and error is {}".format( "Power law fit y = x^({}) * {} with R^2 = {} and error is {}".format(