@@ -1041,29 +1041,20 @@ def set_thetalim(self, *args, **kwargs):
10411041 wrapped in to the range :math:`[0, 2\pi]` (in radians), so for example
10421042 it is possible to do ``set_thetalim(-np.pi / 2, np.pi / 2)`` to have
10431043 an axes symmetric around 0. A ValueError is raised if the absolute
1044- angle difference is larger than :math:`2\pi` .
1044+ angle difference is larger than a full circle .
10451045 """
1046- thetamin = None
1047- thetamax = None
1048- left = None
1049- right = None
1050-
1051- if len (args ) == 2 :
1052- if args [0 ] is not None and args [1 ] is not None :
1053- left , right = args
1054- if abs (right - left ) > 2 * np .pi :
1055- raise ValueError ('The angle range must be <= 2 pi' )
1056-
1046+ orig_lim = self .get_xlim () # in radians
10571047 if 'thetamin' in kwargs :
1058- thetamin = np .deg2rad (kwargs .pop ('thetamin' ))
1048+ kwargs [ 'xmin' ] = np .deg2rad (kwargs .pop ('thetamin' ))
10591049 if 'thetamax' in kwargs :
1060- thetamax = np .deg2rad (kwargs .pop ('thetamax' ))
1061-
1062- if thetamin is not None and thetamax is not None :
1063- if abs (thetamax - thetamin ) > 2 * np .pi :
1064- raise ValueError ('The angle range must be <= 360 degrees' )
1065- return tuple (np .rad2deg (self .set_xlim (left = left , right = right ,
1066- xmin = thetamin , xmax = thetamax )))
1050+ kwargs ['xmax' ] = np .deg2rad (kwargs .pop ('thetamax' ))
1051+ new_min , new_max = self .set_xlim (* args , ** kwargs )
1052+ # Parsing all permutations of *args, **kwargs is tricky; it is simpler
1053+ # to let set_xlim() do it and then validate the limits.
1054+ if abs (new_max - new_min ) > 2 * np .pi :
1055+ self .set_xlim (orig_lim ) # un-accept the change
1056+ raise ValueError ("The angle range must be less than a full circle" )
1057+ return tuple (np .rad2deg ((new_min , new_max )))
10671058
10681059 def set_theta_offset (self , offset ):
10691060 """
0 commit comments