@@ -830,10 +830,10 @@ def axhline(self, y=0, xmin=0, xmax=1, **kwargs):
830
830
831
831
>>> axhline(y=.5, xmin=0.25, xmax=0.75)
832
832
"""
833
+ self ._check_scalars ([xmin , xmax ], ['xmin' , 'xmax' ])
833
834
if "transform" in kwargs :
834
- raise ValueError (
835
- "'transform' is not allowed as a kwarg;"
836
- + "axhline generates its own transform." )
835
+ raise ValueError ("'transform' is not allowed as a kwarg; "
836
+ "axhline generates its own transform." )
837
837
ymin , ymax = self .get_ybound ()
838
838
839
839
# We need to strip away the units for comparison with
@@ -899,11 +899,10 @@ def axvline(self, x=0, ymin=0, ymax=1, **kwargs):
899
899
900
900
>>> axvline(x=.5, ymin=0.25, ymax=0.75)
901
901
"""
902
-
902
+ self . _check_scalars ([ ymin , ymax ], [ 'ymin' , 'ymax' ])
903
903
if "transform" in kwargs :
904
- raise ValueError (
905
- "'transform' is not allowed as a kwarg;"
906
- + "axvline generates its own transform." )
904
+ raise ValueError ("'transform' is not allowed as a kwarg; "
905
+ "axvline generates its own transform." )
907
906
xmin , xmax = self .get_xbound ()
908
907
909
908
# We need to strip away the units for comparison with
@@ -918,6 +917,16 @@ def axvline(self, x=0, ymin=0, ymax=1, **kwargs):
918
917
self ._request_autoscale_view (scalex = scalex , scaley = False )
919
918
return l
920
919
920
+ @staticmethod
921
+ def _check_scalars (vals , names ):
922
+ # Helper method to check that vals are all scalars
923
+ for val , name in zip (vals , names ):
924
+ try :
925
+ float (val )
926
+ except Exception as e :
927
+ raise ValueError (f"{ name } must be a single scalar value, "
928
+ f"but got { val } " ) from e
929
+
921
930
@docstring .dedent_interpd
922
931
def axline (self , xy1 , xy2 = None , * , slope = None , ** kwargs ):
923
932
"""
@@ -1038,6 +1047,7 @@ def axhspan(self, ymin, ymax, xmin=0, xmax=1, **kwargs):
1038
1047
--------
1039
1048
axvspan : Add a vertical span across the axes.
1040
1049
"""
1050
+ self ._check_scalars ([xmin , xmax ], ['xmin' , 'xmax' ])
1041
1051
trans = self .get_yaxis_transform (which = 'grid' )
1042
1052
1043
1053
# process the unit information
@@ -1098,6 +1108,7 @@ def axvspan(self, xmin, xmax, ymin=0, ymax=1, **kwargs):
1098
1108
>>> axvspan(1.25, 1.55, facecolor='g', alpha=0.5)
1099
1109
1100
1110
"""
1111
+ self ._check_scalars ([ymin , ymax ], ['ymin' , 'ymax' ])
1101
1112
trans = self .get_xaxis_transform (which = 'grid' )
1102
1113
1103
1114
# process the unit information
0 commit comments