()
| 1710 | |
| 1711 | |
| 1712 | def test_patchcollection_legend(): |
| 1713 | # Test that PatchCollection labels show up in legend and preserve visual |
| 1714 | # properties (issue #23998) |
| 1715 | fig, ax = plt.subplots() |
| 1716 | |
| 1717 | pc = mcollections.PatchCollection( |
| 1718 | [mpatches.Circle((0, 0), 1), mpatches.Circle((2, 0), 1)], |
| 1719 | label="patch collection", |
| 1720 | facecolor='red', |
| 1721 | edgecolor='blue', |
| 1722 | linewidths=3, |
| 1723 | linestyle='--', |
| 1724 | ) |
| 1725 | ax.add_collection(pc) |
| 1726 | ax.autoscale_view() |
| 1727 | |
| 1728 | leg = ax.legend() |
| 1729 | |
| 1730 | # Check that the legend contains our label |
| 1731 | assert len(leg.get_texts()) == 1 |
| 1732 | assert leg.get_texts()[0].get_text() == "patch collection" |
| 1733 | |
| 1734 | # Check that the legend handle exists and has correct visual properties |
| 1735 | assert len(leg.legend_handles) == 1 |
| 1736 | legend_patch = leg.legend_handles[0] |
| 1737 | assert mpl.colors.same_color(legend_patch.get_facecolor(), |
| 1738 | pc.get_facecolor()[0]) |
| 1739 | assert mpl.colors.same_color(legend_patch.get_edgecolor(), |
| 1740 | pc.get_edgecolor()[0]) |
| 1741 | assert legend_patch.get_linewidth() == pc.get_linewidths()[0] |
| 1742 | assert legend_patch.get_linestyle() == pc.get_linestyles()[0] |
| 1743 | |
| 1744 | |
| 1745 | def test_patchcollection_legend_empty(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…