GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Better choice of offset-text. by anntzer · Pull Request #5785 · matplotlib/matplotlib

Conversation

@anntzer

@anntzer anntzer commented Jan 2, 2016

Copy link
Copy Markdown
Contributor

The axis offset text is chosen as follows:

xlims => offsettext
123, 189 => 0
12341, 12349 => 12340
99999.5, 100010.5 => 100000 # (also a test for #5780)
99990.5, 100000.5 => 100000
1233999, 1234001 => 1234000

(and the same for negative limits).

See #5755.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tacaswell tacaswell added the status: needs review label Jan 2, 2016
@tacaswell tacaswell added this to the next major release (2.0) milestone Jan 2, 2016
@WeatherGod

WeatherGod commented Jan 6, 2016

Copy link
Copy Markdown
Member

I have some test cases from a while back when I last tried to come up with a better offset text logic. These test cases really helped explore the possible edge cases in that attempt. You might find it useful (the test data, that is, not the code): https://gist.github.com/WeatherGod/272f4022bf7a8ca12ff4

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer

anntzer commented Jan 6, 2016

Copy link
Copy Markdown
Contributor Author

Thanks @WeatherGod, I incorporated them in the test suite and slightly changed the algorithm. Now, the main condition of whether to use the offset is whether there are two common significant digits at the beginning of every label (allowing for negative labels as discussed above, I think that's the main questionable choice remaining).

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer

anntzer commented Jan 6, 2016

Copy link
Copy Markdown
Contributor Author

(hum, the failing test seems to work for me (and doesn't involve offset texts))

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

tacaswell
tacaswell reviewed Jan 7, 2016
View reviewed changes
Comment thread lib/matplotlib/tests/test_ticker.py Outdated

@tacaswell tacaswell Jan 7, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This needs an @cleanup decorator

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@anntzer anntzer Jan 7, 2016

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

As it is, the @cleanup decorator doesn't support generative tests. I'll write an patch for that first.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tacaswell tacaswell Jan 7, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Awesome. That is something that has driven me crazy a couple of times. I have dealt with it by putting the decorator on the called function and creating all of the figures/axes in that function.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@anntzer anntzer Jan 7, 2016

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

See #5809.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@anntzer
anntzer force-pushed the better-offsettext-choice branch from 6c2089d to 313a998 Compare January 7, 2016 03:53
@anntzer anntzer mentioned this pull request Jan 7, 2016
Support generative tests in @cleanup. #5809
Merged
@WeatherGod

WeatherGod commented Jan 27, 2016

Copy link
Copy Markdown
Member

Huh, never seen this error before: "RuntimeError: In set_text: could not load glyph". Also, this branch needs rebasing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer
anntzer force-pushed the better-offsettext-choice branch from 313a998 to 0a9df25 Compare January 27, 2016 20:00
@anntzer

anntzer commented Jan 27, 2016

Copy link
Copy Markdown
Contributor Author

Rebased. I cannot reproduce the glyph-loading errors locally.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

QuLogic
QuLogic reviewed Feb 18, 2016
View reviewed changes
Comment thread lib/matplotlib/ticker.py
abs_min, abs_max = sorted([abs(float(lmin)), abs(float(lmax))])
# Only use offset if there are at least two ticks and every tick has
# the same sign.
if lmin == lmax or lmin <= 0 <= lmax:

@QuLogic QuLogic Feb 18, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can move this section above the absolute values to short-circuit a little earlier.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@anntzer
anntzer force-pushed the better-offsettext-choice branch from 0a9df25 to 39efb99 Compare February 18, 2016 08:27
@tacaswell tacaswell closed this Feb 18, 2016
@tacaswell tacaswell reopened this Feb 18, 2016
@tacaswell tacaswell added status: needs review and removed status: needs review labels Feb 18, 2016
@anntzer
anntzer force-pushed the better-offsettext-choice branch from 39efb99 to 80de215 Compare February 21, 2016 17:32
@tacaswell tacaswell mentioned this pull request Mar 21, 2016
Offset and scaling factors in axis format #4376 #6086
Closed
VincentVandalon
VincentVandalon reviewed Mar 21, 2016
View reviewed changes
Comment thread lib/matplotlib/ticker.py

def _set_offset(self, range):
# offset of 20,001 is 20,000, for example
def _compute_offset(self):

@VincentVandalon VincentVandalon Mar 21, 2016

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I fully agree that renaming this method was really needed; the new name actually reflects the purpose of the function.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@tacaswell tacaswell Mar 21, 2016

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Contra my reluctance to change the public API at all, changing anything with a leading _ is fair game.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@QuLogic QuLogic mentioned this pull request Mar 26, 2016
Make @cleanup *really* support generative tests. #6022
Merged
@efiring

efiring commented May 2, 2016

Copy link
Copy Markdown
Member

This is failing the two tests in which left==right. It's not clear to me whether the problem is in the algorithm, or in the tests.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

anntzer added 3 commits May 1, 2016 18:07
@anntzer
Better choice of offset-text.
9a4ecfb
The axis offset text is chosen as follows:

xlims => offsettext
123, 189 => 0
12341, 12349 => 12340
99999.5, 100010.5 => 100000 # (also a test for matplotlib#5780)
99990.5, 100000.5 => 100000
1233999, 1234001 => 1234000

(and the same for negative limits).

See matplotlib#5755.
@anntzer
Only use offset if it saves >=2 sig. digits.
f37fd3d
Tests cases courtesy of @WeatherGod.  Slightly improved numerical
accuracy.
@anntzer
Slightly more efficient impl.; more tests.
0c39a78
@anntzer

anntzer commented May 2, 2016

Copy link
Copy Markdown
Contributor Author

The test failure was probably masked at some point by the misuse of a generative test. Anyways, this comes down to a policy choice for the left == right case. I guess that "by continuity", we should just let the offset be equal to the single value in that case (say the values were x-eps and x+eps, then it would be normal for x (rounded to ~eps) to be the offset, so we should keep that as eps->0).
Thoughts?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@efiring

efiring commented May 2, 2016

Copy link
Copy Markdown
Member

The present algorithm is giving (1, 1, 1) and (123, 123, 120) as left, right, offset. Nonsingular is expanding the actual left, right ranges to (0.999, 1.001) and (122.877, 123.123). So the test cases with left==right are not really special cases. Either we like what the algorithm does, or we don't. I still don't completely understand what the algorithm's criteria are, but the results at least look reasonable, so I would be inclined to just change the tests to match. Maybe the tests should actually be changed to use the values provided by the present implementation of nonsingular rather than feeding in equal numbers, since otherwise a change to nonsingular would cause this test to fail for reasons not related to the algorithm it is testing.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer
Fix test values.
9d0acb2
@anntzer
anntzer force-pushed the better-offsettext-choice branch from 80de215 to 9d0acb2 Compare May 2, 2016 04:13
@anntzer

anntzer commented May 2, 2016

Copy link
Copy Markdown
Contributor Author

OK, now I remember what I did: an offset text is used if it "saves" at least two significant digits, i.e. if the length of the (low, high) range is no more than a hundredth of the largest power of ten below high. So yes, the (1, 1, 1) and (123, 123, 120) outputs are expected given the effect of nonsingular. I rewrote the tests (still using equal left and right for now because using different left and right is basically already tested) and rebased on master.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@WeatherGod

WeatherGod commented May 2, 2016

Copy link
Copy Markdown
Member

This is looking good to me. Were there any remaining concerns? Do we need to update any documentation about the improved offset text algorithm?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer

anntzer commented May 2, 2016

Copy link
Copy Markdown
Contributor Author

I can add a snippet like "The default offset-text choice was changed to only use significant digits that are common to all ticks (e.g. 1231..1239 -> 1230, instead of 1231), except when they straddle a relatively large multiple of a power of ten in which case that multiple is chosen (e.g. 1999..2001->2000)." Looks good?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@efiring

efiring commented May 2, 2016

Copy link
Copy Markdown
Member

@anntzer Yes, adding that explanation would be good.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer
Add What's new entry.
782b8a1
@anntzer

anntzer commented May 2, 2016

Copy link
Copy Markdown
Contributor Author

Done.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dopplershift

dopplershift commented May 11, 2016

Copy link
Copy Markdown
Contributor

Looks like the only failure on AppVeyor was spurious. Anyone with proper permissions wanna restart the appveyor run so this can go green and be merged?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@efiring efiring closed this May 11, 2016
@efiring efiring reopened this May 11, 2016
@efiring efiring added status: needs review and removed status: needs review labels May 11, 2016
@efiring

efiring commented May 11, 2016

Copy link
Copy Markdown
Member

I don't see a way to restart just one appveyor test, so I triggered the whole set of checks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@dopplershift

dopplershift commented May 11, 2016 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

If you have permissions, you can log into AppVeyor and re-run the build. Unfortunately, it doesn't key off of GitHub permissions; those permissions are managed manually by whoever owns the AppVeyor project (looks like @mdboom )

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@efiring
efiring merged commit 4e1792b into matplotlib:master May 11, 2016
@efiring efiring removed the status: needs review label May 11, 2016
efiring added a commit that referenced this pull request May 11, 2016
@efiring
Merge pull request #5785 from anntzer/better-offsettext-choice
beb08c8
Better choice of offset-text.
@efiring

efiring commented May 11, 2016

Copy link
Copy Markdown
Member

Backported to v2.x as beb08c8.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anntzer
anntzer deleted the better-offsettext-choice branch May 11, 2016 18:30
@anntzer anntzer mentioned this pull request May 11, 2016
Better choice of axes offset value #5755
Closed
@anntzer anntzer mentioned this pull request Sep 13, 2016
set offset threshold to 4 #7104
Closed
@petehuang petehuang mentioned this pull request Jan 10, 2017
Minor offsetText formatting improvement #4451
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

v2.0.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@anntzer @WeatherGod @efiring @dopplershift @tacaswell @QuLogic @VincentVandalon
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.