| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -679,20 +679,15 @@ def __init__(self, *args, **kwargs): | |||
| 679 | 679 | super().__init__(*args, **kwargs) | |
| 680 | 680 | self.sticky_edges.y.append(0) | |
| 681 | 681 | ||
| 682 | - def _wrap_locator_formatter(self): | ||
| 683 | - self.set_major_locator(RadialLocator(self.get_major_locator(), | ||
| 684 | - self.axes)) | ||
| 685 | - self.isDefault_majloc = True | ||
| 682 | + def set_major_locator(self, locator): | ||
| 683 | + if not isinstance(locator, RadialLocator): | ||
| 684 | + locator = RadialLocator(locator, self.axes) | ||
| 685 | + super().set_major_locator(locator) | ||
| 686 | 686 | ||
| 687 | 687 | def clear(self): | |
| 688 | 688 | # docstring inherited | |
| 689 | 689 | super().clear() | |
| 690 | 690 | self.set_ticks_position('none') | |
| 691 | - self._wrap_locator_formatter() | ||
| 692 | - | ||
| 693 | - def _set_scale(self, value, **kwargs): | ||
| 694 | - super()._set_scale(value, **kwargs) | ||
| 695 | - self._wrap_locator_formatter() | ||
| 696 | 691 | ||
| 697 | 692 | ||
| 698 | 693 | def _is_full_circle_deg(thetamin, thetamax): | |
@@ -1242,19 +1237,11 @@ def set_rlabel_position(self, value): | |||
| 1242 | 1237 | """ | |
| 1243 | 1238 | self._r_label_position.clear().translate(np.deg2rad(value), 0.0) | |
| 1244 | 1239 | ||
| 1245 | - def set_yscale(self, *args, **kwargs): | ||
| 1246 | - super().set_yscale(*args, **kwargs) | ||
| 1247 | - self.yaxis.set_major_locator( | ||
| 1248 | - self.RadialLocator(self.yaxis.get_major_locator(), self)) | ||
| 1249 | - | ||
| 1250 | 1240 | def set_rscale(self, *args, **kwargs): | |
| 1251 | 1241 | return Axes.set_yscale(self, *args, **kwargs) | |
| 1252 | 1242 | ||
| 1253 | 1243 | def set_rticks(self, *args, **kwargs): | |
| 1254 | - result = Axes.set_yticks(self, *args, **kwargs) | ||
| 1255 | - self.yaxis.set_major_locator( | ||
| 1256 | - self.RadialLocator(self.yaxis.get_major_locator(), self)) | ||
| 1257 | - return result | ||
| 1244 | + return Axes.set_yticks(self, *args, **kwargs) | ||
| 1258 | 1245 | ||
| 1259 | 1246 | def set_thetagrids(self, angles, labels=None, fmt=None, **kwargs): | |
| 1260 | 1247 | """ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3,8 +3,10 @@ | |||
| 3 | 3 | import pytest | |
| 4 | 4 | ||
| 5 | 5 | import matplotlib as mpl | |
| 6 | + from matplotlib.projections.polar import RadialLocator | ||
| 6 | 7 | from matplotlib import pyplot as plt | |
| 7 | 8 | from matplotlib.testing.decorators import image_comparison, check_figures_equal | |
| 9 | + import matplotlib.ticker as mticker | ||
| 8 | 10 | ||
| 9 | 11 | ||
| 10 | 12 | @image_comparison(['polar_axes.png'], style='default', tol=0.012) | |
@@ -526,3 +528,43 @@ def test_radial_limits_behavior(): | |||
| 526 | 528 | # negative data also autoscales to negative limits | |
| 527 | 529 | ax.plot([1, 2], [-1, -2]) | |
| 528 | 530 | assert ax.get_ylim() == (-2, 2) | |
| 531 | + | ||
| 532 | + | ||
| 533 | + def test_radial_locator_wrapping(): | ||
| 534 | + # Check that the locator is always wrapped inside a RadialLocator | ||
| 535 | + # and that RaidialAxis.isDefault_majloc is set correctly. | ||
| 536 | + fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}) | ||
| 537 | + assert ax.yaxis.isDefault_majloc | ||
| 538 | + assert isinstance(ax.yaxis.get_major_locator(), RadialLocator) | ||
| 539 | + | ||
| 540 | + # set an explicit locator | ||
| 541 | + locator = mticker.MaxNLocator(3) | ||
| 542 | + ax.yaxis.set_major_locator(locator) | ||
| 543 | + assert not ax.yaxis.isDefault_majloc | ||
| 544 | + assert isinstance(ax.yaxis.get_major_locator(), RadialLocator) | ||
| 545 | + assert ax.yaxis.get_major_locator().base is locator | ||
| 546 | + | ||
| 547 | + ax.clear() # reset to the default locator | ||
| 548 | + assert ax.yaxis.isDefault_majloc | ||
| 549 | + assert isinstance(ax.yaxis.get_major_locator(), RadialLocator) | ||
| 550 | + | ||
| 551 | + ax.set_rticks([0, 1, 2, 3]) # implicitly sets a FixedLocator | ||
| 552 | + assert not ax.yaxis.isDefault_majloc # because of the fixed ticks | ||
| 553 | + assert isinstance(ax.yaxis.get_major_locator(), RadialLocator) | ||
| 554 | + assert isinstance(ax.yaxis.get_major_locator().base, mticker.FixedLocator) | ||
| 555 | + | ||
| 556 | + ax.clear() | ||
| 557 | + | ||
| 558 | + ax.set_rgrids([0, 1, 2, 3]) # implicitly sets a FixedLocator | ||
| 559 | + assert not ax.yaxis.isDefault_majloc # because of the fixed ticks | ||
| 560 | + assert isinstance(ax.yaxis.get_major_locator(), RadialLocator) | ||
| 561 | + assert isinstance(ax.yaxis.get_major_locator().base, mticker.FixedLocator) | ||
| 562 | + | ||
| 563 | + ax.clear() | ||
| 564 | + | ||
| 565 | + ax.set_yscale("log") # implicitly sets a LogLocator | ||
| 566 | + # Note that the LogLocator is still considered the default locator | ||
| 567 | + # for the log scale | ||
| 568 | + assert ax.yaxis.isDefault_majloc | ||
| 569 | + assert isinstance(ax.yaxis.get_major_locator(), RadialLocator) | ||
| 570 | + assert isinstance(ax.yaxis.get_major_locator().base, mticker.LogLocator) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments