Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 29aae1f

Browse filesBrowse files
authored
Merge pull request #16717 from CSCD01-team13/bugfix-for-issue-16501
Bugfix for issue 16501 raised ValueError polar subplot with (thetamax - thetamin) > 2pi
2 parents f369b10 + e38a5bc commit 29aae1f
Copy full SHA for 29aae1f

File tree

Expand file treeCollapse file tree

2 files changed

+44
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+44
-4
lines changed

‎lib/matplotlib/projections/polar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/projections/polar.py
+21-4Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1040,13 +1040,30 @@ def set_thetalim(self, *args, **kwargs):
10401040
where minval and maxval are the minimum and maximum limits. Values are
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
1043-
an axes symmetric around 0.
1043+
an axes symmetric around 0. A ValueError is raised if the absolute
1044+
angle difference is larger than :math:`2\pi`.
10441045
"""
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+
10451057
if 'thetamin' in kwargs:
1046-
kwargs['xmin'] = np.deg2rad(kwargs.pop('thetamin'))
1058+
thetamin = np.deg2rad(kwargs.pop('thetamin'))
10471059
if 'thetamax' in kwargs:
1048-
kwargs['xmax'] = np.deg2rad(kwargs.pop('thetamax'))
1049-
return tuple(np.rad2deg(self.set_xlim(*args, **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)))
10501067

10511068
def set_theta_offset(self, offset):
10521069
"""

‎lib/matplotlib/tests/test_subplots.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_subplots.py
+23Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,26 @@ def test_dont_mutate_kwargs():
173173
gridspec_kw=gridspec_kw)
174174
assert subplot_kw == {'sharex': 'all'}
175175
assert gridspec_kw == {'width_ratios': [1, 2]}
176+
177+
178+
def test_subplot_theta_min_max_raise():
179+
with pytest.raises(ValueError, match='The angle range ' +
180+
'must be<= 360 degrees'):
181+
ax = plt.subplot(111, projection='polar')
182+
ax.set_thetalim(thetamin=800, thetamax=400)
183+
184+
185+
def test_subplot_theta_min_max_non_raise():
186+
ax = plt.subplot(111, projection='polar')
187+
ax.set_thetalim(thetamin=800, thetamax=440)
188+
189+
190+
def test_subplot_theta_range_raise():
191+
with pytest.raises(ValueError, match='The angle range must be <= 2 pi'):
192+
ax = plt.subplot(111, projection='polar')
193+
ax.set_thetalim(0, 3 * numpy.pi)
194+
195+
196+
def test_subplot_theta_range_normal_non_raise():
197+
ax = plt.subplot(111, projection='polar')
198+
ax.set_thetalim(0, 2 * numpy.pi)

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.