|
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) |
0 commit comments