|
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)
|
@@ -546,3 +548,43 @@ def test_radial_limits_behavior():
|
546 | 548 | # negative data also autoscales to negative limits
|
547 | 549 | ax.plot([1, 2], [-1, -2])
|
548 | 550 | assert ax.get_ylim() == (-2, 2)
|
| 551 | + |
| 552 | + |
| 553 | +def test_radial_locator_wrapping(): |
| 554 | + # Check that the locator is always wrapped inside a RadialLocator |
| 555 | + # and that RaidialAxis.isDefault_majloc is set correctly. |
| 556 | + fig, ax = plt.subplots(subplot_kw={'projection': 'polar'}) |
| 557 | + assert ax.yaxis.isDefault_majloc |
| 558 | + assert isinstance(ax.yaxis.get_major_locator(), RadialLocator) |
| 559 | + |
| 560 | + # set an explicit locator |
| 561 | + locator = mticker.MaxNLocator(3) |
| 562 | + ax.yaxis.set_major_locator(locator) |
| 563 | + assert not ax.yaxis.isDefault_majloc |
| 564 | + assert isinstance(ax.yaxis.get_major_locator(), RadialLocator) |
| 565 | + assert ax.yaxis.get_major_locator().base is locator |
| 566 | + |
| 567 | + ax.clear() # reset to the default locator |
| 568 | + assert ax.yaxis.isDefault_majloc |
| 569 | + assert isinstance(ax.yaxis.get_major_locator(), RadialLocator) |
| 570 | + |
| 571 | + ax.set_rticks([0, 1, 2, 3]) # implicitly sets a FixedLocator |
| 572 | + assert not ax.yaxis.isDefault_majloc # because of the fixed ticks |
| 573 | + assert isinstance(ax.yaxis.get_major_locator(), RadialLocator) |
| 574 | + assert isinstance(ax.yaxis.get_major_locator().base, mticker.FixedLocator) |
| 575 | + |
| 576 | + ax.clear() |
| 577 | + |
| 578 | + ax.set_rgrids([0, 1, 2, 3]) # implicitly sets a FixedLocator |
| 579 | + assert not ax.yaxis.isDefault_majloc # because of the fixed ticks |
| 580 | + assert isinstance(ax.yaxis.get_major_locator(), RadialLocator) |
| 581 | + assert isinstance(ax.yaxis.get_major_locator().base, mticker.FixedLocator) |
| 582 | + |
| 583 | + ax.clear() |
| 584 | + |
| 585 | + ax.set_yscale("log") # implicitly sets a LogLocator |
| 586 | + # Note that the LogLocator is still considered the default locator |
| 587 | + # for the log scale |
| 588 | + assert ax.yaxis.isDefault_majloc |
| 589 | + assert isinstance(ax.yaxis.get_major_locator(), RadialLocator) |
| 590 | + assert isinstance(ax.yaxis.get_major_locator().base, mticker.LogLocator) |
0 commit comments