FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

axes.bar supports values given as dict_values yet axes.barh throws an error · Issue #14693 · matplotlib/matplotlib · GitHub

Repository navigation

axes.bar supports values given as dict_values yet axes.barh throws an error #14693

Closed

Description

Bug report

Bug summary
Calling axes.barh will throw this error if the height of the bars are given as a dictonary values type
TypeError: unsupported operand type(s) for +: 'int' and 'dict_values'

Code for reproduction

import matplotlib.pyplot as plt

data = {'cats': 10, 'dogs': 20}

# Works as expected
fig, ax = plt.subplots(1)
ax.bar(range(len(data)), data.values())

# Doesn't work
fig, ax = plt.subplots(1)
ax.barh(range(len(data)), data.values())

# Works as expected
fig, ax = plt.subplots(1)
ax.barh(range(len(data)), list(data.values()))

plt.show()

Activity

  1. timhoffm commented on Jul 4, 2019

    Member

    Works on master with Python 3.7.

    Please provide your python and matplotlib versions.

  2. Dr-Hughes commented on Jul 4, 2019

    Author
    • matplotlib version 3.0.2
    • python 3.6.7
    • OSX
    
    (playground)  nathan@x86_64-apple-darwin13  ~ ipython
    Python 3.6.7 |Anaconda, Inc.| (default, Oct 23 2018, 14:01:38)
    Type 'copyright', 'credits' or 'license' for more information
    IPython 7.2.0 -- An enhanced Interactive Python. Type '?' for help.
    
    In [1]: import matplotlib
    
    In [2]: matplotlib.__version__
    Out[2]: '3.0.2'
    
    In [3]: import matplotlib.pyplot as plt
       ...:
       ...: data = {'cats': 10, 'dogs': 20}
       ...:
       ...: # Works as expected
       ...: fig, ax = plt.subplots(1)
       ...: ax.bar(range(len(data)), data.values())
       ...:
       ...: # Doesn't work
       ...: fig, ax = plt.subplots(1)
       ...: ax.barh(range(len(data)), data.values())
       ...:
       ...: # Works as expected
       ...: fig, ax = plt.subplots(1)
       ...: ax.barh(range(len(data)), list(data.values()))
       ...:
       ...: plt.show()
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-3-79a8e56f0f43> in <module>
          9 # Doesn't work
         10 fig, ax = plt.subplots(1)
    ---> 11 ax.barh(range(len(data)), data.values())
         12
         13 # Works as expected
    
    ~/anaconda3/envs/playground/lib/python3.6/site-packages/matplotlib/axes/_axes.py in barh(self, y, width, height, left, align, **kwargs)
       2461         kwargs.setdefault('orientation', 'horizontal')
       2462         patches = self.bar(x=left, height=height, width=width, bottom=y,
    -> 2463                            align=align, **kwargs)
       2464         return patches
       2465
    
    ~/anaconda3/envs/playground/lib/python3.6/site-packages/matplotlib/__init__.py in inner(ax, data, *args, **kwargs)
       1808                         "the Matplotlib list!)" % (label_namer, func.__name__),
       1809                         RuntimeWarning, stacklevel=2)
    -> 1810             return func(ax, *args, **kwargs)
       1811
       1812         inner.__doc__ = _add_data_doc(inner.__doc__,
    
    ~/anaconda3/envs/playground/lib/python3.6/site-packages/matplotlib/axes/_axes.py in bar(self, x, height, width, bottom, align, **kwargs)
       2294                 edgecolor=e,
       2295                 linewidth=lw,
    -> 2296                 label='_nolegend_',
       2297                 )
       2298             r.update(kwargs)
    
    ~/anaconda3/envs/playground/lib/python3.6/site-packages/matplotlib/patches.py in __init__(self, xy, width, height, angle, **kwargs)
        664         self._height = height
        665
    --> 666         self._x1 = self._x0 + self._width
        667         self._y1 = self._y0 + self._height
        668
    
    TypeError: unsupported operand type(s) for +: 'int' and 'dict_values'
    
    In [4]:
    
  3. dstansby commented on Jul 15, 2019

    Member

    It looks like you're using an old version of Matplotlib; the most recent version is 3.1.1. Please could you upgrade to Matplotlib 3.1.1 and let us know if there is still a problem?

  4. jklymak commented on Jul 15, 2019

    Member

    Yeah this was fixed in 3.1. #13187 I'm going to close...

  5. added this to the v3.1.0 milestone on Jul 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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


      Back | FazBrowse Home | New Git URL