Skip to content

Commit

Permalink
Merge pull request #449 from reneeotten/small_fixes_after_merge
Browse files Browse the repository at this point in the history
Small fixes after merge
  • Loading branch information
newville authored Dec 7, 2017
2 parents 40d307f + 58e52dd commit fc5e38d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 32 deletions.
10 changes: 6 additions & 4 deletions examples/doc_model_loadmodel.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env python
#<examples/doc_model_loadmodel.py>
import numpy as np

# <examples/doc_model_loadmodel.py>
import matplotlib.pyplot as plt
import numpy as np

from lmfit.model import load_model


def mysine(x, amp, freq, shift):
return amp * np.sin(x*freq + shift)

Expand All @@ -24,5 +27,4 @@ def mysine(x, amp, freq, shift):
plt.plot(x, y, 'bo')
plt.plot(x, result.best_fit, 'r-')
plt.show()

#<end examples/doc_model_loadmodel.py>
# <end examples/doc_model_loadmodel.py>
9 changes: 5 additions & 4 deletions examples/doc_model_loadmodelresult.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python
#<examples/doc_model_loadmodelresult.py>
import numpy as np

# <examples/doc_model_loadmodelresult.py>
import matplotlib.pyplot as plt
import numpy as np

from lmfit.model import load_modelresult

data = np.loadtxt('model1d_gauss.dat')
Expand All @@ -14,5 +16,4 @@
plt.plot(x, y, 'bo')
plt.plot(x, result.best_fit, 'r-')
plt.show()

#<end examples/doc_model_loadmodelresult.py>
# <end examples/doc_model_loadmodelresult.py>
8 changes: 5 additions & 3 deletions examples/doc_model_loadmodelresult2.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env python
#<examples/doc_model_loadmodelresult2.py>
import numpy as np

# <examples/doc_model_loadmodelresult2.py>
import matplotlib.pyplot as plt
import numpy as np

from lmfit.model import load_modelresult

dat = np.loadtxt('NIST_Gauss2.dat')
Expand All @@ -14,4 +16,4 @@
plt.plot(x, y, 'bo')
plt.plot(x, result.best_fit, 'r-')
plt.show()
#<end examples/doc_model_loadmodelresult2.py>
# <end examples/doc_model_loadmodelresult2.py>
7 changes: 5 additions & 2 deletions examples/doc_model_savemodel.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#!/usr/bin/env python
#<examples/doc_mode_savemodel.py>

# <examples/doc_mode_savemodel.py>
import numpy as np

from lmfit.model import Model, save_model


def mysine(x, amp, freq, shift):
return amp * np.sin(x*freq + shift)

Expand All @@ -11,4 +14,4 @@ def mysine(x, amp, freq, shift):
pars = sinemodel.make_params(amp=1, freq=0.25, shift=0)

save_model(sinemodel, 'sinemodel.sav')
#<end examples/doc_model_savemodel.py>
# <end examples/doc_model_savemodel.py>
10 changes: 6 additions & 4 deletions examples/doc_model_savemodelresult.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
#!/usr/bin/env python
#<examples/doc_model_savemodelresult.py>
import numpy as np

# <examples/doc_model_savemodelresult.py>
import matplotlib.pyplot as plt
from lmfit.models import GaussianModel
import numpy as np

from lmfit.model import save_modelresult
from lmfit.models import GaussianModel

data = np.loadtxt('model1d_gauss.dat')
x = data[:, 0]
Expand All @@ -20,4 +22,4 @@
plt.plot(x, result.init_fit, 'k--')
plt.plot(x, result.best_fit, 'r-')
plt.show()
#<end examples/doc_model_savemodelresult.py>
# <end examples/doc_model_savemodelresult.py>
10 changes: 4 additions & 6 deletions examples/doc_model_savemodelresult2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
#<examples/doc_model_savemodelresult2.py>

# <examples/doc_model_savemodelresult2.py>
import numpy as np

from lmfit.model import save_modelresult
from lmfit.models import ExponentialModel, GaussianModel

Expand All @@ -13,15 +15,12 @@

gauss1 = GaussianModel(prefix='g1_')
pars.update(gauss1.make_params())

pars['g1_center'].set(value=105, min=75, max=125)
pars['g1_sigma'].set(value=15, min=3)
pars['g1_amplitude'].set(value=2000, min=10)

gauss2 = GaussianModel(prefix='g2_')

pars.update(gauss2.make_params())

pars['g2_center'].set(value=155, min=125, max=175)
pars['g2_sigma'].set(value=15, min=3)
pars['g2_amplitude'].set(value=2000, min=10)
Expand All @@ -35,5 +34,4 @@
save_modelresult(result, 'nistgauss_modelresult.sav')

print(result.fit_report())

#<end examples/doc_model_savemodelresult2.py>
# <end examples/doc_model_savemodelresult2.py>
10 changes: 5 additions & 5 deletions lmfit/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1649,11 +1649,6 @@ def plot_fit(self, ax=None, datafmt='o', fitfmt='-', initfmt='--',
**{independent_var: x_array_dense}),
initfmt, label='init', **init_kws)

ax.plot(
x_array_dense,
self.model.eval(self.params, **{independent_var: x_array_dense}),
fitfmt, label='best-fit', **fit_kws)

if yerr is None and self.weights is not None:
yerr = 1.0/self.weights
if yerr is not None:
Expand All @@ -1662,6 +1657,11 @@ def plot_fit(self, ax=None, datafmt='o', fitfmt='-', initfmt='--',
else:
ax.plot(x_array, self.data, datafmt, label='data', **data_kws)

ax.plot(
x_array_dense,
self.model.eval(self.params, **{independent_var: x_array_dense}),
fitfmt, label='best-fit', **fit_kws)

ax.set_title(self.model.name)
if xlabel is None:
ax.set_xlabel(independent_var)
Expand Down
6 changes: 2 additions & 4 deletions lmfit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class GaussianModel(Model):
"""

fwhm_factor = 2.354820
fwhm_factor = 2*np.sqrt(2*np.log(2))
height_factor = 1./np.sqrt(2*np.pi)

def __init__(self, independent_vars=['x'], prefix='', nan_policy='raise',
Expand Down Expand Up @@ -526,8 +526,6 @@ class Pearson7Model(Model):
"""

fwhm_factor = 1.0

def __init__(self, independent_vars=['x'], prefix='', nan_policy='raise',
**kwargs):
kwargs.update({'prefix': prefix, 'nan_policy': nan_policy,
Expand Down Expand Up @@ -808,7 +806,7 @@ class SkewedGaussianModel(Model):
"""

fwhm_factor = 2.354820
fwhm_factor = 2*np.sqrt(2*np.log(2))
height_factor = 1./np.sqrt(2*np.pi)

def __init__(self, independent_vars=['x'], prefix='', nan_policy='raise',
Expand Down

0 comments on commit fc5e38d

Please sign in to comment.