File tree Expand file tree Collapse file tree 3 files changed +10
-11
lines changed Expand file tree Collapse file tree 3 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -725,12 +725,12 @@ def validate_legend_loc(loc):
725
725
726
726
Parameters
727
727
----------
728
- loc : str | (float, float) | str((float, float))
728
+ loc : str | int | (float, float) | str((float, float))
729
729
The location of the legend.
730
730
731
731
Returns
732
732
-------
733
- loc : str | (float, float) or raise ValueError exception
733
+ loc : str | int | (float, float) or raise ValueError exception
734
734
The location of the legend.
735
735
"""
736
736
valid = [
@@ -745,6 +745,8 @@ def validate_legend_loc(loc):
745
745
f"are { [* valid .values ()]} | tuple(float, float) "
746
746
f"| str(tuple(float, float))" )
747
747
748
+ if isinstance (loc , int ):
749
+ return loc
748
750
if isinstance (loc , str ):
749
751
loc = loc .lower ()
750
752
if loc in valid :
@@ -761,7 +763,9 @@ def validate_legend_loc(loc):
761
763
if matches and len (tuples ) == 1 :
762
764
loc = tuples [0 ]
763
765
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 ):
765
769
return loc
766
770
raise ValueError (msg )
767
771
Original file line number Diff line number Diff line change @@ -157,5 +157,5 @@ def validate_hist_bins(
157
157
float
158
158
]: ...
159
159
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):
598
598
# mpl.RcParams({'legend.loc': value})
599
599
600
600
@pytest .mark .parametrize ('value' , [
601
+ 1 ,
601
602
(0.9 , .7 ),
602
603
'(0.9, .7)'
603
604
])
604
605
def test_rcparams_legend_loc (value ):
605
606
# rcParams['legend.loc'] should allow any of the following formats.
606
607
# if any of these are not allowed, an exception will be raised
607
608
# 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 )
611
609
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