本文整理汇总了Python中Stoner.Data.plot方法的典型用法代码示例。如果您正苦于以下问题:Python Data.plot方法的具体用法?Python Data.plot怎么用?Python Data.plot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Stoner.Data
的用法示例。
在下文中一共展示了Data.plot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Plottest
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
class Plottest(unittest.TestCase):
"""Path to sample Data File"""
datadir=path.join(pth,"sample-data")
def setUp(self):
self.d=Data(path.join(__home__,"..","sample-data","New-XRay-Data.dql"))
def test_set_no_figs(self):
self.assertTrue(Options.no_figs,"Default setting for no_figs option is incorrect.")
Options.no_figs=True
e=self.d.clone
ret=e.plot()
self.assertTrue(ret is None,"Output of Data.plot() was not None when no_figs is True and showfig is not set({})".format(type(ret)))
Options.no_figs=False
e.showfig=False
ret=e.plot()
self.assertTrue(isinstance(ret,Data),"Return value of Data.plot() was not self when Data.showfig=False ({})".format(type(ret)))
e.showfig=True
ret=e.plot()
self.assertTrue(isinstance(ret,Figure),"Return value of Data.plot() was not Figure when Data.showfig=False({})".format(type(ret)))
e.showfig=None
ret=e.plot()
self.assertTrue(ret is None,"Output of Data.plot() was not None when Data.showfig is None ({})".format(type(ret)))
Options.no_figs=True
self.assertTrue(Options.no_figs,"set_option no_figs failed.")
self.d=Data(path.join(__home__,"..","sample-data","New-XRay-Data.dql"))
self.d.showfig=False
ret=self.d.plot()
self.assertTrue(ret is None,"Output of Data.plot() was not None when no_figs is True ({})".format(type(ret)))
Options.no_figs=True
plt.close("all")
def test_template_settings(self):
template=DefaultPlotStyle(font__weight="bold")
self.assertEqual(template["font.weight"],"bold","Setting ytemplate parameter in init failed.")
template(font__weight="normal")
self.assertEqual(template["font.weight"],"normal","Setting ytemplate parameter in call failed.")
template["font.weight"]="bold"
self.assertEqual(template["font.weight"],"bold","Setting ytemplate parameter in setitem failed.")
del template["font.weight"]
self.assertEqual(template["font.weight"],"normal","Resettting template parameter failed.")
keys=sorted([x for x in template])
self.assertEqual(sorted(template.keys()),keys,"template.keys() and template.iter() disagree.")
attrs=[x for x in dir(template) if template._allowed_attr(x)]
length=len(dict(plt.rcParams))+len(attrs)
self.assertEqual(len(template),length,"templa length wrong.")
示例2: linspace
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
"""Example of Quadratic Fit."""
from Stoner import Data
import Stoner.Fit as SF
from numpy import linspace
from numpy.random import normal
import matplotlib.pyplot as plt
# Make some data
x = linspace(-10, 10, 101)
y = SF.quadratic(x + normal(size=len(x), scale=0.1), 4, -2, 11) * normal(
size=len(x), scale=0.05, loc=1.0
)
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(
示例3: Data
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
"""Detect outlying points from a lione."""
from Stoner import Data
from Stoner.Analysis import _poly_outlier
import numpy as np
x = np.linspace(0, 100, 201)
y = 0.01 * x ** 2 + 5 * np.sin(x / 10.0)
i = np.random.randint(len(x) - 20, size=20) + 10
y[i] += np.random.normal(size=len(i), scale=20)
d = Data(np.column_stack((x, y)), column_headers=["x", "y"], setas="xy")
d.plot(fmt="b.", label="raw data")
e = d.clone
e.outlier_detection(window=5, action="delete")
e.plot(fmt="r-", label="Default Outliers removed")
f = d.clone
f.outlier_detection(
window=21, order=3, certainty=2, width=3, action="delete", func=_poly_outlier
)
f.plot(fmt="g-", label="Poly Outliers removed")
g = d.clone
g = g.outlier_detection(
window=21, order=3, certainty=3, width=3, action="delete", func=_poly_outlier
)
g.plot(color="purple", label="Masked outliers")
g = d.clone
e.title = "Outlier detection test"
示例4: Data
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
"""Example plot style using Seaborn plot styling template."""
from Stoner import Data, __home__
from Stoner.plot.formats import SeabornPlotStyle
import os.path as path
filename = path.realpath(path.join(__home__, "..", "doc", "samples", "sample.txt"))
d = Data(
filename,
setas="xyy",
template=SeabornPlotStyle(stylename="dark", context="talk", palette="muted"),
)
d.plot(multiple="y2")
示例5: Data
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
"""Add an inset to a plot."""
from Stoner import Data
p = Data("sample.txt", setas="xy")
p.plot()
p.inset(loc=1, width="50%", height="50%")
p.setas = "x.y"
p.plot()
p.title = "" # Turn off the inset title
示例6: linspace
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
"""Simple use of lmfit to fit data."""
from Stoner import Data
from numpy import linspace, exp, random
# Make some data
x = linspace(0, 10.0, 101)
y = 2 + 4 * exp(-x / 1.7) + random.normal(scale=0.2, size=101)
d = Data(x, y, column_headers=["Time", "Signal"], setas="xy")
d.plot(fmt="ro") # plot our data
func = lambda x, A, B, C: A + B * exp(-x / C)
# Do the fitting and plot the result
fit = d.differential_evolution(
func, result=True, header="Fit", A=1, B=1, C=1, prefix="Model", residuals=True
)
# Reset labels
d.labels = []
# Make nice two panel plot layout
ax = d.subplot2grid((3, 1), (2, 0))
d.setas = "x..y"
d.plot(fmt="g+")
d.title = ""
ax = d.subplot2grid((3, 1), (0, 0), rowspan=2)
d.setas = "xyy"
示例7: Data
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
"""Example of using lmfit to do a bounded fit."""
from Stoner import Data
from Stoner.Fit import StretchedExp
# Load dat and plot
d = Data("lmfit_data.txt", setas="xy")
# Do the fit
d.lmfit(StretchedExp, result=True, header="Fit", prefix="")
# plot
d.setas = "xyy"
d.plot(fmt=["+", "-"])
# Make apretty label using Stoner.Util methods
text = r"$y=A e^{-\left(\frac{x}{x_0}\right)^\beta}$" + "\n"
text += d.annotate_fit(StretchedExp, text_only=True, prefix="")
d.text(6, 4e4, text)
示例8: Data
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
"""Smoothing Data methods example."""
from Stoner import Data
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(9, 6))
d = Data("Noisy_Data.txt", setas="xy")
d.fig = fig
d.plot(color="grey")
# Filter with Savitsky-Golay filter, linear over 7 ppoints
d.SG_Filter(result=True, points=11, header="S-G Filtered")
d.setas = "x.y"
d.plot(lw=2, label="SG Filter")
d.setas = "xy"
# Filter with cubic splines
d.spline(replace=2, order=3, smoothing=4, header="Spline")
d.setas = "x.y"
d.plot(lw=2, label="Spline")
d.setas = "xy"
# Rebin data
d.smooth("hamming", size=0.2, result=True, replace=False, header="Smoothed")
d.setas = "x...y"
d.plot(lw=2, label="Smoooth", color="green")
d.setas = "xy"
d2 = d.bin(bins=100, mode="lin")
d2.fig = d.fig
d2.plot(lw=2, label="Re-binned", color="blue")
d2.xlim(3.5, 6.5)
d2.ylim(-0.2, 0.4)
示例9: exp
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
y = 2 + 4 * exp(-x / 1.7) + random.normal(scale=0.2, size=101)
d = Data(x, y, column_headers=["Time", "Signal"], setas="xy")
# Do the fitting and plot the result
func = lambda x, A, B, C: A + B * exp(-x / C)
fit = d.lmfit(
func, result=True, header="Fit", A=1, B=1, C=1, residuals=True, output="report"
)
# Reset labels
d.labels = []
# Make nice two panel plot layout
ax = d.subplot2grid((3, 1), (2, 0))
d.setas = "x..y"
d.plot(fmt="g+")
d.title = ""
ax = d.subplot2grid((3, 1), (0, 0), rowspan=2)
d.setas = "xyy"
d.plot(fmt=["ro", "b-"])
d.xticklabels = [[]]
d.xlabel = ""
# Annotate plot with fitting parameters
d.annotate_fit(func, prefix="Model", x=7.2, y=3, fontdict={"size": "x-small"})
text = r"$y=A+Be^{-x/C}$" + "\n\n"
d.text(7.2, 3.9, text, fontdict={"size": "x-small"})
d.title = u"Levenberg-Marquardt Fit"
示例10: linspace
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
from Stoner import Data
from numpy import linspace, ones_like, sin, cos, pi
from numpy.random import normal
from Stoner.plot.utils import errorfill
x = linspace(0, 10 * pi, 101)
e = 0.01 * ones_like(x)
y = 0.1 * sin(x) + normal(size=len(x), scale=0.01) + 0.1
e2 = 0.01 * cos(x)
y2 = 0.1 * ones_like(x)
d = Data(
x,
y,
e,
y2,
e2,
column_headers=["$X$", "$Y_+$", r"$\delta Y_+$", "$Y_-$", r"$\delta Y_-$"],
setas="xyeye",
)
a = tuple(d.column_headers[1:3])
b = tuple(d.column_headers[3:5])
d.add(a, b, replace=False)
d.subtract(a, b, replace=False)
d.multiply(a, b, replace=False)
d.divide(a, b, replace=False)
d.diffsum(a, b, replace=False)
d.setas = "xyeyeyeyeyeyeye"
d.plot(multiple="panels", plotter=errorfill, color="red", alpha_fill=0.2)
示例11: logspace
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
"""Example of Arrhenius Fit."""
from Stoner import Data
from Stoner.Fit import vftEquation, VFTEquation
from numpy import logspace, log10
from numpy.random import normal
# 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
示例12: guess_vals
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
@simple_model.guesser
def guess_vals(y, x=None):
"""Should guess parameter values really!"""
m = (y.max() - y.min()) / (x[y.argmax()] - x[y.argmin()])
c = x.mean() * m - y.mean() # return one value per parameter
return [m, c]
# Add a function to sry vonstraints on parameters (optional)
@simple_model.hinter
def hint_parameters():
"""Five some hints about the parameter."""
return {"m": {"max": 10.0, "min": 0.0}, "c": {"max": 5.0, "min": -5.0}}
# Create some x,y data
x = linspace(0, 10, 101)
y = 4.5 * x - 2.3 + normal(scale=0.4, size=len(x))
# Make The Data object
d = Data(x, y, setas="xy", column_headers=["X", "Y"])
# Do the fit
d.lmfit(simple_model, result=True)
# Plot the result
d.setas = "xyy"
d.plot(fmt=["r+", "b-"])
d.title = "Simple Model Fit"
d.annotate_fit(simple_model, x=0.05, y=0.5)
示例13: Data
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
"""Scale data to stitch it together."""
from Stoner import Data
from Stoner.Util import format_error
import matplotlib.pyplot as plt
# Load and plot two sets of data
s1 = Data("Stitch-scan1.txt", setas="xy")
s2 = Data("Stitch-scan2.txt", setas="xy")
s1.plot(label="Set 1")
s2.fig = s1.fig
s2.plot(label="Set 2")
# Stitch scan 2 onto scan 1
s2.stitch(s1)
s2.plot(label="Stictched")
s2.title = "Stictching Example"
# Tidy up the plot by adding annotation fo the stirching co-efficients
labels = ["A", "B", "C"]
txt = []
lead = r"$x'\rightarrow x+A$" + "\n" + r"$y'=\rightarrow By+C$" + "\n"
for l, v, e in zip(
labels, s2["Stitching Coefficients"], s2["Stitching Coeffient Errors"]
):
txt.append(format_error(v, e, latex=True, prefix=l + "="))
plt.text(0.7, 0.65, lead + "\n".join(txt), fontdict={"size": "x-small"})
plt.draw()
示例14: gmean
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
result.data[:, c] = (resfldr[1][:, c] + resfldr[0][:, c]) / 2.0
for c in [1, 3, 5, 7]:
result.data[:, c] = gmean((resfldr[0][:, c], resfldr[1][:, c]), axis=0)
# Doing the Kittel fit with an orthogonal distance regression as we have x errors not y errors
p0 = [2, 200e3, 10e3] # Some sensible guesses
result.lmfit(
Inverse_Kittel, p0=p0, result=True, header="Kittel Fit", output="report"
)
result.setas[-1] = "y"
result.template.yformatter = TexEngFormatter
result.template.xformatter = TexEngFormatter
result.labels = None
result.figure(figsize=(6, 8))
result.subplot(211)
result.plot(fmt=["r.", "b-"])
result.annotate_fit(Inverse_Kittel, x=7e9, y=1e5, fontdict={"size": 8})
result.ylabel = "$H_{res} \\mathrm{(Am^{-1})}$"
result.title = "Inverse Kittel Fit"
# Get alpha
result.subplot(212)
result.setas(y="Delta_H", e="Delta_H.stderr", x="Freq")
result.y /= mu_0
result.e /= mu_0
result.lmfit(Linear, result=True, header="Width", output="report")
result.setas[-1] = "y"
result.plot(fmt=["r.", "b-"])
result.annotate_fit(Linear, x=5.5e9, y=2.8e3, fontdict={"size": 8})
示例15: Data
# 需要导入模块: from Stoner import Data [as 别名]
# 或者: from Stoner.Data import plot [as 别名]
"""Double y axis plot."""
from Stoner import Data
p = Data("sample.txt", setas="xyy")
# Quick plot
p.plot(multiple="y2")