mirror of
https://github.com/fjosw/pyerrors.git
synced 2025-05-15 03:53:41 +02:00
Merge pull request #146 from fjosw/feat/errorbar_wrapper
Wrapper for errorbar matplotlib method
This commit is contained in:
commit
ef23dd256f
2 changed files with 52 additions and 0 deletions
|
@ -1,8 +1,40 @@
|
|||
import pickle
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
from .obs import Obs
|
||||
|
||||
|
||||
def errorbar(x, y, axes=plt, **kwargs):
|
||||
"""pyerrors wrapper for the errorbars method of matplotlib
|
||||
|
||||
Parameters
|
||||
----------
|
||||
x : list
|
||||
A list of x-values which can be Obs.
|
||||
y : list
|
||||
A list of y-values which can be Obs.
|
||||
axes : (matplotlib.pyplot.axes)
|
||||
The axes to plot on. default is plt.
|
||||
"""
|
||||
val = {}
|
||||
err = {}
|
||||
for name, comp in zip(["x", "y"], [x, y]):
|
||||
if all(isinstance(o, Obs) for o in comp):
|
||||
if not all(hasattr(o, 'e_dvalue') for o in comp):
|
||||
[o.gamma_method() for o in comp]
|
||||
val[name] = [o.value for o in comp]
|
||||
err[name] = [o.dvalue for o in comp]
|
||||
else:
|
||||
val[name] = comp
|
||||
err[name] = None
|
||||
|
||||
if f"{name}err" in kwargs:
|
||||
err[name] = kwargs.get(f"{name}err")
|
||||
kwargs.pop(f"{name}err", None)
|
||||
|
||||
axes.errorbar(val["x"], val["y"], xerr=err["x"], yerr=err["y"], **kwargs)
|
||||
|
||||
|
||||
def dump_object(obj, name, **kwargs):
|
||||
"""Dump object into pickle file.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue