Search code examples
pythonlmfit

Extending a trendline in a lmfit plot


I have fitted a curve using lmfit but the trendline/curve is short. Please how do I extend the trendline/curve in both directions because the trendline/curve is hanging. Sample codes are warmly welcome my senior programmers. Thanks.


Solution

  • More detail about what you are actually doing would be helpful. That is, vague questions can really only get vague answers.

    Assuming you are doing curve fitting with lmfit's Model class, then once you have your Model and a set of Parameters (say, after a fit has refined them to best match some data), then you can use those to evaluate the Model (with the model.eval() method) for any values of the independent variable (typically called x). That allows on a finer grid or extending past the range of the data you actually used in the fit.

    Of course, predicting past the end of the data range assumes that the model is valid outside the range of the data. It's hard to know when that assumption is correct, especially when you have no data ;). "It's tough to make predictions, especially about the future."