Adding an offset with ModelResult.plot_fit ?

32 views
Skip to first unread message

Cosme

unread,
Dec 12, 2023, 12:02:46 PM12/12/23
to lmfit-py
Dear all,

I was wondering if adding an offset to a ModelResult.plot_fit was possible ? 

I was looking at the documentation (https://lmfit.github.io/lmfit-py/model.html#lmfit.model.ModelResult.plot_fit) but I do not see how I could do this...

plot_fit is great for me because I am using a CompositeModel and I need to display the fitted data in a bigger interval than the fitted one. (To do so I use the  numpoints options in plot_fit.)

Do you know if an offset could be added to plot_fit? Thanks again for your help.
Cosme

Ex of a part of my code :

### Making the Model
mod  = QuadraticModel() # background
pars = mod.make_params()
for i in range(n):
    modi = PseudoVoigtModel(prefix='dho'+str(i)+'_')
    modi.guess(y, x=x)
    pars+= modi.make_params()    
    mod += modi
    # INITIALISATION OF THE DATA NOT SHOWN

### FITTING
iteration_number = 2000
out = mod.fit(yfit, pars, x=xfit, max_nfev=iteration_number)
out.plot_fit(numpoints=10000, title=" ", datafmt=' ', fitfmt='k')

Matt Newville

unread,
Dec 12, 2023, 12:29:03 PM12/12/23
to lmfi...@googlegroups.com
Hi Cosme,

Sorry for being dense, but an offset to what? 

Honestly, I think we mostly regret including these matplotlib plotting functions.  We might be willing to add features for common use cases, but we want to avoid trying to accommodate all possible visualizations of fits.



--
You received this message because you are subscribed to the Google Groups "lmfit-py" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lmfit-py+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lmfit-py/74207e69-5373-48cf-b48b-fde6f1819498n%40googlegroups.com.


--Matt 

Cosme

unread,
Dec 13, 2023, 2:07:10 PM12/13/23
to lmfit-py
Hello Matt, 
Thanks a lot for your answer and sorry for not being clearer ! 

What I meant by offset is to add a constant number to y in the original and fitted data, so that I could plot several curves in a waterfall, such as visible here in subfigures (a) or (b) : Link

No worries if there is no way of doing such a thing with this function !

All the best,
- Cosme
Reply all
Reply to author
Forward
0 new messages