Skip to content

Deprecate smart_bounds handling in Axis and Spine #11004

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 2 commits into from
Jul 17, 2019
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
6 changes: 6 additions & 0 deletions doc/api/next_api_changes/2019-07-16-EF.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Deprecations
````````````

The "smart_bounds" functionality is deprecated. This includes
``Axis.set_smart_bounds()``, ``Axis.get_smart_bounds()``,
``Spine.set_smart_bounds()``, and ``Spine.get_smart_bounds()``.
9 changes: 0 additions & 9 deletions examples/ticks_and_spines/spine_placement_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('center')
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

Expand All @@ -34,8 +32,6 @@
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position('zero')
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

Expand All @@ -46,8 +42,6 @@
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position(('axes', 0.1))
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

Expand All @@ -58,8 +52,6 @@
ax.spines['right'].set_color('none')
ax.spines['bottom'].set_position(('data', 2))
ax.spines['top'].set_color('none')
ax.spines['left'].set_smart_bounds(True)
ax.spines['bottom'].set_smart_bounds(True)
ax.xaxis.set_ticks_position('bottom')
ax.yaxis.set_ticks_position('left')

Expand All @@ -71,7 +63,6 @@ def adjust_spines(ax, spines):
for loc, spine in ax.spines.items():
if loc in spines:
spine.set_position(('outward', 10)) # outward by 10 points
spine.set_smart_bounds(True)
else:
spine.set_color('none') # don't draw spine

Expand Down
6 changes: 4 additions & 2 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ def __init__(self, axes, pickradius=15):
self.callbacks = cbook.CallbackRegistry()

self._autolabelpos = True
self._smart_bounds = False
self._smart_bounds = False # Deprecated in 3.2

self.label = self._get_label()
self.labelpad = rcParams['axes.labelpad']
Expand Down Expand Up @@ -1085,11 +1085,13 @@ def get_ticklabel_extents(self, renderer):
bbox2 = mtransforms.Bbox.from_extents(0, 0, 0, 0)
return bbox, bbox2

@cbook.deprecated("3.2")
def set_smart_bounds(self, value):
"""Set the axis to have smart bounds."""
self._smart_bounds = value
self.stale = True

@cbook.deprecated("3.2")
def get_smart_bounds(self):
"""Return whether the axis has smart bounds."""
return self._smart_bounds
Expand Down Expand Up @@ -1121,7 +1123,7 @@ def _update_ticks(self):
if view_low > view_high:
view_low, view_high = view_high, view_low

if self._smart_bounds and ticks:
if self._smart_bounds and ticks: # _smart_bounds is deprecated in 3.2
# handle inverted limits
data_low, data_high = sorted(self.get_data_interval())
locs = np.sort([tick.get_loc() for tick in ticks])
Expand Down
7 changes: 5 additions & 2 deletions lib/matplotlib/spines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import matplotlib
from matplotlib import cbook, docstring, rcParams
from matplotlib.artist import allow_rasterization
import matplotlib.cbook as cbook
import matplotlib.transforms as mtransforms
import matplotlib.patches as mpatches
import matplotlib.path as mpath
Expand Down Expand Up @@ -56,7 +57,7 @@ def __init__(self, axes, spine_type, path, **kwargs):
self.set_transform(self.axes.transData) # default transform

self._bounds = None # default bounds
self._smart_bounds = False
self._smart_bounds = False # deprecated in 3.2

# Defer initial position determination. (Not much support for
# non-rectangular axes is currently implemented, and this lets
Expand All @@ -77,6 +78,7 @@ def __init__(self, axes, spine_type, path, **kwargs):
# Note: This cannot be calculated until this is added to an Axes
self._patch_transform = mtransforms.IdentityTransform()

@cbook.deprecated("3.2")
def set_smart_bounds(self, value):
"""Set the spine and associated axis to have smart bounds."""
self._smart_bounds = value
Expand All @@ -88,6 +90,7 @@ def set_smart_bounds(self, value):
self.axes.xaxis.set_smart_bounds(value)
self.stale = True

@cbook.deprecated("3.2")
def get_smart_bounds(self):
"""Return whether the spine has smart bounds."""
return self._smart_bounds
Expand Down Expand Up @@ -268,7 +271,7 @@ def _adjust_location(self):
raise ValueError('unknown spine spine_type: %s' %
self.spine_type)

if self._smart_bounds:
if self._smart_bounds: # deprecated in 3.2
# attempt to set bounds in sophisticated way

# handle inverted limits
Expand Down