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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions examples/scales/custom_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,21 +38,19 @@ class MercatorLatitudeScale(mscale.ScaleBase):
http://en.wikipedia.org/wiki/Mercator_projection
"""

# The scale class must have a member ``name`` that defines the
# string used to select the scale. For example,
# ``gca().set_yscale("mercator")`` would be used to select this
# scale.
# The scale class must have a member ``name`` that defines the string used
# to select the scale. For example, ``gca().set_yscale("mercator")`` would
# be used to select this scale.
name = 'mercator'

def __init__(self, axis, *, thresh=np.deg2rad(85), **kwargs):
"""
Any keyword arguments passed to ``set_xscale`` and
``set_yscale`` will be passed along to the scale's
constructor.
Any keyword arguments passed to ``set_xscale`` and ``set_yscale`` will
be passed along to the scale's constructor.

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

super().__init__(axis)
if thresh >= np.pi / 2:
raise ValueError("thresh must be less than pi/2")
self.thresh = thresh
Expand Down
6 changes: 2 additions & 4 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -969,8 +969,7 @@ def cla(self):
x0, x1 = self._sharex.get_xlim()
self.set_xlim(x0, x1, emit=False,
auto=self._sharex.get_autoscalex_on())
self.xaxis._scale = mscale.scale_factory(
self._sharex.xaxis.get_scale(), self.xaxis)
self.xaxis._scale = self._sharex.xaxis._scale
else:
self.xaxis._set_scale('linear')
try:
Expand All @@ -984,8 +983,7 @@ def cla(self):
y0, y1 = self._sharey.get_ylim()
self.set_ylim(y0, y1, emit=False,
auto=self._sharey.get_autoscaley_on())
self.yaxis._scale = mscale.scale_factory(
self._sharey.yaxis.get_scale(), self.yaxis)
self.yaxis._scale = self._sharey.yaxis._scale
else:
self.yaxis._set_scale('linear')
try:
Expand Down
17 changes: 14 additions & 3 deletions lib/matplotlib/scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ class ScaleBase(object):
And optionally:
- :meth:`limit_range_for_scale`
"""

def __init__(self, axis, **kwargs):
r"""
Construct a new scale.

Note
----
The following note is for scale implementors.

For back-compatibility reasons, scales take an `~.Axis` object as first
argument. However, this argument should not be used: a single scale
object should be usable by multiple `~.Axis`\es at the same time.
"""

def get_transform(self):
"""
Return the :class:`~matplotlib.transforms.Transform` object
Expand Down Expand Up @@ -57,9 +71,6 @@ class LinearScale(ScaleBase):

name = 'linear'

def __init__(self, axis, **kwargs):
pass

def set_default_locators_and_formatters(self, axis):
"""
Set the locators and formatters to reasonable defaults for
Expand Down