当前位置: 首页>>代码示例>>Python>>正文


Python Data.curve_fit方法代码示例

本文整理汇总了Python中Stoner.Data.curve_fit方法的典型用法代码示例。如果您正苦于以下问题:Python Data.curve_fit方法的具体用法?Python Data.curve_fit怎么用?Python Data.curve_fit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stoner.Data的用法示例。


在下文中一共展示了Data.curve_fit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: linspace

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
"""Example of nDimArrhenius Fit."""
from Stoner import Data
import Stoner.Fit as SF
from numpy import linspace
from numpy.random import normal

# Make some data
T = linspace(50, 500, 101)
R = SF.nDimArrhenius(T + normal(size=len(T), scale=5.0, loc=1.0), 1e6, 0.5, 2)
d = Data(T, R, setas="xy", column_headers=["T", "Rate"])

# Curve_fit on its own
d.curve_fit(SF.nDimArrhenius, p0=[1e6, 0.5, 2], result=True, header="curve_fit")
d.setas = "xyy"
d.plot(fmt=["r.", "b-"])
d.annotate_fit(SF.nDimArrhenius, x=0.25, y=0.3)

# lmfit using lmfit guesses
fit = SF.NDimArrhenius()
p0 = fit.guess(R, x=T)
d.lmfit(fit, p0=p0, result=True, header="lmfit")
d.setas = "x..y"
d.plot(fmt="g-")
d.annotate_fit(SF.NDimArrhenius, x=0.25, y=0.05, prefix="NDimArrhenius")

d.title = "n-D Arrhenius Test Fit"
d.ylabel = "Rate"
d.xlabel = "Temperature (K)"
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:30,代码来源:nDimArrhenius.py

示例2: plane

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
def plane(coord, a, b, c):
    """Function to define a plane"""
    return c - (coord[0] * a + coord[1] * b)


coeefs = [1, -0.5, -1]
col = linspace(-10, 10, 6)
X, Y = meshgrid(col, col)
Z = plane((X, Y), *coeefs) + normal(size=X.shape, scale=7.0)
d = Data(
    column_stack((X.ravel(), Y.ravel(), Z.ravel())),
    filename="Fitting a Plane",
    setas="xyz",
)

d.column_headers = ["X", "Y", "Z"]
d.figure(projection="3d")
d.plot_xyz(plotter="scatter")

popt, pcov = d.curve_fit(plane, [0, 1], 2, result=True)
d.setas = "xy.z"

d.plot_xyz(linewidth=0, cmap=cmap.jet)

txt = "$z=c-ax+by$\n"
txt += "\n".join([d.format("plane:{}".format(k), latex=True) for k in ["a", "b", "c"]])

ax = plt.gca(projection="3d")
ax.text(15, 5, -50, txt)
d.draw()
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:32,代码来源:curve_fit_plane.py

示例3: linspace

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
"""Simple use of lmfit to fit data."""
from Stoner import Data
from Stoner.Fit import PowerLaw
from Stoner.analysis.fitting import odr_Model
from numpy import linspace, exp, random

# Make some data
x = linspace(0, 10.0, 101)
y = PowerLaw().func(x, 1e-1, 1.64) * random.normal(loc=1.0, scale=0.05, size=101)
d = Data(x, y, column_headers=["Time", "Signal"], setas="xy")

# Do the fitting and plot the result
fit = d.curve_fit(
    PowerLaw, result=True, header="LM-Model Fit", residuals=True, output="report"
)

ODRModel = odr_Model(PowerLaw, p0=(1, 1))
fit = d.curve_fit(
    ODRModel,
    result=True,
    header="ODR-Fit",
    residuals=True,
    output="report",
    prefix="ODRModel",
)
# Reset labels
d.labels = []

# Make nice two panel plot layout
ax = d.subplot2grid((3, 1), (2, 0))
d.setas = "x..y"
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:33,代码来源:curvefit_models.py

示例4: Data

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
s = y * 0.05
d = Data(x, y, s, setas="xye", column_headers=["X", "Y"])
d.plot(fmt="r.")

d.polyfit(result=True, header="Polyfit")
d.setas = "x..y"
d.plot(fmt="m-", label="Polyfit")
d.text(
    -9,
    450,
    "Polynominal co-efficients\n{}".format(d["2nd-order polyfit coefficients"]),
    fontdict={"size": "x-small", "color": "magenta"},
)

d.setas = "xy"
d.curve_fit(SF.quadratic, result=True, header="Curve-fit")
d.setas = "x...y"
d.plot(fmt="b-", label="curve-fit")
d.annotate_fit(
    SF.quadratic,
    prefix="quadratic",
    x=0.2,
    y=0.65,
    fontdict={"size": "x-small", "color": "blue"},
)

d.setas = "xy"
fit = SF.Quadratic()
p0 = fit.guess(y, x=x)
d.lmfit(SF.Quadratic, p0=p0, result=True, header="lmfit")
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:32,代码来源:Quadratic.py

示例5: linspace

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
"""Example of nDimArrhenius Fit."""
from Stoner import Data
import Stoner.Fit as SF
from numpy import linspace, ones_like
from numpy.random import normal

# Make some data
V = linspace(-4, 4, 1000)
I = SF.fowlerNordheim(V, 2500, 3.2, 15.0) + normal(size=len(V), scale=1e-6)
dI = ones_like(V) * 10e-6

d = Data(V, I, dI, setas="xye", column_headers=["Bias", "Current", "Noise"])

d.curve_fit(SF.fowlerNordheim, p0=[2500, 3.2, 15.0], result=True, header="curve_fit")
d.setas = "xyey"
d.plot(fmt=["r.", "b-"])
d.annotate_fit(
    SF.fowlerNordheim,
    x=0.2,
    y=0.6,
    prefix="fowlerNordheim",
    fontdict={"size": "x-small", "color": "blue"},
)

d.setas = "xye"
fit = SF.FowlerNordheim()
p0 = [2500, 5.2, 15.0]
p0 = fit.guess(I, x=V)
for p, v, mi, mx in zip(
    ["A", "phi", "d"], [2500, 3.2, 15.0], [100, 1, 5], [1e4, 20.0, 30.0]
):
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:33,代码来源:FowlerNordheim.py

示例6: linspace

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
"""Test Weak-localisation fitting."""
from Stoner import Data
import Stoner.Fit as SF
from numpy import linspace, ones_like
from numpy.random import normal
from copy import copy

B = linspace(-0.01, 0.01, 100)
params = [1, 1.0e-11, 250]
G = SF.langevin(B, *params) + normal(size=len(B), scale=5e-3)
dG = ones_like(B) * 5e-3
d = Data(B, G, dG, setas="xye", column_headers=["Field $\\mu_0H (T)$", "Moment", "dM"])

func = lambda H, M_s, m: SF.langevin(H, M_s, m, 250)

d.curve_fit(func, p0=copy(params)[0:2], result=True, header="curve_fit")

d.setas = "xye"
fit = SF.Langevin()
p0 = fit.guess(G, x=B)
for p, v in zip(p0, params):
    p0[p].set(v)
    p0[p].max = v * 5
    p0[p].min = 0
    p0[p].vary = p != "T"

d.lmfit(fit, p0=p0, result=True, header="lmfit")


d.setas = "xyeyy"
d.plot(fmt=["r.", "b-", "g-"])
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:33,代码来源:langevin.py

示例7: normal

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
r = normal(loc=3.0, size=250, scale=0.5)

x, y, z = transform(r, q, p)

x += 3.0
y -= 4.0
z += 2.0

# Construct the  DataFile object
d = Data(column_stack((x, y, z)), setas="xyz", filename="Best fit sphere")
d.template.fig_width = 5.2
d.template.fig_height = 5.0  # Square aspect ratio
d.plot_xyz(plotter="scatter")

# curve_fit does the hard work
popt, pcov = d.curve_fit(sphere, (0, 1, 2), zeros_like(d.x))

# This manually constructs the best fit sphere
a, b, c, r = popt
p = linspace(-pi / 2, pi / 2, 16)
q = linspace(-pi, pi, 31)
P, Q = meshgrid(p, q)
R = ones_like(P) * r
x, y, z = transform(R, Q, P)
x += a
y += b
z += c

ax = plt.gca(projection="3d")
ax.plot_surface(x, y, z, rstride=1, cstride=1, color=(1.0, 0.0, 0.0, 0.25), linewidth=0)
plt.draw()
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:33,代码来源:sphere_fit.py

示例8: linspace

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
"""Example of nDimArrhenius Fit."""
from Stoner import Data
import Stoner.Fit as SF
from numpy import linspace, ones_like
from numpy.random import normal

# Make some data
V = linspace(-4, 4, 1001)
I = SF.simmons(V, 2500, 5.2, 15.0) + normal(size=len(V), scale=100e-9)
dI = ones_like(V) * 100e-9

d = Data(V, I, dI, setas="xye", column_headers=["Bias", "Current", "Noise"])

d.curve_fit(SF.simmons, p0=[2500, 5.2, 15.0], result=True, header="curve_fit")
d.setas = "xyey"
d.plot(fmt=["r.", "b-"])
d.annotate_fit(
    SF.simmons,
    x=0.25,
    y=0.25,
    prefix="simmons",
    fontdict={"size": "x-small", "color": "blue"},
)

d.setas = "xye"
fit = SF.Simmons()
p0 = [2500, 5.2, 15.0]
d.lmfit(SF.Simmons, p0=p0, result=True, header="lmfit")
d.setas = "x...y"
d.plot(fmt="g-")
d.annotate_fit(
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:33,代码来源:Simmons.py

示例9: linspace

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
from numpy import linspace, ones_like
from numpy.random import normal

B = linspace(2, 100, 26)
params = [12.5, 0.75, 1e3]
G = SF.fluchsSondheimer(B, *params) + normal(size=len(B), scale=5e-5)
dG = ones_like(B) * 5e-5
d = Data(
    B,
    G,
    dG,
    setas="xye",
    column_headers=["Thickness (nm)", "Conductance", "dConductance"],
)

d.curve_fit(SF.fluchsSondheimer, p0=params, result=True, header="curve_fit")

d.setas = "xye"
d.lmfit(SF.FluchsSondheimer, p0=params, result=True, header="lmfit")

d.setas = "xyeyy"
d.plot(fmt=["r.", "b-", "g-"])

d.annotate_fit(
    SF.fluchsSondheimer, x=0.2, y=0.6, fontdict={"size": "x-small", "color": "blue"}
)
d.annotate_fit(
    SF.FluchsSondheimer,
    x=0.2,
    y=0.4,
    fontdict={"size": "x-small", "color": "green"},
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:33,代码来源:f_s.py

示例10: enumerate

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
result=Data()
for data in fldr: #For each iteration ramp in the Tc data
    row=[data.mean(iterator)]
    data.figure(figsize=(8,4))
    for i,r_col in enumerate(r_cols):
        data.setas(x=t_col,y=r_col)
        data.del_rows(isnan(data.y))

        #Normalise data on y axis between +/- 1
        data.normalise(base=(-1.,1.), replace=True)

        #Swap x and y axes around so that R is x and T is y
        data=~data

        #Curve fit a straight line, using only the central 90% of the resistance transition
        data.curve_fit(linear,bounds=lambda x,r:-threshold<x<threshold,result=True,p0=[7.0,0.0]) #result=True to record fit into metadata

        #Plot the results
        data.setas[-1]="y"
        data.subplot(1,len(r_cols),i+1)
        data.plot(fmt=["k.","r-"])
        data.annotate_fit(linear,x=-1.,y=7.3c,fontsize="small")
        data.title="Ramp {}".format(data[iterator][0])
        row.extend([data["linear:intercept"],data["linear:intercept err"]])
    data.tight_layout()
    result+=np.array(row)

result.column_headers=["Ramp","Sample 4 R","dR","Sample 7 R","dR"]
result.setas="xyeye"
result.plot(fmt=["k.","r."])
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:32,代码来源:Tc_Fit.py

示例11: logspace

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
# Make some data
T = logspace(log10(200), log10(350), 51)
params = (1e16, 0.5, 150)
noise = 0.5
R = vftEquation(T, *params) * normal(size=len(T), scale=noise, loc=1.0)
dR = vftEquation(T, *params) * noise
d = Data(T, R, dR, setas="xy.", column_headers=["T", "Rate"])

# Plot the data points.
d.plot(fmt="r.", label="Data Points")

# Turn on the sigma column (error bars look messy on plot due to logscale)
d.setas[2] = "e"

# Curve_fit on its own
d.curve_fit(vftEquation, p0=params, result=True, header="curve_fit")

# lmfit uses some guesses
p0 = params
d.lmfit(VFTEquation, p0=p0, result=True, header="lmfit")

# Plot these results too
d.setas = "x..yy"
d.plot(fmt=["b-", "g-"])
# Annotate the graph
d.annotate_fit(
    vftEquation,
    x=0.25,
    y=0.35,
    fontdict={"size": "x-small", "color": "blue"},
    mode="eng",
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:33,代码来源:vftEquation.py

示例12: linspace

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
from copy import copy

B = linspace(1e3, 5e4, 51)
params = [2.2, 1e5, 2e2]
G = SF.kittelEquation(B, *params) + normal(size=len(B), scale=5e7)
dG = ones_like(B) * 5e7

d = Data(
    B,
    G,
    dG,
    setas="xye",
    column_headers=["Field $Oe$", r"$\nu (Hz)$", r"\delta $\nu (Hz)$"],
)

d.curve_fit(SF.kittelEquation, p0=copy(params), result=True, header="curve_fit")

fit = SF.KittelEquation()
p0 = fit.guess(G, x=B)

d.lmfit(fit, p0=p0, result=True, header="lmfit")

d.setas = "xyeyy"
d.plot(fmt=["r.", "b-", "g-"])

d.annotate_fit(
    SF.kittelEquation,
    x=0.5,
    y=0.25,
    fontdict={"size": "x-small", "color": "blue"},
    mode="eng",
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:33,代码来源:kittel.py

示例13: linspace

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
"""Example of Arrhenius Fit."""
from Stoner import Data
import Stoner.Fit as SF
from numpy import linspace, ceil, log10, abs
from numpy.random import normal

# Make some data
T = linspace(200, 350, 101)
R = SF.arrhenius(T + normal(size=len(T), scale=3.0, loc=0.0), 1e6, 0.5)
E = 10 ** ceil(log10(abs(R - SF.arrhenius(T, 1e6, 0.5))))
d = Data(T, R, E, setas="xye", column_headers=["T", "Rate"])

# Curve_fit on its own
d.curve_fit(SF.arrhenius, p0=(1e6, 0.5), result=True, header="curve_fit")
d.setas = "xyey"
d.plot(fmt=["r.", "b-"])
d.annotate_fit(
    SF.arrhenius,
    x=0.5,
    y=0.5,
    mode="eng",
    fontdict={"size": "x-small", "color": "blue"},
)

# lmfit using lmfit guesses
fit = SF.Arrhenius()
d.setas = "xye"
d.lmfit(fit, result=True, header="lmfit")
d.setas = "x...y"
d.plot(fmt="g-")
d.annotate_fit(
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:33,代码来源:Arrhenius.py

示例14: linspace

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
"""Example of nDimArrhenius Fit."""
from Stoner import Data
import Stoner.Fit as SF
from numpy import linspace, ones_like
from numpy.random import normal

# Make some data
V = linspace(-10, 10, 1000)
I = SF.bdr(V, 2.5, 3.2, 0.3, 15.0, 1.0) + normal(size=len(V), scale=1.0e-3)
dI = ones_like(V) * 1.0e-3

# Curve fit
d = Data(V, I, dI, setas="xye", column_headers=["Bias", "Current", "Noise"])

d.curve_fit(SF.bdr, p0=[2.5, 3.2, 0.3, 15.0, 1.0], result=True, header="curve_fit")
d.setas = "xyey"
d.plot(fmt=["r.", "b-"])
d.annotate_fit(
    SF.bdr, x=0.6, y=0.05, prefix="bdr", fontdict={"size": "x-small", "color": "blue"}
)

# lmfit
d.setas = "xy"
fit = SF.BDR(missing="drop")
p0 = fit.guess(I, x=V)
for p, v, mi, mx in zip(
    ["A", "phi", "dphi", "d", "mass"],
    [2.500, 3.2, 0.3, 15.0, 1.0],
    [0.100, 1.0, 0.05, 5.0, 0.5],
    [10, 10.0, 2.0, 30.0, 5.0],
):
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:33,代码来源:BDR.py

示例15: linear

# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import curve_fit [as 别名]
"""USe curve_fit to fit a straight line."""
from Stoner import Data


def linear(x, m, c):
    """Straight line function."""
    return m * x + c


d = Data("curve_fit_data.dat", setas="xye")
d.plot(fmt="ro")
fit = d.curve_fit(linear, result=True, replace=False, header="Fit", output="report")
d.setas = "x..y"
d.plot(fmt="b-")
d.annotate_fit(linear)
d.draw()
print(fit.fit_report())
开发者ID:gb119,项目名称:Stoner-PythonCode,代码行数:19,代码来源:curve_fit_line.py


注:本文中的Stoner.Data.curve_fit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。