Skip to content

added ChoiceLocator#8

Open
Sreekanth-M8 wants to merge 2 commits intor3kste:mainfrom
Sreekanth-M8:ChoiceLocator
Open

added ChoiceLocator#8
Sreekanth-M8 wants to merge 2 commits intor3kste:mainfrom
Sreekanth-M8:ChoiceLocator

Conversation

@Sreekanth-M8
Copy link
Copy Markdown
Collaborator

PR summary

added ChoiceLocator as per 20012

PR checklist

Copy link
Copy Markdown
Owner

@r3kste r3kste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sreekanth-M8 This looks good. As discussed, you can go ahead condense this solution to put as a comment to ask for initial feedback. There is just one minor comment about radial locator.

Copy link
Copy Markdown
Owner

@r3kste r3kste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran test_polar.py and left some comments about the failing tests.

  1. For Theta Tick, there is one test failing: lib/matplotlib/tests/test_polar.py::test_polar_theta_limits.

  2. For Radial Tick, there are a lot of tests failing.

As mentioned below, it would be better if we stick with only changing Theta ticks in this PR (as that is what the issue also expects).

Copy link
Copy Markdown
Owner

@r3kste r3kste left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sreekanth-M8 Sorry for the delay in the review. Apart from the below comments you can go ahead with implementing tests.

  1. See how Cartesian Axes Locators are tested and add similar tests for ChoiceLocator.
  2. Make sure previously existing tests with full circle plots still pass.
  3. Update the test image for lib/matplotlib/tests/test_polar.py::test_polar_theta_limits

"""

def __init__(self, base):
class ChoiceLocator(mticker.Locator):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add docstrings.


def __init__(self, base):
class ChoiceLocator(mticker.Locator):
def __init__(self, base=None, choices=None):
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Should base be optional here, considering for ThetaLocator it was not.
  2. I think we don't need to take choices as a parameter. Or is there a usecase to be able to control this?

Comment on lines 283 to +316
if _is_full_circle_deg(lim[0], lim[1]):
return np.deg2rad(min(lim)) + np.arange(8) * 2 * np.pi / 8
if (vmax - vmin > 60):
for ticks in self.choices:
in_range = (ticks >= vmin - tol) & (ticks <= vmax + tol)
ticks = ticks[in_range]
if len(ticks) > max_ticks:
continue
if len(ticks) == max_ticks:
if vmin != ticks[0]:
ticks[0] = vmin
if vmax != ticks[-1]:
ticks[-1] = vmax
return np.deg2rad(ticks)
if len(ticks) < max_ticks:
if vmin != ticks[0]:
if abs(ticks[0] - vmin) >= tick_interval:
ticks = np.concatenate(([vmin], ticks))
else:
ticks[0] = vmin
if vmax != ticks[-1]:
if len(ticks) < max_ticks:
if abs(vmax - ticks[-1]) >= tick_interval:
ticks = np.concatenate((ticks, [vmax]))
else:
ticks[-1] = vmax
else:
ticks[-1] = vmax
return np.deg2rad(ticks)
else:
return np.deg2rad(self.base())
ticks = self.choices[-1]
ticks = ticks[(ticks >= vmin - tol) & (ticks <= vmax + tol)]
return ticks
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The logic here is pretty convoluted, but seems to be correct. Can you add comments for each case?

ticks[-1] = vmax
return np.deg2rad(ticks)
else:
return np.deg2rad(self.base())
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move this check up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants