def ExpLine(*args, **kwargs):
rate = kwargs.pop('rate', None)
log_data = kwargs.pop('log_data', True)
data = kwargs.pop('data', None)
const = kwargs.pop('const', 1)
if rate is None:
assert data is not None and len(data) > 0, "rate or data must be given"
x = np.array([d[0] for d in data])
y = np.array([d[1] for d in data])
if len(x) > 0 and len(y) > 0:
if log_data:
rate = np.polyfit(np.log(x), np.log(y), 1)[0]
else:
rate = np.polyfit(x, y, 1)[0]
if "label" in kwargs:
kwargs["label"] = kwargs.pop("label").format(rate=rate)
return FunctionLine2D(*args, fn=lambda x, r=rate:
const*np.array(x)**r, data=data,
log_data=log_data, **kwargs)
评论列表
文章目录