Skip to content

Deprecate support for (n, 1)-shaped error arrays in errorbar(). - #13209

Merged
tacaswell merged 1 commit into
matplotlib:masterfrom
anntzer:errorbar
Feb 23, 2019
Merged

tacaswell merged 1 commit into
matplotlib:masterfrom
anntzer:errorbar

Conversation

@anntzer

@anntzer anntzer commented Jan 17, 2019

Copy link
Copy Markdown
Contributor

errorbar() documents that it supports the following shapes for error
arrays:

- scalar: Symmetric +/- values for all data points.
- shape(N,): Symmetric +/-values for each data point.
- shape(2,N): Separate - and + values for each bar. First row
    contains the lower errors, the second row contains the
    upper errors.
- *None*: No errorbar.

Actually it also supports (N, 1)-shaped arrays (treating them as shape
(N,)), but this support is broken for N=2 at least since Matplotlib
1.5:

N = 2; errorbar(range(N), range(N), np.arange(N).reshape((N, 1)))
...
ValueError: In safezip, len(args[0])=2 but len(args[1])=1

(This works for other values of N.)

Instead of further maintaining code to handle that case, just deprecate
it (no one has apparently noticed the N=2 bug, suggesting that this
(mis)feature is not much used anyways).

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

errorbar() documents that it supports the following shapes for error
arrays:

    - scalar: Symmetric +/- values for all data points.
    - shape(N,): Symmetric +/-values for each data point.
    - shape(2,N): Separate - and + values for each bar. First row
        contains the lower errors, the second row contains the
        upper errors.
    - *None*: No errorbar.

Actually it also supports (N, 1)-shaped arrays (treating them as shape
(N,)), but this support is broken for N=2 *at least* since Matplotlib
1.5:

    N = 2; errorbar(range(N), range(N), np.arange(N).reshape((N, 1)))
    ...
    ValueError: In safezip, len(args[0])=2 but len(args[1])=1

(This works for other values of N.)

Instead of further maintaining code to handle that case, just deprecate
it (no one has apparently noticed the N=2 bug, suggesting that this
(mis)feature is not much used anyways).
@jklymak

jklymak commented Feb 3, 2019

Copy link
Copy Markdown
Member

I think this is OK. Not sure though if there is a community that has Nx1 matrices. I probably did for the first year or so after switching from Matlab...

@anntzer

anntzer commented Feb 3, 2019

Copy link
Copy Markdown
Contributor Author

And then you saw the light? :p
(My experience with dealing with MATLAB code (still on a regular basis) is that half of the people use rows and the other half use columns, so you never know (well plenty of MATLAB functions "correctly" infer the intent by checking for dimensions equal to 1, but still :/).)

@jklymak

jklymak commented Feb 3, 2019

Copy link
Copy Markdown
Member

Well I am now used to the numpy way, but when I took matrix algebra there was a difference between an Nx1 and a 1xN vector that is less explicit in numpy.

@anntzer

anntzer commented Feb 3, 2019

Copy link
Copy Markdown
Contributor Author

In linear algebra, yes, but most often the data we're plotting is not a vector in a linear algebra sense (you're not intending to matrix-multiply it by some matrix, for example); they're just... a list (in the non-technical sense) of data points.
Also, MATLAB will happily plot both 1xn and nx1 data (including one against the other) so if anything it's MATLAB that's sloppier there...

@tacaswell
tacaswell merged commit 5ff12ef into matplotlib:master Feb 23, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Feb 23, 2019
QuLogic added a commit that referenced this pull request Feb 23, 2019
…209-on-v3.1.x

Backport PR #13209 on branch v3.1.x (Deprecate support for (n, 1)-shaped error arrays in errorbar().)
@anntzer
anntzer deleted the errorbar branch February 23, 2019 21:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants