"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"hv.extension('plotly')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"``ErrorBars`` provide a visual indicator for the variability of the plotted data on a graph. They are usually applied on top of other plots such as scatter, curve or bar plots to indicate the variability in each sample. \n",
"\n",
"``ErrorBars`` may be used to represent symmetric error or asymmetric error. An ``ErrorBars`` Element must have one key dimensions representing the samples along the x-axis and two or three value dimensions representing the value of the sample and positive and negative error values associated with that sample or x-axis. See the [Tabular Datasets](../../../user_guide/08-Tabular_Datasets.ipynb) user guide for supported data formats, which include arrays, pandas dataframes and dictionaries of arrays."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Symmetric error\n",
"\n",
"By default the ``ErrorBars`` Element accepts x- and y-coordinates along with a symmetric error value along y-axis:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"np.random.seed(7)\n",
"errors = [(0.1*i, np.sin(0.1*i), np.random.rand()/2) for i in np.linspace(0, 100, 11)]\n",
"hv.Curve(errors) * hv.ErrorBars(errors)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Asymmetric error"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"``ErrorBars`` is a set of x-/y-coordinates with associated error values along y-axis. Error values may be either symmetric or asymmetric, and thus can be supplied as an Nx3 or Nx4 array (or any of the alternative constructors Chart Elements allow)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"errors = [(0.1*i, np.sin(0.1*i), np.random.rand()/2, np.random.rand()/4) for i in np.linspace(0, 100, 11)]\n",
"hv.Curve(errors) * hv.ErrorBars(errors, vdims=['y', 'yerrneg', 'yerrpos'])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Errors along x-axis"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"``ErrorBars`` can be a set of a set of x-/y-coordinates with associated error values along x-axis. The parameter `horizontal`, when set to `True`, will set supplied errors along x-axis instead of y-axis."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"errors = [(0.1*i, np.sin(0.1*i), np.random.rand()/2) for i in np.linspace(0, 100, 11)]\n",
"hv.Curve(errors) * hv.ErrorBars(errors, horizontal=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Errors along x and y axes"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Two `ErrorBars` with orthogonal errors can be composed together to give x and y errorbars"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"yerrors = [(0.1*i, np.sin(0.1*i), np.random.rand()/2, np.random.rand()/4) for i in np.linspace(0, 100, 11)]\n",
"xerrors = [(0.1*i, np.sin(0.1*i), np.random.rand()/2, np.random.rand()/4) for i in np.linspace(0, 100, 11)]\n",
"\n",
"(hv.Curve(yerrors)\n",
" * hv.ErrorBars(yerrors, vdims=['y', 'yerrneg', 'yerrpos'])\n",
" * hv.ErrorBars(xerrors, vdims=['y', 'xerrneg', 'xerrpos'], horizontal=True)\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"For full documentation and the available style and plot options, use ``hv.help(hv.ErrorBars).``"
]
}
],
"metadata": {
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}