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

Skip to content

Commit 5eace1e

Browse files
committed
Small cleanups.
Mostly formatting/markup. Changed the `__str__` of Axes to include the actual subclass name, which is more informative IMO. Slightly reworded the warning on tight_layout failure; in the original wording, I felt that "its" tended to refer to figure rather than tight_layout, which is nonsensical.
1 parent 225a4a0 commit 5eace1e

5 files changed

Lines changed: 79 additions & 114 deletions

File tree

lib/matplotlib/axes/_base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,8 @@ class _AxesBase(martist.Artist):
414414
_shared_y_axes = cbook.Grouper()
415415

416416
def __str__(self):
417-
return "Axes(%g,%g;%gx%g)" % tuple(self._position.bounds)
417+
return "{0}({1[0]:g},{1[1]:g};{1[2]:g}x{1[3]:g})".format(
418+
type(self).__name__, self._position.bounds)
418419

419420
def __init__(self, fig, rect,
420421
facecolor=None, # defaults to rc axes.facecolor

lib/matplotlib/backend_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ class ToolHome(ViewsPositionsBase):
732732
class ToolBack(ViewsPositionsBase):
733733
"""Move back up the view lim stack"""
734734

735-
description = 'Back to previous view'
735+
description = 'Back to previous view'
736736
image = 'back.png'
737737
default_keymap = rcParams['keymap.back']
738738
_on_trigger = 'back'

lib/matplotlib/figure.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ def add_axes(self, *args, **kwargs):
958958
# check that an axes of this type doesn't already exist, if it
959959
# does, set it as active and return it
960960
ax = self._axstack.get(key)
961-
if ax is not None and isinstance(ax, projection_class):
961+
if isinstance(ax, projection_class):
962962
self.sca(ax)
963963
return ax
964964

@@ -1860,12 +1860,10 @@ def subplots_adjust(self, *args, **kwargs):
18601860
for ax in self.axes:
18611861
if not isinstance(ax, SubplotBase):
18621862
# Check if sharing a subplots axis
1863-
if (ax._sharex is not None and
1864-
isinstance(ax._sharex, SubplotBase)):
1863+
if isinstance(ax._sharex, SubplotBase):
18651864
ax._sharex.update_params()
18661865
ax.set_position(ax._sharex.figbox)
1867-
elif (ax._sharey is not None and
1868-
isinstance(ax._sharey, SubplotBase)):
1866+
elif isinstance(ax._sharey, SubplotBase):
18691867
ax._sharey.update_params()
18701868
ax.set_position(ax._sharey.figbox)
18711869
else:
@@ -1972,8 +1970,8 @@ def get_tightbbox(self, renderer):
19721970

19731971
return bbox_inches
19741972

1975-
def tight_layout(self, renderer=None, pad=1.08, h_pad=None,
1976-
w_pad=None, rect=None):
1973+
def tight_layout(self, renderer=None, pad=1.08, h_pad=None, w_pad=None,
1974+
rect=None):
19771975
"""
19781976
Adjust subplot parameters to give specified padding.
19791977
@@ -1991,23 +1989,20 @@ def tight_layout(self, renderer=None, pad=1.08, h_pad=None,
19911989
labels) will fit into. Default is (0, 0, 1, 1).
19921990
"""
19931991

1994-
from .tight_layout import (get_renderer, get_tight_layout_figure,
1995-
get_subplotspec_list)
1992+
from .tight_layout import (
1993+
get_renderer, get_subplotspec_list, get_tight_layout_figure)
19961994

19971995
subplotspec_list = get_subplotspec_list(self.axes)
19981996
if None in subplotspec_list:
1999-
warnings.warn("This figure includes Axes that are not "
2000-
"compatible with tight_layout, so its "
2001-
"results might be incorrect.")
1997+
warnings.warn("This figure includes Axes that are not compatible "
1998+
"with tight_layout, so results might be incorrect.")
20021999

20032000
if renderer is None:
20042001
renderer = get_renderer(self)
20052002

2006-
kwargs = get_tight_layout_figure(self, self.axes, subplotspec_list,
2007-
renderer,
2008-
pad=pad, h_pad=h_pad, w_pad=w_pad,
2009-
rect=rect)
2010-
2003+
kwargs = get_tight_layout_figure(
2004+
self, self.axes, subplotspec_list, renderer,
2005+
pad=pad, h_pad=h_pad, w_pad=w_pad, rect=rect)
20112006
self.subplots_adjust(**kwargs)
20122007

20132008

0 commit comments

Comments
 (0)