Skip to content

Commit c5bb83f

Browse files
mortadaJulianWgs
authored andcommitted
DOC: add example for plotting asymmetrical error bars (pandas-dev#41035)
1 parent 5db5ca7 commit c5bb83f

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

doc/source/user_guide/visualization.rst

+26-6
Original file line numberDiff line numberDiff line change
@@ -1458,25 +1458,23 @@ Horizontal and vertical error bars can be supplied to the ``xerr`` and ``yerr``
14581458
* As a ``str`` indicating which of the columns of plotting :class:`DataFrame` contain the error values.
14591459
* As raw values (``list``, ``tuple``, or ``np.ndarray``). Must be the same length as the plotting :class:`DataFrame`/:class:`Series`.
14601460

1461-
Asymmetrical error bars are also supported, however raw error values must be provided in this case. For a ``N`` length :class:`Series`, a ``2xN`` array should be provided indicating lower and upper (or left and right) errors. For a ``MxN`` :class:`DataFrame`, asymmetrical errors should be in a ``Mx2xN`` array.
1462-
14631461
Here is an example of one way to easily plot group means with standard deviations from the raw data.
14641462

14651463
.. ipython:: python
14661464
14671465
# Generate the data
14681466
ix3 = pd.MultiIndex.from_arrays(
14691467
[
1470-
["a", "a", "a", "a", "b", "b", "b", "b"],
1471-
["foo", "foo", "bar", "bar", "foo", "foo", "bar", "bar"],
1468+
["a", "a", "a", "a", "a", "b", "b", "b", "b", "b"],
1469+
["foo", "foo", "foo", "bar", "bar", "foo", "foo", "bar", "bar", "bar"],
14721470
],
14731471
names=["letter", "word"],
14741472
)
14751473
14761474
df3 = pd.DataFrame(
14771475
{
1478-
"data1": [3, 2, 4, 3, 2, 4, 3, 2],
1479-
"data2": [6, 5, 7, 5, 4, 5, 6, 5],
1476+
"data1": [9, 3, 2, 4, 3, 2, 4, 6, 3, 2],
1477+
"data2": [9, 6, 5, 7, 5, 4, 5, 6, 5, 1],
14801478
},
14811479
index=ix3,
14821480
)
@@ -1499,6 +1497,28 @@ Here is an example of one way to easily plot group means with standard deviation
14991497
15001498
plt.close("all")
15011499
1500+
Asymmetrical error bars are also supported, however raw error values must be provided in this case. For a ``N`` length :class:`Series`, a ``2xN`` array should be provided indicating lower and upper (or left and right) errors. For a ``MxN`` :class:`DataFrame`, asymmetrical errors should be in a ``Mx2xN`` array.
1501+
1502+
Here is an example of one way to plot the min/max range using asymmetrical error bars.
1503+
1504+
.. ipython:: python
1505+
1506+
mins = gp3.min()
1507+
maxs = gp3.max()
1508+
1509+
# errors should be positive, and defined in the order of lower, upper
1510+
errors = [[means[c] - mins[c], maxs[c] - means[c]] for c in df3.columns]
1511+
1512+
# Plot
1513+
fig, ax = plt.subplots()
1514+
@savefig errorbar_asymmetrical_example.png
1515+
means.plot.bar(yerr=errors, ax=ax, capsize=4, rot=0);
1516+
1517+
.. ipython:: python
1518+
:suppress:
1519+
1520+
plt.close("all")
1521+
15021522
.. _visualization.table:
15031523

15041524
Plotting tables

0 commit comments

Comments
 (0)