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

Skip to content

Commit 4003603

Browse files
committed
Addresses fixes #1871 by making axis.set_scale private and adding
a wrapper function with depreciation warning.
1 parent f39cdb6 commit 4003603

2 files changed

Lines changed: 29 additions & 16 deletions

File tree

lib/matplotlib/axes.py

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

868868
# This overwrites the current formatter/locator
869-
self.xaxis.set_scale(self._sharex.xaxis.get_scale())
869+
self.xaxis._set_scale(self._sharex.xaxis.get_scale())
870870

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

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

891891
# This overwrites the current formatter/locator
892-
self.yaxis.set_scale(self._sharey.yaxis.get_scale())
892+
self.yaxis._set_scale(self._sharey.yaxis.get_scale())
893893

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

902902
self._autoscaleXon = True
903903
self._autoscaleYon = True
@@ -2575,7 +2575,7 @@ def set_xscale(self, value, **kwargs):
25752575
Different kwargs are accepted, depending on the scale:
25762576
%(scale_docs)s
25772577
"""
2578-
self.xaxis.set_scale(value, **kwargs)
2578+
self.xaxis._set_scale(value, **kwargs)
25792579
self.autoscale_view(scaley=False)
25802580
self._update_transScale()
25812581

@@ -2800,7 +2800,7 @@ def set_yscale(self, value, **kwargs):
28002800
Different kwargs are accepted, depending on the scale:
28012801
%(scale_docs)s
28022802
"""
2803-
self.yaxis.set_scale(value, **kwargs)
2803+
self.yaxis._set_scale(value, **kwargs)
28042804
self.autoscale_view(scalex=False)
28052805
self._update_transScale()
28062806

@@ -9076,7 +9076,7 @@ def matshow(self, Z, **kwargs):
90769076
return im
90779077

90789078
def get_default_bbox_extra_artists(self):
9079-
return [artist for artist in self.get_children()
9079+
return [artist for artist in self.get_children()
90809080
if artist.get_visible()]
90819081

90829082
def get_tightbbox(self, renderer, call_axes_locator=True):

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 matplotlib import MatplotlibDeprecationWarning as 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+
Deprecatted 1.3.
690+
691+
This sholud 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)