Test legend.linewidth parameter and rcParam.
()
| 1679 | |
| 1680 | |
| 1681 | def test_legend_linewidth(): |
| 1682 | """Test legend.linewidth parameter and rcParam.""" |
| 1683 | fig, ax = plt.subplots() |
| 1684 | ax.plot([1, 2, 3], label='data') |
| 1685 | |
| 1686 | # Test direct parameter |
| 1687 | leg = ax.legend(linewidth=2.5) |
| 1688 | assert leg.legendPatch.get_linewidth() == 2.5 |
| 1689 | |
| 1690 | # Test rcParam |
| 1691 | with mpl.rc_context({'legend.linewidth': 3.0}): |
| 1692 | fig, ax = plt.subplots() |
| 1693 | ax.plot([1, 2, 3], label='data') |
| 1694 | leg = ax.legend() |
| 1695 | assert leg.legendPatch.get_linewidth() == 3.0 |
| 1696 | |
| 1697 | # Test None default (should inherit from patch.linewidth) |
| 1698 | with mpl.rc_context({'legend.linewidth': None, 'patch.linewidth': 1.5}): |
| 1699 | fig, ax = plt.subplots() |
| 1700 | ax.plot([1, 2, 3], label='data') |
| 1701 | leg = ax.legend() |
| 1702 | assert leg.legendPatch.get_linewidth() == 1.5 |
| 1703 | |
| 1704 | # Test that direct parameter overrides rcParam |
| 1705 | with mpl.rc_context({'legend.linewidth': 1.0}): |
| 1706 | fig, ax = plt.subplots() |
| 1707 | ax.plot([1, 2, 3], label='data') |
| 1708 | leg = ax.legend(linewidth=4.0) |
| 1709 | assert leg.legendPatch.get_linewidth() == 4.0 |
| 1710 | |
| 1711 | |
| 1712 | def test_patchcollection_legend(): |
nothing calls this directly
no test coverage detected
searching dependent graphs…