Skip to content

TypeError when plotting stacked bar chart with decimal #10788

@GrishaVar

Description

@GrishaVar

Bug report

Bug summary

When plotting bar graph, TypeError exception is raised if values for bar bases are Decimal types.

Code for reproduction

from decimal import Decimal
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
x = list(range(10))
y = [Decimal(x) for x in range(10)]
bar1 = ax.bar(x, y)
bar2 = ax.bar(x, y, bottom=y)

Actual outcome

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/user/dev/venv/lib/python3.6/site-packages/matplotlib/__init__.py", line 1717, in inner
    return func(ax, *args, **kwargs)
  File "/home/user/dev/venv/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 2137, in bar
    self.autoscale_view()
  File "/home/user/dev/venv/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2351, in autoscale_view
    'minposy', self.yaxis, self._ymargin, y_stickies, self.set_ybound)
  File "/home/user/dev/venv/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 2330, in handle_single_axis
    do_lower_margin = not np.any(np.isclose(x0, stickies))
  File "/home/user/dev/venv/lib/python3.6/site-packages/numpy/core/numeric.py", line 2333, in isclose
    yfin = isfinite(y)
TypeError: ufunc 'isfinite' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

Expected outcome

No exception is raised, bar2 line behaves the same way it would if y contained ints or floats.

Matplotlib version

  • Operating system: Ubuntu 16.04
  • Matplotlib version: 2.1.1
  • Matplotlib backend: TkAgg
  • Python version: 3.6.4
  • Decimal version: 1.70

python installed via pyenv, matplotlib via pip

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions