Skip to content

Using "drawstyle" raises AttributeError in errorbar, when yerr is specified. #19879

Closed
@matteobachetti

Description

@matteobachetti

Bug report

Hello maintainers!
Starting from 3.4.1, I'm having failures in CI related to a failure in errorbar (e.g. https://github.com/StingraySoftware/HENDRICS/runs/2267849177?check_suite_focus=true). Until at least 3.3.4, this code line

plt.errorbar(x, profile, yerr=profile_err, drawstyle="steps-mid")

used to work, now it doesn't. After a little debugging, I realized that yerr and drawstyle seem incompatible. I write a MWE below

Code for reproduction

In [1]: import numpy as np

In [2]: import matplotlib.pyplot as plt

In [3]: x = np.arange(10)

In [4]: y = np.random.poisson(100, 10)

In [5]: plt.errorbar(x, y, drawstyle="steps-mid")
Out[5]: <ErrorbarContainer object of 3 artists>

In [6]: plt.show()  # It works

In [7]: yerr = np.zeros_like(y) + 10

In [8]: plt.errorbar(x, y, yerr=yerr, drawstyle="steps-mid")
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-8-a70dfad4683c> in <module>
----> 1 plt.errorbar(x, y, yerr=yerr, drawstyle="steps-mid")

~/anaconda3/envs/py38/lib/python3.8/site-packages/matplotlib/pyplot.py in errorbar(x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, data, **kwargs)
   2739         uplims=False, xlolims=False, xuplims=False, errorevery=1,
   2740         capthick=None, *, data=None, **kwargs):
-> 2741     return gca().errorbar(
   2742         x, y, yerr=yerr, xerr=xerr, fmt=fmt, ecolor=ecolor,
   2743         elinewidth=elinewidth, capsize=capsize, barsabove=barsabove,

~/anaconda3/envs/py38/lib/python3.8/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
   1350     def inner(ax, *args, data=None, **kwargs):
   1351         if data is None:
-> 1352             return func(ax, *map(sanitize_sequence, args), **kwargs)
   1353 
   1354         bound = new_sig.bind(ax, *args, **kwargs)

~/anaconda3/envs/py38/lib/python3.8/site-packages/matplotlib/axes/_axes.py in errorbar(self, x, y, yerr, xerr, fmt, ecolor, elinewidth, capsize, barsabove, lolims, uplims, xlolims, xuplims, errorevery, capthick, **kwargs)
   3496         if yerr is not None:
   3497             lower, upper = extract_err('y', yerr, y, lolims, uplims)
-> 3498             barcols.append(self.vlines(
   3499                 *apply_mask([x, lower, upper], everymask), **eb_lines_style))
   3500             # select points without upper/lower limits in y and

~/anaconda3/envs/py38/lib/python3.8/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
   1350     def inner(ax, *args, data=None, **kwargs):
   1351         if data is None:
-> 1352             return func(ax, *map(sanitize_sequence, args), **kwargs)
   1353 
   1354         bound = new_sig.bind(ax, *args, **kwargs)

~/anaconda3/envs/py38/lib/python3.8/site-packages/matplotlib/axes/_axes.py in vlines(self, x, ymin, ymax, colors, linestyles, label, **kwargs)
   1118                                      linestyles=linestyles, label=label)
   1119         self.add_collection(lines, autolim=False)
-> 1120         lines.update(kwargs)
   1121 
   1122         if len(x) > 0:

~/anaconda3/envs/py38/lib/python3.8/site-packages/matplotlib/artist.py in update(self, props)
   1060                     func = getattr(self, f"set_{k}", None)
   1061                     if not callable(func):
-> 1062                         raise AttributeError(f"{type(self).__name__!r} object "
   1063                                              f"has no property {k!r}")
   1064                     ret.append(func(v))

AttributeError: 'LineCollection' object has no property 'drawstyle'

Matplotlib version

  • Operating system: Mac OS, Linux, Windows (all tested on CI)
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): 3.4.1
  • Matplotlib backend (print(matplotlib.get_backend())): various
  • Python version: 3.8
  • Jupyter version (if applicable):
  • Other libraries:

I installed matplotlib from pip (on CI) and conda (my laptop)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions