{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Errorbar\n\nDemo of errorbar function with different ways of specifying error bars.\n\nErrors can be specified as a constant value (as shown in ``errorbar_demo.py``),\nor as demonstrated in this example, they can be specified by an ``N x 1`` or ``2 x N``,\nwhere ``N`` is the number of data points.\n\n**N x 1**:\n Error varies for each point, but the error values are symmetric (i.e. the\n lower and upper values are equal).\n\n**2 x N**:\n Error varies for each point, and the lower and upper limits (in that order)\n are different (asymmetric case)\n\nIn addition, this example demonstrates how to use log scale with errorbar.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np\nimport matplotlib.pyplot as plt\n\n# example data\nx = np.arange(0.1, 4, 0.5)\ny = np.exp(-x)\n\n# example error bar values that vary with x-position\nerror = 0.1 + 0.2 * x\n\n# error bar values w/ different -/+ errors\nlower_error = 0.4 * error\nupper_error = error\nasymmetric_error = [lower_error, upper_error]\n\nfig, (ax0, ax1) = plt.subplots(nrows=2, sharex=True)\nax0.errorbar(x, y, yerr=error, fmt=\"-o\")\nax0.set_title(\"variable, symmetric error\")\n\nax1.errorbar(x, y, xerr=asymmetric_error, fmt=\"o\")\nax1.set_title(\"variable, asymmetric error\")\nax1.set_yscale(\"log\")\nplt.show()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.10" } }, "nbformat": 4, "nbformat_minor": 0 }