|
11 | 11 | import numpy as np
|
12 | 12 | from numpy import ma
|
13 | 13 | from cycler import cycler
|
| 14 | +from decimal import Decimal |
14 | 15 | import pytest
|
15 | 16 |
|
16 | 17 | import warnings
|
@@ -1477,6 +1478,62 @@ def test_bar_tick_label_multiple_old_alignment():
|
1477 | 1478 | align='center')
|
1478 | 1479 |
|
1479 | 1480 |
|
| 1481 | +@check_figures_equal(extensions=["png"]) |
| 1482 | +def test_bar_decimal_center(fig_test, fig_ref): |
| 1483 | + ax = fig_test.subplots() |
| 1484 | + x0 = [1.5, 8.4, 5.3, 4.2] |
| 1485 | + y0 = [1.1, 2.2, 3.3, 4.4] |
| 1486 | + x = [Decimal(x) for x in x0] |
| 1487 | + y = [Decimal(y) for y in y0] |
| 1488 | + # Test image - vertical, align-center bar chart with Decimal() input |
| 1489 | + ax.bar(x, y, align='center') |
| 1490 | + # Reference image |
| 1491 | + ax = fig_ref.subplots() |
| 1492 | + ax.bar(x0, y0, align='center') |
| 1493 | + |
| 1494 | + |
| 1495 | +@check_figures_equal(extensions=["png"]) |
| 1496 | +def test_barh_decimal_center(fig_test, fig_ref): |
| 1497 | + ax = fig_test.subplots() |
| 1498 | + x0 = [1.5, 8.4, 5.3, 4.2] |
| 1499 | + y0 = [1.1, 2.2, 3.3, 4.4] |
| 1500 | + x = [Decimal(x) for x in x0] |
| 1501 | + y = [Decimal(y) for y in y0] |
| 1502 | + # Test image - horizontal, align-center bar chart with Decimal() input |
| 1503 | + ax.barh(x, y, height=[0.5, 0.5, 1, 1], align='center') |
| 1504 | + # Reference image |
| 1505 | + ax = fig_ref.subplots() |
| 1506 | + ax.barh(x0, y0, height=[0.5, 0.5, 1, 1], align='center') |
| 1507 | + |
| 1508 | + |
| 1509 | +@check_figures_equal(extensions=["png"]) |
| 1510 | +def test_bar_decimal_width(fig_test, fig_ref): |
| 1511 | + x = [1.5, 8.4, 5.3, 4.2] |
| 1512 | + y = [1.1, 2.2, 3.3, 4.4] |
| 1513 | + w0 = [0.7, 1.45, 1, 2] |
| 1514 | + w = [Decimal(i) for i in w0] |
| 1515 | + # Test image - vertical bar chart with Decimal() width |
| 1516 | + ax = fig_test.subplots() |
| 1517 | + ax.bar(x, y, width=w, align='center') |
| 1518 | + # Reference image |
| 1519 | + ax = fig_ref.subplots() |
| 1520 | + ax.bar(x, y, width=w0, align='center') |
| 1521 | + |
| 1522 | + |
| 1523 | +@check_figures_equal(extensions=["png"]) |
| 1524 | +def test_barh_decimal_height(fig_test, fig_ref): |
| 1525 | + x = [1.5, 8.4, 5.3, 4.2] |
| 1526 | + y = [1.1, 2.2, 3.3, 4.4] |
| 1527 | + h0 = [0.7, 1.45, 1, 2] |
| 1528 | + h = [Decimal(i) for i in h0] |
| 1529 | + # Test image - horizontal bar chart with Decimal() height |
| 1530 | + ax = fig_test.subplots() |
| 1531 | + ax.barh(x, y, height=h, align='center') |
| 1532 | + # Reference image |
| 1533 | + ax = fig_ref.subplots() |
| 1534 | + ax.barh(x, y, height=h0, align='center') |
| 1535 | + |
| 1536 | + |
1480 | 1537 | def test_bar_color_none_alpha():
|
1481 | 1538 | ax = plt.gca()
|
1482 | 1539 | rects = ax.bar([1, 2], [2, 4], alpha=0.3, color='none', edgecolor='r')
|
@@ -1819,6 +1876,21 @@ def test_scatter_2D(self):
|
1819 | 1876 | fig, ax = plt.subplots()
|
1820 | 1877 | ax.scatter(x, y, c=z, s=200, edgecolors='face')
|
1821 | 1878 |
|
| 1879 | + @check_figures_equal(extensions=["png"]) |
| 1880 | + def test_scatter_decimal(self, fig_test, fig_ref): |
| 1881 | + x0 = np.array([1.5, 8.4, 5.3, 4.2]) |
| 1882 | + y0 = np.array([1.1, 2.2, 3.3, 4.4]) |
| 1883 | + x = np.array([Decimal(i) for i in x0]) |
| 1884 | + y = np.array([Decimal(i) for i in y0]) |
| 1885 | + c = ['r', 'y', 'b', 'lime'] |
| 1886 | + s = [24, 15, 19, 29] |
| 1887 | + # Test image - scatter plot with Decimal() input |
| 1888 | + ax = fig_test.subplots() |
| 1889 | + ax.scatter(x, y, c=c, s=s) |
| 1890 | + # Reference image |
| 1891 | + ax = fig_ref.subplots() |
| 1892 | + ax.scatter(x0, y0, c=c, s=s) |
| 1893 | + |
1822 | 1894 | def test_scatter_color(self):
|
1823 | 1895 | # Try to catch cases where 'c' kwarg should have been used.
|
1824 | 1896 | with pytest.raises(ValueError):
|
@@ -5965,6 +6037,18 @@ def test_plot_columns_cycle_deprecation():
|
5965 | 6037 | plt.plot(np.zeros((2, 2)), np.zeros((2, 3)))
|
5966 | 6038 |
|
5967 | 6039 |
|
| 6040 | +@check_figures_equal(extensions=["png"]) |
| 6041 | +def test_plot_decimal(fig_test, fig_ref): |
| 6042 | + x0 = np.arange(-10, 10, 0.3) |
| 6043 | + y0 = [5.2 * x ** 3 - 2.1 * x ** 2 + 7.34 * x + 4.5 for x in x0] |
| 6044 | + x = [Decimal(i) for i in x0] |
| 6045 | + y = [Decimal(i) for i in y0] |
| 6046 | + # Test image - line plot with Decimal input |
| 6047 | + fig_test.subplots().plot(x, y) |
| 6048 | + # Reference image |
| 6049 | + fig_ref.subplots().plot(x0, y0) |
| 6050 | + |
| 6051 | + |
5968 | 6052 | # pdf and svg tests fail using travis' old versions of gs and inkscape.
|
5969 | 6053 | @check_figures_equal(extensions=["png"])
|
5970 | 6054 | def test_markerfacecolor_none_alpha(fig_test, fig_ref):
|
|
0 commit comments