Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e1985d7

Browse files
committed
Fix issue 10788
1 parent 9faf231 commit e1985d7

4 files changed

Lines changed: 32 additions & 0 deletions

File tree

lib/matplotlib/axes/_axes.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,6 +2344,14 @@ def bar(self, x, height, width=0.8, bottom=None, *, align="center",
23442344
# Fallback if edgecolor == "none".
23452345
itertools.repeat('none'))
23462346

2347+
# Resolve the float - Decimal TypeError
2348+
if (orientation == 'vertical' and x.size > 0
2349+
and isinstance(x[0], Decimal)):
2350+
width = np.array([Decimal(itm) for itm in width])
2351+
elif (orientation == 'horizontal' and y.size > 0
2352+
and isinstance(y[0], Decimal)):
2353+
height = np.array([Decimal(itm) for itm in height])
2354+
23472355
# We will now resolve the alignment and really have
23482356
# left, bottom, width, height vectors
23492357
if align == 'center':
14.3 KB
Loading
10.5 KB
Loading

lib/matplotlib/tests/test_axes.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1506,6 +1506,30 @@ def test_bar_tick_label_multiple_old_alignment():
15061506
align='center')
15071507

15081508

1509+
@image_comparison(
1510+
baseline_images=['bar_decimal_center'],
1511+
extensions=['png'])
1512+
def test_bar_decimal_center():
1513+
# Test vertical, align-center bar chart with Decimal() input
1514+
# No exception should be raised
1515+
ax = plt.gca()
1516+
x = [Decimal(x) for x in [1.5, 8.4, 5.3, 4.2]]
1517+
y = [Decimal(y) for y in [1.1, 2.2, 3.3, 4.4]]
1518+
ax.bar(x, y, align='center')
1519+
1520+
1521+
@image_comparison(
1522+
baseline_images=['barh_decimal_center'],
1523+
extensions=['png'])
1524+
def test_barh_decimal_center():
1525+
# Test horizontal, align-center bar chart with Decimal() input
1526+
# No exception should be raised
1527+
ax = plt.gca()
1528+
x = [Decimal(x) for x in [1.5, 8.4, 5.3, 4.2]]
1529+
y = [Decimal(y) for y in [1.1, 2.2, 3.3, 4.4]]
1530+
ax.barh(x, y, height=[0.5, 0.5, 1, 1], align='center')
1531+
1532+
15091533
def test_bar_color_none_alpha():
15101534
ax = plt.gca()
15111535
rects = ax.bar([1, 2], [2, 4], alpha=0.3, color='none', edgecolor='r')

0 commit comments

Comments
 (0)