Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Errorbar plot with first value masked raises TypeError #9241

Copy link
Copy link
Closed
@astromancer

Description

@astromancer
Issue body actions

Bug report

Bug summary

plt.errorbar borks with `TypeError' when the first element of the error array is masked. This does not seem to happen for other masked elements.

Code for reproduction

x, y, e = np.random.randn(3, 100)
e = np.ma.array(e)
e[0] = np.ma.masked
plt.errorbar(x, y, e)

Actual outcome

Here's the traceback

TypeError                                 Traceback (most recent call last)
<ipython-input-127-b58bf89a7e18> in <module>()
      3 e[0] = np.ma.masked
      4 
----> 5 plt.errorbar(x, y, e)

/usr/local/lib/python3.5/dist-packages/matplotlib-2.1.0rc1+104.g479242506-py3.5-linux-x86_64.egg/matplotlib/pyplot.py in errorbar(x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, hold, data, **kwargs)
   2850                           xlolims=xlolims, xuplims=xuplims,
   2851                           errorevery=errorevery, capthick=capthick, data=data,
-> 2852                           **kwargs)
   2853     finally:
   2854         ax._hold = washold

/usr/local/lib/python3.5/dist-packages/matplotlib-2.1.0rc1+104.g479242506-py3.5-linux-x86_64.egg/matplotlib/__init__.py in inner(ax, *args, **kwargs)
   1708                     warnings.warn(msg % (label_namer, func.__name__),
   1709                                   RuntimeWarning, stacklevel=2)
-> 1710             return func(ax, *args, **kwargs)
   1711         pre_doc = inner.__doc__
   1712         if pre_doc is None:

/usr/local/lib/python3.5/dist-packages/matplotlib-2.1.0rc1+104.g479242506-py3.5-linux-x86_64.egg/matplotlib/axes/_axes.py in errorbar(self, x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, **kwargs)
   3082 
   3083         if yerr is not None:
-> 3084             lower, upper = extract_err(yerr, y)
   3085             # select points without upper/lower limits in y and
   3086             # draw normal errorbars for these points

/usr/local/lib/python3.5/dist-packages/matplotlib-2.1.0rc1+104.g479242506-py3.5-linux-x86_64.egg/matplotlib/axes/_axes.py in extract_err(err, data)
   3022                 fe = safe_first_element(err)
   3023                 if (len(err) != len(data)
-> 3024                         or isinstance(fe, Sized) and len(fe) > 1):
   3025                     raise ValueError("err must be [ scalar | N, Nx1 "
   3026                                      "or 2xN array-like ]")

TypeError: len() of unsized object

Expected outcome

An errorbar plot with the first plot point errorbar being invisible, similar to what is produced when any other errorbar point is masked. The problem seems to stem from the fact that cbook.safe_first_element returns a np.ma.masked value, which for some reason is considered a Sized object: isinstance(np.ma.masked, Sized) returns True. A possible fix would be to prevent cbook.safe_first_element from returning masked values.

Matplotlib version

  • Operating System: Ubuntu 17.04
  • Matplotlib Version: 2.1.0rc1+104.g479242506
  • Python Version: 3.5

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.