Skip to content

Commit fb2da34

Browse files
committed
Merge pull request #1917 from tacaswell/priv_axis.set_scale
Make `axis.set_scale` private
2 parents 23c9734 + d2eb877 commit fb2da34

File tree

2 files changed

+28
-15
lines changed

2 files changed

+28
-15
lines changed

lib/matplotlib/axes.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -865,15 +865,15 @@ def cla(self):
865865
minl = self._sharex.xaxis.get_minor_locator()
866866

867867
# This overwrites the current formatter/locator
868-
self.xaxis.set_scale(self._sharex.xaxis.get_scale())
868+
self.xaxis._set_scale(self._sharex.xaxis.get_scale())
869869

870870
# Reset the formatter/locator
871871
self.xaxis.set_major_formatter(majf)
872872
self.xaxis.set_minor_formatter(minf)
873873
self.xaxis.set_major_locator(majl)
874874
self.xaxis.set_minor_locator(minl)
875875
else:
876-
self.xaxis.set_scale('linear')
876+
self.xaxis._set_scale('linear')
877877

878878
if self._sharey is not None:
879879
self.yaxis.major = self._sharey.yaxis.major
@@ -888,15 +888,15 @@ def cla(self):
888888
minl = self._sharey.yaxis.get_minor_locator()
889889

890890
# This overwrites the current formatter/locator
891-
self.yaxis.set_scale(self._sharey.yaxis.get_scale())
891+
self.yaxis._set_scale(self._sharey.yaxis.get_scale())
892892

893893
# Reset the formatter/locator
894894
self.yaxis.set_major_formatter(majf)
895895
self.yaxis.set_minor_formatter(minf)
896896
self.yaxis.set_major_locator(majl)
897897
self.yaxis.set_minor_locator(minl)
898898
else:
899-
self.yaxis.set_scale('linear')
899+
self.yaxis._set_scale('linear')
900900

901901
self._autoscaleXon = True
902902
self._autoscaleYon = True
@@ -2573,7 +2573,7 @@ def set_xscale(self, value, **kwargs):
25732573
Different kwargs are accepted, depending on the scale:
25742574
%(scale_docs)s
25752575
"""
2576-
self.xaxis.set_scale(value, **kwargs)
2576+
self.xaxis._set_scale(value, **kwargs)
25772577
self.autoscale_view(scaley=False)
25782578
self._update_transScale()
25792579

@@ -2798,7 +2798,7 @@ def set_yscale(self, value, **kwargs):
27982798
Different kwargs are accepted, depending on the scale:
27992799
%(scale_docs)s
28002800
"""
2801-
self.yaxis.set_scale(value, **kwargs)
2801+
self.yaxis._set_scale(value, **kwargs)
28022802
self.autoscale_view(scalex=False)
28032803
self._update_transScale()
28042804

lib/matplotlib/axis.py

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import numpy as np
1919
import warnings
2020

21+
from cbook import mplDeprecation
22+
2123
GRIDLINE_INTERPOLATION_STEPS = 180
2224

2325

@@ -652,7 +654,7 @@ def __init__(self, axes, pickradius=15):
652654
self._minor_tick_kw = dict()
653655

654656
self.cla()
655-
self.set_scale('linear')
657+
self._set_scale('linear')
656658

657659
def set_label_coords(self, x, y, transform=None):
658660
"""
@@ -683,6 +685,17 @@ def get_scale(self):
683685
return self._scale.name
684686

685687
def set_scale(self, value, **kwargs):
688+
"""
689+
Deprecated 1.3.
690+
691+
This should be a private function (moved to _set_scale)
692+
"""
693+
warnings.warn("This function has been made private and moved"
694+
"to `_set_scale`. This wrapper function will be "
695+
"removed in 1.4", mplDeprecation)
696+
self._set_scale(value, **kwargs)
697+
698+
def _set_scale(self, value, **kwargs):
686699
self._scale = mscale.scale_factory(value, self, **kwargs)
687700
self._scale.set_default_locators_and_formatters(self)
688701

@@ -982,19 +995,19 @@ def _update_ticks(self, renderer):
982995
interval_expanded = interval
983996
else:
984997
interval_expanded = interval[1], interval[0]
985-
998+
986999
if hasattr(self, '_get_pixel_distance_along_axis'):
9871000
# normally, one does not want to catch all exceptions that could possibly happen, but it
9881001
# is not clear exactly what exceptions might arise from a user's projection (their rendition
9891002
# of the Axis object). So, we catch all, with the idea that one would rather potentially
9901003
# lose a tick from one side of the axis or another, rather than see a stack trace.
9911004
try:
992-
ds1 = self._get_pixel_distance_along_axis(interval_expanded[0], -0.5)
1005+
ds1 = self._get_pixel_distance_along_axis(interval_expanded[0], -0.5)
9931006
except:
9941007
warnings.warn("Unable to find pixel distance along axis for interval padding; assuming no interval padding needed.")
9951008
ds1 = 0.0
9961009
try:
997-
ds2 = self._get_pixel_distance_along_axis(interval_expanded[1], +0.5)
1010+
ds2 = self._get_pixel_distance_along_axis(interval_expanded[1], +0.5)
9981011
except:
9991012
warnings.warn("Unable to find pixel distance along axis for interval padding; assuming no interval padding needed.")
10001013
ds2 = 0.0
@@ -1636,11 +1649,11 @@ def _get_pixel_distance_along_axis(self, where, perturb):
16361649
Implementing this routine for an axis is optional; if present, it will ensure that no
16371650
ticks are lost due to round-off at the extreme ends of an axis.
16381651
"""
1639-
1652+
16401653
# Note that this routine does not work for a polar axis, because of the 1e-10 below. To
16411654
# do things correctly, we need to use rmax instead of 1e-10 for a polar axis. But
1642-
# since we do not have that kind of information at this point, we just don't try to
1643-
# pad anything for the theta axis of a polar plot.
1655+
# since we do not have that kind of information at this point, we just don't try to
1656+
# pad anything for the theta axis of a polar plot.
16441657
if self.axes.name == 'polar':
16451658
return 0.0
16461659

@@ -1653,7 +1666,7 @@ def _get_pixel_distance_along_axis(self, where, perturb):
16531666
pix = trans.transform_point((where, 1e-10))
16541667
ptp = transinv.transform_point((pix[0] + perturb, pix[1])) # perturb the pixel.
16551668
dx = abs(ptp[0] - where)
1656-
1669+
16571670
return dx
16581671

16591672
def get_label_position(self):
@@ -1941,7 +1954,7 @@ def _get_pixel_distance_along_axis(self, where, perturb):
19411954
ticks are lost due to round-off at the extreme ends of an axis.
19421955
"""
19431956

1944-
#
1957+
#
19451958
# first figure out the pixel location of the "where" point. We use 1e-10 for the
19461959
# x point, so that we remain compatible with log axes.
19471960
#

0 commit comments

Comments
 (0)