8000 FIX: allow flipped · matplotlib/matplotlib@18bf977 · GitHub
[go: up one dir, main page]

Skip to content

Commit 18bf977

Browse files
committed
FIX: allow flipped
1 parent 24ca248 commit 18bf977

File tree

2 files changed

+28
-17
lines changed

2 files changed

+28
-17
lines changed

lib/matplotlib/projections/polar.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ def transform_non_affine(self, tr):
5858
t += self._axis.get_theta_offset()
5959

6060
if self._use_rmin and self._axis is not None:
61-
r = r - self._axis.get_rorigin()
61+
r = (r - self._axis.get_rorigin()) * self._axis.get_rsign()
62+
6263
mask = r < 0
6364
x[:] = np.where(mask, np.nan, r * np.cos(t))
6465
y[:] = np.where(mask, np.nan, r * np.sin(t))
@@ -169,6 +170,7 @@ def transform_non_affine(self, xy):
169170

170171
if self._use_rmin and self._axis is not None:
171172
r += self._axis.get_rorigin()
173+
r *= self._axis.get_rsign()
172174

173175
return np.concatenate((theta, r), 1)
174176
transform_non_affine.__doc__ = \
@@ -432,10 +434,9 @@ def __call__(self):
432434
# Ensure previous behaviour with full circle non-annular views.
433435
if self._axes:
434436
if _is_full_circle_rad(*self._axes.viewLim.intervalx):
435-
rorigin = self._axes.get_rorigin()
437+
rorigin = self._axes.get_rorigin() * self._axes.get_rsign()
436438
if self._axes.get_rmin() <= rorigin:
437439
show_all = False
438-
439440
if show_all:
440441
return self.base()
441442
else:
@@ -455,7 +456,7 @@ def refresh(self):
455456

456457
def view_limits(self, vmin, vmax):
457458
vmin, vmax = self.base.view_limits(vmin, vmax)
458-
return mtransforms.nonsingular(min(0, vmin), vmax)
459+
return mtransforms.nonsingular(vmin, vmax)
459460

460461

461462
class _ThetaShift(mtransforms.ScaledTranslation):
@@ -790,7 +791,6 @@ def __str__(self):
790791
def get_points(self):
791792
if self._invalid:
792793
points = self._viewLim.get_points().copy()
793-
794794
# Scale angular limits to work with Wedge.
795795
points[:, 0] *= 180 / np.pi
796796
if points[0, 0] > points[1, 0]:
@@ -1015,8 +1015,8 @@ def draw(self, *args, **kwargs):
10151015
thetamin, thetamax = np.rad2deg(self._realViewLim.intervalx)
10161016
if thetamin > thetamax:
10171017
thetamin, thetamax = thetamax, thetamin
1018-
rmin, rmax = self._realViewLim.intervaly - self.get_rorigin()
1019-
1018+
rmin, rmax = ((self._realViewLim.intervaly - self.get_rorigin()) *
1019+
self.get_rsign())
10201020
if isinstance(self.patch, mpatches.Wedge):
10211021
# Backwards-compatibility: Any subclassed Axes might override the
10221022
# patch to not be the Wedge that PolarAxes uses.
@@ -1183,6 +1183,10 @@ def set_rorigin(self, rorigin):
11831183
def get_rorigin(self):
11841184
return self._originViewLim.y0
11851185

1186+
def get_rsign(self):
1187+
return np.sign(self._originViewLim.y1 - self._originViewLim.y0)
1188+
1189+
11861190
def set_rlim(self, bottom=None, top=None, emit=True, auto=False, **kwargs):
11871191
"""
11881192
See `~.polar.PolarAxes.set_ylim`.
@@ -1259,9 +1263,6 @@ def set_ylim(self, bottom=None, top=None, emit=True, auto=False,
12591263
if top is None and len(bottom) == 2:
12601264
top = bottom[1]
12611265
bottom = bottom[0]
1262-
if bottom >= top:
1263-
raise ValueError('Polar axes y/r-limits must be increasing; '
1264-
'i.e. bottom < top')
12651266

12661267
return super().set_ylim(bottom=bottom, top=top, emit=emit, auto=auto)
12671268

lib/matplotlib/tests/test_axes.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,23 @@ def test_polar_rorigin():
735735
ax.set_rorigin(0.0)
736736

737737

738+
@image_comparison(baseline_images=['polar_invertedylim'], style='default',
739+
extensions=['png'])
740+
def test_polar_invertedylim():
741+
fig = plt.figure()
742+
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True)
743+
ax.set_ylim(2, 0)
744+
745+
746+
@image_comparison(baseline_images=['polar_invertedylim_rorigin'],
747+
style='default', extensions=['png'])
748+
def test_polar_invertedylim_rorigin():
749+
fig = plt.figure()
750+
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True)
751+
ax.set_ylim(2, 0)
752+
ax.set_rorigin(3)
753+
754+
738755
@image_comparison(baseline_images=['polar_theta_position'], style='default')
739756
def test_polar_theta_position():
740757
r = np.arange(0, 3.0, 0.01)
@@ -747,13 +764,6 @@ def test_polar_theta_position():
747764
ax.set_theta_direction('clockwise')
748765

749766

750-
def test_polar_invertedylim():
751-
fig = plt.figure()
752-
ax = fig.add_axes([0.1, 0.1, 0.8, 0.8], polar=True)
753-
with pytest.raises(ValueError):
754-
ax.set_ylim(90, -45)
755-
with pytest.raises(ValueError):
756-
ax.set_rlim(90, -45)
757767

758768

759769
@image_comparison(baseline_images=['polar_rlabel_position'], style='default')

0 commit comments

Comments
 (0)
0