Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Reuse scale from sharing axis when calling cla(). #12831

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 26, 2018

Conversation

anntzer
Copy link
Contributor

@anntzer anntzer commented Nov 18, 2018

The previous code, which called

mscale.scale_factory(self._sharex.xaxis.get_scale(), self.xaxis)

assumed that this would be sufficient to "copy" a scale object, but in
fact this fails to copy e.g. the base of log scales, so the log base
would be reset to its default (=10).

Instead, just share the scale object, as is done when creating a
shared axis.

This implies that Scales should be reusable across multiple Axis, hence
the added note in the docstring. (Note that right now, LogScale objects
use the info of whether the axis is an x or a y axis to decide
whether to request arguments named basex or basey; it would not
be too difficult to change the signature of LogScale to always take a
base argument instead (which would be a more reasonable signature
too...); the main problem would be the API difference with loglog(..., basex=..., basey=...) -- but on the other hand it's not as if Scales
were commonly instantiated by end users (for example one cannot even
pass a Scale object to set_scale(!))).

Helps a bit for #12819; at least now the bottom right plot goes to using log-2 instead of log-10 after the reset.

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant
  • New features are documented, with examples if plot related
  • Documentation is sphinx and numpydoc compliant
  • Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

@anntzer anntzer added this to the v3.1 milestone Nov 18, 2018

thresh: The degree above which to crop the data.
"""
mscale.ScaleBase.__init__(self)
Copy link
Member

Choose a reason for hiding this comment

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

Even though ScaleBase.__init__ does not exist currently, I think we should nevertheless include a super().__init__(). This generally good code style and leaves us with the chance of introducing ScaleBase.__init__ later without breaking derieved scale classes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure

@jklymak
Copy link
Member

jklymak commented Nov 18, 2018

This seems right to me, if sharing means two axises have the same scales (which I think they should).

@anntzer
Copy link
Contributor Author

anntzer commented Nov 18, 2018

if sharing means two axises have the same scales (which I think they should).

Right now (before this PR) they "do", except that they don't after a call to cla() if the scale constructor takes additional arguments, as the scale constructor for the shared axes won't get these additional arguments. Which is what this PR is fixing.

The previous code, which called

    mscale.scale_factory(self._sharex.xaxis.get_scale(), self.xaxis)

assumed that this would be sufficient to "copy" a scale object, but in
fact this fails to copy e.g. the base of log scales, so the log base
would be reset to its default (=10).

Instead, just share the scale object, as is done when *creating* a
shared axis.

This implies that Scales should be reusable across multiple Axis, hence
the added note in the docstring.  (Note that right now, LogScale objects
use the info of whether the axis is an `x` or a `y` axis to decide
whether to request arguments named `basex` or `basey`; it would not
be too difficult to change the signature of LogScale to always take a
`base` argument instead (which would be a more reasonable signature
too...); the main problem would be the API difference with `loglog(...,
basex=..., basey=...)` -- but on the other hand it's not as if Scales
were commonly instantiated by end users (for example one cannot even
pass a Scale object to `set_scale`(!))).
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

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

I think this is better than the current behaviour. We should also discuss deprecating the axis kwarg/property, since I'm not convinced its used, and can't really imagine its use.

@anntzer
Copy link
Contributor Author

anntzer commented Nov 19, 2018

In the middle of my long commit message there's the explanation for the (silly, IMO) use of the axis argument:

(Note that right now, LogScale objects use the info of whether the axis is an x or a y axis to decide whether to request arguments named basex or basey; it would not be too difficult to change the signature of LogScale to always take a base argument instead (which would be a more reasonable signature too...); the main problem would be the API difference with loglog(..., basex=..., basey=...) -- but on the other hand it's not as if Scales were commonly instantiated by end users (for example one cannot even pass a Scale object to set_scale(!))).

The other problem is that this would also break third-party scale classes, e.g. https://github.com/matplotlib/mpl-probscale/blob/master/probscale/probscale.py#L95. I guess we could implement rather silly introspecting code to figure out whether the Scale implements the old or the new signature...

Other than these "practical" issues I agree with getting rid of the axis argument.

@timhoffm timhoffm merged commit 0f03057 into matplotlib:master Dec 26, 2018
@anntzer anntzer deleted the scalereuse branch December 26, 2018 13:47
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.

3 participants