| f.set_ticks_position('none') | |
| self._wrap_locator_formatter() | |
| def _set_scale(self, value, **kwargs): | |
| if value != 'linear': | |
| raise NotImplementedError( | |
| "The xscale cannot be set on a polar plot") | |
| super()._set_scale(value, **kwargs) | |
| # LinearScale.set_default_locators_and_formatters just set the major | |
| # locator to be an AutoLocator, so we customize it here to have ticks | |
| # at sensible degree multiples. | |
| self.get_major_locator().set_params(steps=[1, 1.5, 3, 4.5, 9, 10]) | |
| self._wrap_locator_formatter() | |
| def _copy_tick_props(self, src, dest): | |
| """Copy the props from src tick to dest tick.""" | |
| if src is None or dest is None: | |
| return | |
| super()._copy_tick_props(src, dest) | |
| # Ensure that tick transforms are independent so that padding works. | |
| trans = dest._get_text1_transform()[0] | |
| dest.label1.set_transform(trans + dest._text1_translate) | |
| trans = dest._get_text2_transform()[0] | |
| dest.label2.set_transform(trans + dest._text2_translate) | |
| class RadialLocator(mticker.Locator): | |
| """ | |
| Used to locate radius ticks. | |
| Ensures that all ticks are strictly positive. For all other tasks, it | |
| delegates to the base `.Locator` (which may be different depending on the | |
| scale of the *r*-axis). | |
| """ | |
| def __init__(self, base, axes=None): | |
| self.base = base | |
| self._axes = axes | |
| def set_axis(self, axis): | |
| self.base.set_axis(axis) | |
| def __call__(self): | |
| # Ensure previous behaviour with full circle non-annular views. | |
| if self._axes: | |
| if _is_full_circle_rad(*self._axes.viewLim.intervalx): | |
| rorigin = self._axes.get_rorigin() * self._axes.get_rsign() | |
| if self._axes.get_rmin() <= rorigin: | |
| return [tick for tick in self.base() if tick > rorigin] | |
| return self.base() | |
| def _zero_in_bounds(self): | |
| """ | |
| Return True if zero is within the valid values for the | |
| scale of the radial axis. | |
| """ | |
| vmin, vmax = self._axes.yaxis._scale.limit_range_for_scale(0, 1, 1e-5) | |
| return vmin == 0 | |
| def nonsingular(self, vmin, vmax): | |
| # docstring inherited | |
| if self._zero_in_bounds() and (vmin, vmax) == (-np.inf, np.inf): | |
| # Initial view limits | |
| return (0, 1) | |
| else: | |
| return self.base.nonsingular(vmin, vmax) | |
| def view_limits(self, vmin, vmax): | |
| vmin, vmax = self.base.view_limits(vmin, vmax) | |
| if self._zero_in_bounds() and vmax > vmin: | |
| # this allows inverted r/y-lims | |
| vmin = min(0, vmin) | |
| return mtransforms.nonsingular(vmin, vmax) | |
| class _ThetaShift(mtransforms.ScaledTranslation): | |
| """ | |
| Apply a padding shift based on axes theta limits. | |
| This is used to create padding for radial ticks. | |
| Parameters | |
| ---------- | |
| axes : `~matplotlib.axes.Axes` | |
| The owning axes; used to determine limits. | |
| pad : float | |
| The padding to apply, in points. | |
| mode : {'min', 'max', 'rlabel'} | |
| Whether to shift away from the start (``'min'``) or the end (``'max'``) | |
| of the axes, or using the rlabel position (``'rlabel'``). | |
| """ | |
| def __init__(self, axes, pad, mode): | |
| super().__init__(pad, pad, axes.figure.dpi_scale_trans) | |
| self.set_children(axes._realViewLim) | |
| self.axes = axes | |
| self.mode = mode | |
| self.pad = pad | |
| __str__ = mtransforms._make_str_method("axes", "pad", "mode") | |
| def get_matrix(self): | |
| if self._invalid: | |
| if self.mode == 'rlabel': | |
| angle = ( | |
| np.deg2rad(self.axes.get_rlabel_position() | |
| * self.axes.get_theta_direction()) | |
| + self.axes.get_theta_offset() | |
| - np.pi / 2 | |
| ) | |
| elif self.mode == 'min': | |
| angle = self.axes._realViewLim.xmin - np.pi / 2 | |
| elif self.mode == 'max': | |
| angle = self.axes._realViewLim.xmax + np.pi / 2 | |
| self._t = (self.pad * np.cos(angle) / 72, self.pad * np.sin(angle) / 72) | |
| return super().get_matrix() | |
| class RadialTick(maxis.YTick): | |
| """ | |
| A radial-axis tick. | |
| This subclass of `.YTick` provides radial ticks with some small | |
| modification to their re-positioning such that ticks are rotated based on | |
| axes limits. This results in ticks that are correctly perpendicular to | |
| the spine. Labels are also rotated to be perpendicular to the spine, when | |
| 'auto' rotation is enabled. | |
| """ | |
| def __init__(self, *args, **kwargs): | |
| super().__init__(*args, **kwargs) | |
| self.label1.set_rotation_mode('anchor') | |
| self.label2.set_rotation_mode('anchor') | |
| def _determine_anchor(self, mode, angle, start): | |
| # Note: angle is the (spine angle - 90) because it's used for the tick | |
| # & text setup, so all numbers below are -90 from (normed) spine angle. | |
| if mode == 'auto': | |
| if start: | |
| if -90 <= angle <= 90: | |
| return 'left', 'center' | |
| else: | |
| return 'right', 'center' | |
| else: | |
| if -90 <= angle <= 90: | |
| return 'right', 'center' | |
| else: | |
| return 'left', 'center' | |
| else: | |
| if start: | |
| if angle < -68.5: | |
| return 'center', 'top' | |
| elif angle < -23.5: | |
| return 'left', 'top' | |
| elif angle < 22.5: | |
| return 'left', 'center' | |
| elif angle < 67.5: | |
| return 'left', 'bottom' | |
| elif angle < 112.5: | |
| return 'center', 'bottom' | |
| elif angle < 157.5: | |
| return 'right', 'bottom' | |
| elif angle < 202.5: | |
| return 'right', 'center' | |
| elif angle < 247.5: | |
| return 'right', 'top' | |
| else: | |
| return 'center', 'top' | |
| else: | |
| if angle < -68.5: | |
| return 'center', 'bottom' | |
| elif angle < -23.5: | |
| return 'right', 'bottom' | |
| elif angle < 22.5: | |
| return 'right', 'center' | |
| elif angle < 67.5: | |
| return 'right', 'top' | |
| elif angle < 112.5: | |
| return 'center', 'top' | |
| elif angle < 157.5: | |
| return 'left', 'top' | |
| elif angle < 202.5: | |
| return 'left', 'center' | |
| elif angle < 247.5: | |
| return 'left', 'bottom' | |
| else: | |
| return 'center', 'bottom' | |
| def update_position(self, loc): | |
| super().update_position(loc) | |
| axes = self.axes | |
| thetamin = axes.get_thetamin() | |
| thetamax = axes.get_thetamax() | |
| direction = axes.get_theta_direction() | |
| offset_rad = axes.get_theta_offset() | |
| offset = np.rad2deg(offset_rad) | |
| full = _is_full_circle_deg(thetamin, thetamax) | |
| if full: | |
| angle = (axes.get_rlabel_position() * direction + | |
| offset) % 360 - 90 | |
| tick_angle = 0 | |
| else: | |
| angle = (thetamin * direction + offset) % 360 - 90 | |
| if direction > 0: | |
| tick_angle = np.deg2rad(angle) | |
| else: | |
| tick_angle |