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
importmatplotlib.pyplotaspltdata= {'cats': 10, 'dogs': 20}
# Works as expectedfig, ax=plt.subplots(1)
ax.bar(range(len(data)), data.values())
# Doesn't workfig, ax=plt.subplots(1)
ax.barh(range(len(data)), data.values())
# Works as expectedfig, ax=plt.subplots(1)
ax.barh(range(len(data)), list(data.values()))
plt.show()
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?
Activity
timhoffm commented on Jul 4, 2019
Works on master with Python 3.7.
Please provide your python and matplotlib versions.
Dr-Hughes commented on Jul 4, 2019
(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]:dstansby commented on Jul 15, 2019
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?
jklymak commented on Jul 15, 2019
Yeah this was fixed in 3.1. #13187 I'm going to close...