Skip to content

DOC: add example for plotting asymmetrical error bars #41035

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 21, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 26 additions & 6 deletions doc/source/user_guide/visualization.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1455,25 +1455,23 @@ Horizontal and vertical error bars can be supplied to the ``xerr`` and ``yerr``
* As a ``str`` indicating which of the columns of plotting :class:`DataFrame` contain the error values.
* As raw values (``list``, ``tuple``, or ``np.ndarray``). Must be the same length as the plotting :class:`DataFrame`/:class:`Series`.

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.

Here is an example of one way to easily plot group means with standard deviations from the raw data.

.. ipython:: python

# Generate the data
ix3 = pd.MultiIndex.from_arrays(
[
["a", "a", "a", "a", "b", "b", "b", "b"],
["foo", "foo", "bar", "bar", "foo", "foo", "bar", "bar"],
["a", "a", "a", "a", "a", "b", "b", "b", "b", "b"],
["foo", "foo", "foo", "bar", "bar", "foo", "foo", "bar", "bar", "bar"],
],
names=["letter", "word"],
)

df3 = pd.DataFrame(
{
"data1": [3, 2, 4, 3, 2, 4, 3, 2],
"data2": [6, 5, 7, 5, 4, 5, 6, 5],
"data1": [9, 3, 2, 4, 3, 2, 4, 6, 3, 2],
"data2": [9, 6, 5, 7, 5, 4, 5, 6, 5, 1],
},
index=ix3,
)
Expand All @@ -1496,6 +1494,28 @@ Here is an example of one way to easily plot group means with standard deviation

plt.close("all")

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.

Here is an example of one way to plot the min/max range using asymmetrical error bars.

.. ipython:: python

mins = gp3.min()
maxs = gp3.max()

# errors should be positive, and defined in the order of lower, upper
errors = [[means[c] - mins[c], maxs[c] - means[c]] for c in df3.columns]

# Plot
fig, ax = plt.subplots()
@savefig errorbar_asymmetrical_example.png
means.plot.bar(yerr=errors, ax=ax, capsize=4, rot=0);

.. ipython:: python
:suppress:

plt.close("all")

.. _visualization.table:

Plotting tables
Expand Down