Skip to content

Commit 9c51041

Browse files
committed
DOC: add example for plotting asymmetrical error bars
1 parent acacff3 commit 9c51041

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

doc/source/user_guide/visualization.rst

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

1458-
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.
1459-
14601458
Here is an example of one way to easily plot group means with standard deviations from the raw data.
14611459

14621460
.. ipython:: python
14631461
14641462
# Generate the data
14651463
ix3 = pd.MultiIndex.from_arrays(
14661464
[
1467-
["a", "a", "a", "a", "b", "b", "b", "b"],
1468-
["foo", "foo", "bar", "bar", "foo", "foo", "bar", "bar"],
1465+
["a", "a", "a", "a", "a", "b", "b", "b", "b", "b"],
1466+
["foo", "foo", "foo", "bar", "bar", "foo", "foo", "bar", "bar", "bar"],
14691467
],
14701468
names=["letter", "word"],
14711469
)
14721470
14731471
df3 = pd.DataFrame(
14741472
{
1475-
"data1": [3, 2, 4, 3, 2, 4, 3, 2],
1476-
"data2": [6, 5, 7, 5, 4, 5, 6, 5],
1473+
"data1": [9, 3, 2, 4, 3, 2, 4, 6, 3, 2],
1474+
"data2": [9, 6, 5, 7, 5, 4, 5, 6, 5, 1],
14771475
},
14781476
index=ix3,
14791477
)
@@ -1496,6 +1494,30 @@ Here is an example of one way to easily plot group means with standard deviation
14961494
14971495
plt.close("all")
14981496
1497+
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.
1498+
1499+
Here is an example of one way to plot the min/max range using asymmetrical error bars
1500+
1501+
.. ipython:: python
1502+
1503+
mins = gp3.min()
1504+
maxs = gp3.max()
1505+
mins
1506+
maxs
1507+
1508+
# errors should be positive, and defined in the order of lower, upper
1509+
errors = [[means[c] - mins[c], maxs[c] - means[c]] for c in df3.columns]
1510+
1511+
# Plot
1512+
fig, ax = plt.subplots()
1513+
@savefig errorbar_asymmetrical_example.png
1514+
means.plot.bar(yerr=errors, ax=ax, capsize=4, rot=0);
1515+
1516+
.. ipython:: python
1517+
:suppress:
1518+
1519+
plt.close("all")
1520+
14991521
.. _visualization.table:
15001522

15011523
Plotting tables

0 commit comments

Comments
 (0)