File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -725,12 +725,12 @@ def validate_legend_loc(loc):
725725
726726 Parameters
727727 ----------
728- loc : str | (float, float) | str((float, float))
728+ loc : str | int | (float, float) | str((float, float))
729729 The location of the legend.
730730
731731 Returns
732732 -------
733- loc : str | (float, float) or raise ValueError exception
733+ loc : str | int | (float, float) or raise ValueError exception
734734 The location of the legend.
735735 """
736736 valid = [
@@ -745,6 +745,8 @@ def validate_legend_loc(loc):
745745 f"are { [* valid .values ()]} | tuple(float, float) "
746746 f"| str(tuple(float, float))" )
747747
748+ if isinstance (loc , int ):
749+ return loc
748750 if isinstance (loc , str ):
749751 loc = loc .lower ()
750752 if loc in valid :
@@ -761,7 +763,9 @@ def validate_legend_loc(loc):
761763 if matches and len (tuples ) == 1 :
762764 loc = tuples [0 ]
763765 if isinstance (loc , tuple ):
764- if len (loc ) == 2 and all (isinstance (e , numbers .Real ) for e in loc ):
766+ if len (loc ) == 2 \
767+ and all (isinstance (e , numbers .Real )
768+ and float (e ) >= 0.0 for e in loc ):
765769 return loc
766770 raise ValueError (msg )
767771
Original file line number Diff line number Diff line change @@ -157,5 +157,5 @@ def validate_hist_bins(
157157 float
158158]: ...
159159
160- def validate_legend_loc (loc : str | tuple [ float | int ]
161- ) -> str | tuple [float ]: ...
160+ def validate_legend_loc (loc : str | int | tuple [ float ]
161+ ) -> str | int | tuple [float ]: ...
Original file line number Diff line number Diff line change @@ -598,17 +598,12 @@ def test_deprecation(monkeypatch):
598598# mpl.RcParams({'legend.loc': value})
599599
600600@pytest .mark .parametrize ('value' , [
601+ 1 ,
601602 (0.9 , .7 ),
602603 '(0.9, .7)'
603604])
604605def test_rcparams_legend_loc (value ):
605606 # rcParams['legend.loc'] should allow any of the following formats.
606607 # if any of these are not allowed, an exception will be raised
607608 # test for gh issue #22338
608- _ , ax = plt .subplots (1 )
609- expected = ax .legend (value ).get_bbox_to_anchor ().bounds
610- _ , ax = plt .subplots (1 )
611609 mpl .rcParams ['legend.loc' ] = value
612- result = ax .legend ().get_bbox_to_anchor ().bounds
613-
614- assert result == expected
You can’t perform that action at this time.
0 commit comments