Shortcuts

error_bar

alpsplot.utils.group_err_bar(x, y)[source]

Group (x, y) to be a dict. y_dict[x0] = [y0, y1, ...].

Parameters:
Returns:

dict[float, numpy.ndarray] – The result dict.

Example:
>>> import numpy as np
>>> from alpsplot.utils import group_err_bar
>>>
>>> x = np.array([1., 2., 3.] * 2)
>>> x
array([1., 2., 3., 1., 2., 3.])
>>> y = np.arange(6.0)
>>> y
array([0., 1., 2., 3., 4., 5.])
>>> group_err_bar(x, y)
{1.0: array([0., 3.]), 2.0: array([1., 4.]), 3.0: array([2., 5.])}
alpsplot.utils.flatten_err_bar(y_dict)[source]

Flatten y_dict to be data list (x, y).

Parameters:

y_dict (dict[float, numpy.ndarray]) – The dict to flatten.

Returns:

(numpy.ndarray, numpy.ndarray) – The x, y array.

Example:
>>> import numpy as np
>>> from alpsplot.utils import group_err_bar, flatten_err_bar
>>>
>>> x = np.array([1., 2., 3.] * 2)
>>> x
array([1., 2., 3., 1., 2., 3.])
>>> y = np.arange(6.0)
>>> y
array([0., 1., 2., 3., 4., 5.])
>>> y_dict = group_err_bar(x, y)
>>> y_dict
{1.0: array([0., 3.]), 2.0: array([1., 4.]), 3.0: array([2., 5.])}
>>> flatten_err_bar(y_dict)
(array([1., 1., 2., 2., 3., 3.]), array([0., 3., 1., 4., 2., 5.]))
alpsplot.utils.adjust_err_bar(y_dict, mean=None, std=None)[source]

Adjust y_dict with mean and std.

std[i]y_dict[xi].std()(y_dict[xi]y_dict[xi].mean())+mean[i]\frac{std[i]}{y\_dict[x_i].std()} \left(y\_dict[x_i] - y\_dict[x_i].mean()\right) + mean[i]
Parameters:
  • y_dict (dict[float, numpy.ndarray]) – The dict to adjust.

  • mean (numpy.ndarray]) – The new mean values for y_dict. None means keeping the original mean values [y_dict[x].mean() for x in y_dict.keys()]. Defaults to None.

  • std (numpy.ndarray]) – The new std values for y_dict. None means keeping the original std values [y_dict[x].std() for x in y_dict.keys()]. Defaults to None.

Returns:

dict[float, numpy.ndarray] – The new dict.

Example:
>>> import numpy as np
>>> from alpsplot.utils import group_err_bar, adjust_err_bar
>>>
>>> x = np.array([1., 2., 3.] * 2)
>>> x
array([1., 2., 3., 1., 2., 3.])
>>> y = np.arange(6.0)
>>> y
array([0., 1., 2., 3., 4., 5.])
>>> y_dict = group_err_bar(x, y)
>>> y_dict
{1.0: array([0., 3.]), 2.0: array([1., 4.]), 3.0: array([2., 5.])}
>>> adjust_err_bar(y_dict)
{1.0: array([0., 3.]), 2.0: array([1., 4.]), 3.0: array([2., 5.])}
>>> adjust_err_bar(y_dict, mean=0.3, std=0.4)
{1.0: array([-0.1,  0.7]), 2.0: array([-0.1,  0.7]), 3.0: array([-0.1,  0.7])}
>>> adjust_err_bar(y_dict, mean=np.zeros(3), std=np.ones(3))
{1.0: array([-1.,  1.]), 2.0: array([-1.,  1.]), 3.0: array([-1.,  1.])}
alpsplot.utils.normalize_err_bar(x, y)[source]

Normalize x and y into range [0, 1].

each x might correspond to multiple y values and therefore generate an error band on y-axis. The mean of y is normalized into [0, 1].

Parameters:
Returns:

(numpy.ndarray, numpy.ndarray) – The normalized x, y array.

Example:
>>> import numpy as np
>>> from alpsplot.utils import group_err_bar, normalize_err_bar
>>>
>>> x = np.array([1., 2., 3.] * 2)
>>> x
array([1., 2., 3., 1., 2., 3.])
>>> y = np.arange(6.0)
>>> y
array([0., 1., 2., 3., 4., 5.])
>>> normalize_err_bar(x, y)
(array([0. , 0. , 0.5, 0.5, 1. , 1. ]), array([-1.5,  1.5, -1. ,  2. , -0.5,  2.5]))
alpsplot.utils.avg_smooth_err_bar(x, y, window=3, **kwargs)[source]

Average smooth x and y using window size window.

Each x might correspond to multiple y values and therefore generate an error band on y-axis. The mean of y is smoothed.

Parameters:
Returns:

(numpy.ndarray, numpy.ndarray) – The smoothed x, y array.

Example:
>>> import numpy as np
>>> from alpsplot.utils import group_err_bar, avg_smooth_err_bar
>>>
>>> x = np.array([1., 2., 3.] * 2)
>>> x
array([1., 2., 3., 1., 2., 3.])
>>> y = np.arange(6.0)
>>> y
array([0., 1., 2., 3., 4., 5.])
>>> avg_smooth_err_bar(x, y)
(array([1., 1., 2., 2., 3., 3.]), array([0.33333333, 3.33333333, 1.        , 4.        , 1.66666667, 4.66666667]))
>>> avg_smooth_err_bar(x, y, window=5)
(array([1., 1., 2., 2., 3., 3.]), array([0.6, 3.6, 1. , 4. , 1.4, 4.4]))

Docs

Access comprehensive developer documentation for AlpsPlot

View Docs