MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / test_patchcollection_legend

Function test_patchcollection_legend

lib/matplotlib/tests/test_legend.py:1712–1742  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1710
1711
1712def 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
1745def test_patchcollection_legend_empty():

Callers

nothing calls this directly

Calls 11

add_collectionMethod · 0.80
get_textsMethod · 0.80
get_linewidthsMethod · 0.80
subplotsMethod · 0.45
autoscale_viewMethod · 0.45
legendMethod · 0.45
get_textMethod · 0.45
get_facecolorMethod · 0.45
get_edgecolorMethod · 0.45
get_linewidthMethod · 0.45
get_linestyleMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…