Skip to content

Fix asymmetric error bars for series (closes #9536) #12046

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

Closed
wants to merge 1 commit into from

Conversation

kleingeist
Copy link

closes #9536

This fix is for handling asymmetric error bars for series.
It adapts to the syntax for
http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.errorbar
where a sequence of shape 2xN is expected in case of asymmetric error bars.

If a single series is to be plotted and the error sequence is of shape 2xN
it will be used as asymmetric error bars.
Previously a 2xN error sequence was assumed to be 2 symmetric error sequences
for 2 series. Thus in the end only the first error sequence was used.

@jreback jreback added the Visualization plotting label Jan 15, 2016
@jreback
Copy link
Contributor

jreback commented Jan 15, 2016

  • does this have a related issue?
  • needs a whatsnew note. is this an APi change?
  • does the do-string need updating?
  • needs some tests

@kleingeist
Copy link
Author

Yes, as mentioned in the commit subject and the title this is associated to issue #9536 .

I am not sure what you mean by "needs a whatsnew note" and undecided if i would call it an API change. The current doc [0] states "Asymmetrical error bars are also supported, however raw error values must be provided in this case. For a M length Series, a Mx2 array should be provided indicating lower and upper (or left and right) errors." which is, as noted in #9536 not working. Still, after this commit the documented syntax is changed from 2xM to Mx2 as is the format matplotlib expects asymmetrical error bars. So probably it makes sense to document it as an API change.
I did add some more documentation on the docstring and the undocumented feature of providing a single number to use for every error bar.
I also did add a test.

[0] http://pandas.pydata.org/pandas-docs/stable/visualization.html#visualization-errorbars
[1] http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.errorbar

@@ -1419,10 +1419,16 @@ def _parse_errorbars(self, label, err):
Error bars can be specified in several ways:
Series: the user provides a pandas.Series object of the same
length as the data
ndarray: provides a np.ndarray of the same length as the data
list_like (list/tuple/ndarray/iterator): either a list like of the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you are changing this, then pls provide tests for what you are adding.

@jreback
Copy link
Contributor

jreback commented Jan 19, 2016

whatsnew note in doc/source/whatsnew/v0.18.0.txt under API changes

@jreback jreback added the Bug label Jan 19, 2016
@jreback
Copy link
Contributor

jreback commented Jan 24, 2016

@kleingeist can you update

@kleingeist
Copy link
Author

@jreback sorry, i had a lot to do last week and couldn't look into it.
i tried to adapt the changes to your requests and did add test and a note in the whatsnew under "Api -> Other enhancements". I hope this is the right place?

Regarding your line comment

I would like to see a more general soln here, rather than specific ndim checking.

i have no idea how to do that. The fix is for one specific case: Only one Series to plot, with error bars given as raw values in an array of shape 2xN. I don't know to come up for a more general solution for this special case.
The more general solution is available in the form of Mx2xN arrays which can be already used for plotting asymmetric error bars for M multiple values of dataframes.
For Series it is already possible to use this general solution by providing a 1x2xN shaped array for asymmetric error bars.
But i would argue this is counterintuitive as the matplotlib api uses the 2xN format and i, as well as others #9536, http://stackoverflow.com/q/26793758/4262879 did expect that the pandas API would work the same.

@@ -152,6 +152,7 @@ Other enhancements
- ``Series`` gained an ``is_unique`` attribute (:issue:`11946`)
- ``DataFrame.quantile`` and ``Series.quantile`` now accept ``interpolation`` keyword (:issue:`10174`).
- ``DataFrame.select_dtypes`` now allows the ``np.float16`` typecode (:issue:`11990`)
- ``Series.plot`` allows now asymmetric error bars in the shape of 2xN array (:issue:`9536`)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to 0.18.1

@jreback
Copy link
Contributor

jreback commented Mar 12, 2016

can you rebase/update

@kleingeist
Copy link
Author

@jreback

This fix is for handling asymmetric error bars for series.
It adapts to the syntax for
http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.errorbar
where a sequence of shape 2xN is expected in case of asymmetric error bars.

If a single series is to be plotted and the error sequence is of shape 2xN
it will be used as asymmetric error bars.
Previously a 2xN error sequence was assumed to be 2 symmetric error sequences
for 2 series. Thus in the end only the first error sequence was used.

This commit improves the docstring of the `_parse_errorbars` method as well
as the general pandas doc on error bars.
@@ -60,12 +60,13 @@ Other Enhancements
- ``pd.read_msgpack()`` now always gives writeable ndarrays even when compression is used (:issue:`12359`).
- ``Index.take`` now handles ``allow_fill`` and ``fill_value`` consistently (:issue:`12631`)

.. ipython:: python
.. ipython:: python
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like these changes slipped in accidentally? Till line 67.

@kleingeist
Copy link
Author

@TomAugspurger i thought the .rst format would work like markdown, where i would have had to indent the code block if i would like it to be a child of a list-item. The newly indented code example is associated with the list item above, and since i wanted to add an item to the same list i indented the code block as i would have in markdown.

I would really like to give up this PullRequest, as i thought i'd submit a short patch for an issue i encountered, but don't want to study the documentation of .rst files. Please feel free to fork the branch i started and adapt everything to your project guidelines / doc formats.

Or drop the PR at all. I am fine with the workaround i found while debugging the error (adding another pair of parenthesis/ dimension to the 2xN asymmetric error bars list.

@jreback
Copy link
Contributor

jreback commented May 7, 2016

closing as stale. but please reopen if you'd like to continue work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Asymmetric error bars are not supported for series (only dataframes)
3 participants