FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Cleanup scales by anntzer · Pull Request #7144 · matplotlib/matplotlib · GitHub

Repository navigation

Cleanup scales - #7144

Merged
Kojoley merged 2 commits into
matplotlib:masterfrom
anntzer:cleanup-scales
Nov 13, 2016
Merged

Kojoley merged 2 commits into
matplotlib:masterfrom
anntzer:cleanup-scales

Conversation

anntzer commented Sep 20, 2016

Copy link
Copy Markdown
Contributor

Fixes #7143, together with some cleanups (in a separate commit).
There's a test failure (RMS=0.010) I can reproduce locally but I don't visually see any differences in the plots...

By the way the 1-1e-300 in the clipping of logit transforms is not very useful...

Comment thread lib/matplotlib/scale.py Outdated
return InvertedLog10Transform()
with np.errstate(invalid="ignore"):
a = np.where(a <= 0, self._fill_value, a)
np.log(a, a)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

nitpick: a = np.log(a) is much more common and readable IMO

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

There was a comment about returning a itself from _mask_non_positives, i.e. saving a copy. I make an extra copy in where but get it back here. I don't mind just writing this as return np.log(a) / np.log(self.base) + 1 either -- it's probably a premature optimization anyways...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Recommendation: np.log(a, out=a) keeps the memory and speed efficiency and improves the readability.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I personally tend to favor readability over memory and speed efficiency, but OK…

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I think the new version is not too bad:
return np.divide(np.log(a, out=a), np.log(self.base), out=a)

Comment thread lib/matplotlib/scale.py Outdated
a = np.where(a <= 0, self._fill_value, a)
np.log(a, a)
a /= np.log(self.base)
a += 1

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why do you add one here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

... because the previous version did so (by multiplying by base before taking the log, which comes down to the same)... I didn't figure out why so I just left it, but apparently that's not needed. Removed.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Eh… That was an odd choice from previous developers, and somehow very confusing considering the name of the functions. Thanks for clarifying.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It looks like this practice of multiplying by the base in the forward transform and dividing by it in the inverse dates back to 8327bd4. I don't understand it, but it seems like it would have a substantial effect on log plots. @mdboom, do you remember why this was being done? Is there something that depends on it?

Comment thread lib/matplotlib/scale.py Outdated

def transform_non_affine(self, a):
return ma.power(10.0, a) / 10.0
return ma.power(self.base, a - 1)

NelleV Sep 20, 2016 •
edited
Loading

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Why do you remove 1 here? (It is obviously linked to the +1 up there…)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It looks like we need tests to ensure that the inverse actually reverses the action of the transform for any transform with an inverse.

tacaswell added this to the 2.1 (next point release) milestone Sep 20, 2016

efiring commented Sep 20, 2016

Copy link
Copy Markdown
Member

@NelleV, can you revoke your "approval"? It is misleading, given that you pointed out a major bug.

anntzer commented Sep 20, 2016

Copy link
Copy Markdown
Contributor Author

I'm not sure what is the "major bug" you're talking about? I think as long as we either keep the +/-1 on both sides or get rid of it on both sides we're good?

Copy link
Copy Markdown
Contributor

Tests of the inverses sound like a good idea.

I must say I am lost with the +1 -1 issue, I can't see that in the diff any more.

efiring commented Sep 20, 2016

Copy link
Copy Markdown
Member

Sorry, the problem is that the review comments on this page are showing an outdated diff. The current proposed modification looks fine to me--but I still think we need to understand the consequences, if any, of the change in output that these modifications make. Doesn't it make a substantive difference somewhere in mpl when the log transform returns log10(x) instead of 1 + log10(x)?

Kojoley commented Sep 20, 2016 •
edited
Loading

Copy link
Copy Markdown
Member
Original code came from #3753 with this comment https://github.com//pull/3753#issuecomment-62970292 related to the +1/-1 > Ok, the problem that get_minpos is kind of specially crafted for log axes stays, but I fixed the logit tick locator with a hack for now. In case limits for the axis are outside ]0, 1[, I assume 1 - get_minpos() as axis limit. That defaults to 1 - 1e-7 and should be good for most cases.

anntzer commented Sep 20, 2016

Copy link
Copy Markdown
Contributor Author

@Kojoley I don't see how this is related?

efiring commented Sep 20, 2016

Copy link
Copy Markdown
Member

I'm wondering whether the +1 -1 business is actually a bug that has been present for nearly a decade, but that has mostly subtle effects. I'm also wondering whether it is related to #6915.

Kojoley commented Sep 20, 2016

Copy link
Copy Markdown
Member

NelleV previously requested changes Sep 21, 2016

NelleV left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I am attempting to cancel my approval :(

anntzer commented Sep 26, 2016

Copy link
Copy Markdown
Contributor Author

Could this be milestoned to 2.0? This gets rid of a spurious warning while maintaining full backcompatibility.

tacaswell modified the milestones: 2.0 (style change major release), 2.1 (next point release), 2.0.1 (next bug fix release) Sep 27, 2016

Copy link
Copy Markdown
Member

milestoned an 2.0.1 so it will be backported, but will not block 2.0

efiring commented Nov 5, 2016

Copy link
Copy Markdown
Member

@anntzer I'm inclined to just merge this ASAP to be sure it gets into 2.0. It looks like the test failure is a very slight difference in one image. Would you replace the test image, please, so we can get the tests passing and proceed?

NelleV dismissed their stale review November 5, 2016 19:45

It's way to old.

efiring commented Nov 5, 2016

Copy link
Copy Markdown
Member

@anntzer It might be best to get #7410 merged and propagated up to master before re-checking the tests on this one; it's possible that with #7410, this one might change additional baseline images.

anntzer commented Nov 5, 2016

Copy link
Copy Markdown
Contributor Author

Ping me when #7410 is merged.

I'm pretty sure the diff is due to some floating point imprecision. For example, if I subtract 1 from the return value of LogTransformBase.transform_non_affine and add 1 back to the return value of InvertedLogTransformBase.transform_non_affine (what the previous version used to do), the RMS error slightly increases to 0.010.

efiring commented Nov 5, 2016

Copy link
Copy Markdown
Member

@anntzer, #7410 is merged.

anntzer commented Nov 5, 2016

Copy link
Copy Markdown
Contributor Author

done.

Comment thread lib/matplotlib/scale.py
base = 10.0

def inverted(self):
return InvertedLog10Transform()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

You could rewrite this like:

class Log10Transform(LogTransformBase):
    base = 10.0
    inverted = InvertedLog10Transform

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

No, because InvertedLog10Transform is not defined yet at that point. (InvertedLog10Transform could define inverted as a reference to the Log10Transform class but I decided to keep definitions symmetric.)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ah, yes. You are right.

NelleV left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Thanks @anntzer

NelleV changed the title Cleanup scales [MRG+1] Cleanup scales Nov 10, 2016

phobson left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

much improved! thanks for this.

phobson changed the title [MRG+1] Cleanup scales [MRG+2] Cleanup scales Nov 10, 2016
Kojoley merged commit 540fc5a into matplotlib:master Nov 13, 2016
Kojoley changed the title [MRG+2] Cleanup scales Cleanup scales Nov 13, 2016
Kojoley added a commit that referenced this pull request Nov 13, 2016

Kojoley commented Nov 13, 2016

Copy link
Copy Markdown
Member

Backported to v2.x as dc9e7ec

Kojoley commented Nov 13, 2016

Copy link
Copy Markdown
Member

I have broken master and v2.x by merging this.
At the point when the builds were made there was no test_log_margins test (it was restored by #7435).

anntzer deleted the cleanup-scales branch November 13, 2016 18:50
QuLogic modified the milestones: 2.0.1 (next bug fix release), 2.0 (style change major release) Dec 7, 2016
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants


Back | FazBrowse Home | New Git URL