Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3481e10

Browse files
committed
Fix positions of r axis labels when rmin != 0.0 in polar plots.
svn path=/branches/v1_0_maint/; revision=8649
1 parent d5680c7 commit 3481e10

2 files changed

Lines changed: 36 additions & 9 deletions

File tree

lib/matplotlib/projections/polar.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from matplotlib.ticker import Formatter, Locator, FormatStrFormatter
1515
from matplotlib.transforms import Affine2D, Affine2DBase, Bbox, \
1616
BboxTransformTo, IdentityTransform, Transform, TransformWrapper, \
17-
ScaledTranslation, blended_transform_factory
17+
ScaledTranslation, blended_transform_factory, BboxTransformToMaxOnly
1818
import matplotlib.spines as mspines
1919

2020
class PolarAxes(Axes):
@@ -41,16 +41,16 @@ def __init__(self, axis=None):
4141
self._axis = axis
4242

4343
def transform(self, tr):
44-
xy = np.zeros(tr.shape, np.float_)
44+
xy = np.empty(tr.shape, np.float_)
4545
if self._axis is not None:
4646
rmin = self._axis.viewLim.ymin
4747
else:
4848
rmin = 0
4949

50-
t = tr[:, 0:1]
51-
r = tr[:, 1:2]
52-
x = xy[:, 0:1]
53-
y = xy[:, 1:2]
50+
t = tr[:, 0:1]
51+
r = tr[:, 1:2]
52+
x = xy[:, 0:1]
53+
y = xy[:, 1:2]
5454

5555
if rmin != 0:
5656
r = r - rmin
@@ -188,7 +188,7 @@ def refresh(self):
188188

189189
def view_limits(self, vmin, vmax):
190190
vmin, vmax = self.base.view_limits(vmin, vmax)
191-
return 0, vmax
191+
return vmin, vmax
192192

193193

194194
def __init__(self, *args, **kwargs):
@@ -290,15 +290,17 @@ def _set_lim_and_transforms(self):
290290
# The r-axis labels are put at an angle and padded in the r-direction
291291
self._r_label1_position = ScaledTranslation(
292292
22.5, self._rpad,
293-
blended_transform_factory(Affine2D(), BboxTransformTo(self.viewLim)))
293+
blended_transform_factory(
294+
Affine2D(), BboxTransformToMaxOnly(self.viewLim)))
294295
self._yaxis_text1_transform = (
295296
self._r_label1_position +
296297
Affine2D().scale(1.0 / 360.0, 1.0) +
297298
self._yaxis_transform
298299
)
299300
self._r_label2_position = ScaledTranslation(
300301
22.5, -self._rpad,
301-
blended_transform_factory(Affine2D(), BboxTransformTo(self.viewLim)))
302+
blended_transform_factory(
303+
Affine2D(), BboxTransformToMaxOnly(self.viewLim)))
302304
self._yaxis_text2_transform = (
303305
self._r_label2_position +
304306
Affine2D().scale(1.0 / 360.0, 1.0) +

lib/matplotlib/transforms.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2107,6 +2107,31 @@ def get_matrix(self):
21072107
get_matrix.__doc__ = Affine2DBase.get_matrix.__doc__
21082108

21092109

2110+
class BboxTransformToMaxOnly(BboxTransformTo):
2111+
"""
2112+
:class:`BboxTransformTo` is a transformation that linearly
2113+
transforms points from the unit bounding box to a given
2114+
:class:`Bbox` with a fixed upper left of (0, 0).
2115+
"""
2116+
def __repr__(self):
2117+
return "BboxTransformToMaxOnly(%s)" % (self._boxout)
2118+
__str__ = __repr__
2119+
2120+
def get_matrix(self):
2121+
if self._invalid:
2122+
xmax, ymax = self._boxout.max
2123+
if DEBUG and (xmax == 0 or ymax == 0):
2124+
raise ValueError("Transforming to a singular bounding box.")
2125+
self._mtx = np.array([[xmax, 0.0, 0.0],
2126+
[ 0.0, ymax, 0.0],
2127+
[ 0.0, 0.0, 1.0]],
2128+
np.float_)
2129+
self._inverted = None
2130+
self._invalid = 0
2131+
return self._mtx
2132+
get_matrix.__doc__ = Affine2DBase.get_matrix.__doc__
2133+
2134+
21102135
class BboxTransformFrom(Affine2DBase):
21112136
"""
21122137
:class:`BboxTransformFrom` linearly transforms points from a given

0 commit comments

Comments
 (0)