Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make LogLocator only return one tick out of range#24436

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
dstansby wants to merge7 commits intomatplotlib:mainfromdstansby:test-loglocator

Conversation

dstansby
Copy link
Member

@dstansbydstansby commentedNov 12, 2022
edited
Loading

PR Summary

I'm working on thoroughly testingLogLocator, and this PR is a start. There is a new parametrized test that checks the tick locations for a given vmin, vmax.

I have also changed the logic for geting the tick locations slightly. Before the locator was returning two ticks belowvmin, and two ticks abovevmax. Looking through the commit history I cannot find any reason to do this, so to make the logic clear I have changed this to returning one tick belowvmin/one ablovevmax (as is needed for clipping and potentially autoscaling). I've then documented this logic in the docstring.

The changed tests are just removing the extra tick at each end - because there is still a single "out of bounds" tick returned at each end no figures should change with this PR.

PR Checklist

Tests and Styling

  • Has pytest style unit tests (andpytest passes).
  • IsFlake 8 compliant (installflake8-docstrings and runflake8 --docstring-convention=all).

Documentation

  • Documentation is sphinx and numpydoc compliant (the docs shouldbuild without error).
  • New plotting related features are documented with examples.

Release Notes

  • New features are marked with a.. versionadded:: directive in the docstring and documented indoc/users/next_whats_new/
  • API changes are marked with a.. versionchanged:: directive in the docstring and documented indoc/api/next_api_changes/
  • Release notes conform with instructions innext_whats_new/README.rst ornext_api_changes/README.rst

@QuLogic
Copy link
Member

I think it's been a long-standing confusion that locators don't have to return tick locations in (vmin, vmax). I'm not sure, but this might not be specific toLogLocator.

@dstansby
Copy link
MemberAuthor

This is good for review now - I changed to logic a bit (see changelog entry) and updated the docstring oftick_values to match.

@dstansbydstansby marked this pull request as ready for reviewDecember 1, 2022 11:12
@dstansbydstansby mentioned this pull requestDec 1, 2022
3 tasks
@QuLogic
Copy link
Member

The PR title is no longer correct now, I think?

@dstansbydstansby changed the titleAdd some more LogLocator testsMake LogLocator only return one tick out of rangeDec 15, 2022
@dstansby
Copy link
MemberAuthor

Ah thanks for catching - I've updated it 👍

@dstansbydstansby added this to thev3.8.0 milestoneJan 8, 2023
for the decades containing ``vmin`` and ``vmax``. If ``vmin`` or ``vmax``
are exactly on a decade this means no ticks above/below are returned.
Otherwise a single major tick is returned above/below, and for minor ticks
all the ticks in the decade containing ``vmin`` or ``vmax`` are returned.
Copy link
Member

Choose a reason for hiding this comment

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

Can this clarify the previous behaviour? Did we un-conditionally return an extra tick?

Copy link
Member

Choose a reason for hiding this comment

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

Before it was 1 or 2, now it is 0 or 1.

I think the question is MUST locators return extra or MAY locators return extra.

10**np.arange(-16.,16.2, 4.))
# note only -24 to +24 are visible
10**np.arange(-12.,12.2, 4.))
# note only -12 to +12 are visible
Copy link
Member

Choose a reason for hiding this comment

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

Was this comment wrong before?

@@ -2450,7 +2461,7 @@ def nonsingular(self, vmin, vmax):
vmin, vmax = 1, 10 # Initial range, no data plotted yet.
elif vmax <= 0:
_api.warn_external(
"Data hasnopositive values, and therefore cannot be "
"Data hasnon-positive values, and therefore cannot be "
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Data hasnon-positive values, and therefore cannot be "
"Data hasnopositive values, and therefore cannot be "

I think this one should stay as "no positive" as in the other blocks we clip vmin to a small positive value.

@@ -2359,7 +2368,7 @@ def tick_values(self, vmin, vmax):

if vmin <= 0.0 or not np.isfinite(vmin):
raise ValueError(
"Data hasnopositive values, and therefore can not be "
"Data hasnon-positive values, and therefore can not be "
Copy link
Member

Choose a reason for hiding this comment

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

This overall logic does not seem 10% correct because we are only checking vmin here and just below we ensure that vmin and vmax are sorted.

We also only get this error if the locator is not attached to as axis as in that case we silently clip vmin.

@tacaswell
Copy link
Member

My understanding is that locators MAY return at least 1 "extra" tick on either side to deal with clipping / float rounding issues when there might be a tick exactlyat vmin or vmax and we want to defer the clipping to draw time (both to be safe and to only have one place to go hunting for the bug).

The weird thing about LogLocator is that we get one expansion from the floor / ceiling logic and the a second from the "lets expand" which means in the general case we get 2 "extra" locations (the decade bracketing the vmin/vmax and the next one). However, I think the "special case" of vmin / vmax already being on a decade are far more likely due to conventions (at least the field I came out of) for always putting the view limits of a log axis to be on a decade so I think this is pushing us to the state of "no extra" in the most common case.

My risk calculus is that we have had things go wrong with too few ticks and I can not think of something that would go wrong with too many. Hence, I am wary of doing this trimming but not enough that I would block it.

@dstansby
Copy link
MemberAuthor

dstansby commentedFeb 3, 2023
edited
Loading

The weird thing about LogLocator is that we get one expansion from the floor / ceiling logic and the a second from the "lets expand"

I don't think this is right - we were getting two ticks just from this line (before this PR):

decades=np.arange(math.floor(log_vmin)-stride,math.ceil(log_vmax)+2*stride,stride)

e.g. iflog_vmin = 1.5 andstride=1, this will have ticks at log values of0, 1, 2..., where0 and1 are out of bounds.

I think the question is MUST locators return extra or MAY locators return extra.

Agreed. I'm not 100% sure on the answer to this, but would say that to be safe MUST return one extra seems sensible. I'll open a new issue to track deciding and documenting this.

My risk calculus is that we have had things go wrong with too few ticks and I can not think of something that would go wrong with too many.

The motivation for this PR was really to reduce internal tech debt I guess - returning one or two ticks didn't make sense to me. But I do agree that it's probably safer to leave this alone, so I will close this PR (and resurrect the testing bits without changing the logic). Thanks all for taking the time to carefully look over this 😃

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

@tacaswelltacaswelltacaswell left review comments

@jklymakjklymakjklymak left review comments

@timhoffmtimhoffmtimhoffm left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
v3.8.0
Development

Successfully merging this pull request may close these issues.

5 participants
@dstansby@QuLogic@tacaswell@jklymak@timhoffm

[8]ページ先頭

©2009-2025 Movatter.jp