@@ -1669,6 +1669,37 @@ def test_boxplot_legend_labels():
16691669 assert all (x .get_label ().startswith ("_" ) for x in bp4 ['medians' ][1 :])
16701670
16711671
1672+ def test_legend_linewidth ():
1673+ """Test legend.linewidth parameter and rcParam."""
1674+ fig , ax = plt .subplots ()
1675+ ax .plot ([1 , 2 , 3 ], label = 'data' )
1676+
1677+ # Test direct parameter
1678+ leg = ax .legend (linewidth = 2.5 )
1679+ assert leg .legendPatch .get_linewidth () == 2.5
1680+
1681+ # Test rcParam
1682+ with mpl .rc_context ({'legend.linewidth' : 3.0 }):
1683+ fig , ax = plt .subplots ()
1684+ ax .plot ([1 , 2 , 3 ], label = 'data' )
1685+ leg = ax .legend ()
1686+ assert leg .legendPatch .get_linewidth () == 3.0
1687+
1688+ # Test None default (should inherit from patch.linewidth)
1689+ with mpl .rc_context ({'legend.linewidth' : None , 'patch.linewidth' : 1.5 }):
1690+ fig , ax = plt .subplots ()
1691+ ax .plot ([1 , 2 , 3 ], label = 'data' )
1692+ leg = ax .legend ()
1693+ assert leg .legendPatch .get_linewidth () == 1.5
1694+
1695+ # Test that direct parameter overrides rcParam
1696+ with mpl .rc_context ({'legend.linewidth' : 1.0 }):
1697+ fig , ax = plt .subplots ()
1698+ ax .plot ([1 , 2 , 3 ], label = 'data' )
1699+ leg = ax .legend (linewidth = 4.0 )
1700+ assert leg .legendPatch .get_linewidth () == 4.0
1701+
1702+
16721703def test_patchcollection_legend ():
16731704 # Test that PatchCollection labels show up in legend and preserve visual
16741705 # properties (issue #23998)
0 commit comments