diff --git a/.flake8 b/.flake8 index c7e9114821ff..b7c36183b232 100644 --- a/.flake8 +++ b/.flake8 @@ -47,17 +47,13 @@ per-file-ignores = lib/matplotlib/tri/triinterpolate.py: E201, E221 lib/matplotlib/type1font.py: E731 - lib/mpl_toolkits/axes_grid/axes_rgb.py: E501 lib/mpl_toolkits/axes_grid1/axes_divider.py: E402, E501 - lib/mpl_toolkits/axes_grid1/axes_grid.py: E225 - lib/mpl_toolkits/axes_grid1/axes_size.py: E272, E501 + lib/mpl_toolkits/axes_grid1/axes_size.py: E272 lib/mpl_toolkits/axes_grid1/colorbar.py: E225, E501 - lib/mpl_toolkits/axes_grid1/inset_locator.py: E501 lib/mpl_toolkits/axisartist/angle_helper.py: E221 lib/mpl_toolkits/axisartist/clip_path.py: E225 lib/mpl_toolkits/axisartist/floating_axes.py: E225, E402, E501 lib/mpl_toolkits/axisartist/grid_helper_curvelinear.py: E225, E501 - lib/mpl_toolkits/tests/test_axes_grid1.py: E201, E202 doc/conf.py: E402, E501 doc/sphinxext/github.py: E302, E501 diff --git a/lib/mpl_toolkits/axes_grid/axes_rgb.py b/lib/mpl_toolkits/axes_grid/axes_rgb.py index 8ec680ec9db7..099e621c7830 100644 --- a/lib/mpl_toolkits/axes_grid/axes_rgb.py +++ b/lib/mpl_toolkits/axes_grid/axes_rgb.py @@ -1,7 +1,5 @@ -#from mpl_toolkits.axes_grid1.axes_rgb import * -from mpl_toolkits.axes_grid1.axes_rgb import make_rgb_axes, imshow_rgb, RGBAxesBase - -#import mpl_toolkits.axes_grid1.axes_rgb as axes_rgb_orig +from mpl_toolkits.axes_grid1.axes_rgb import ( + make_rgb_axes, imshow_rgb, RGBAxesBase) from mpl_toolkits.axisartist.axislines import Axes diff --git a/lib/mpl_toolkits/axes_grid1/axes_divider.py b/lib/mpl_toolkits/axes_grid1/axes_divider.py index 786d6096f513..40fb5af9b231 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_divider.py +++ b/lib/mpl_toolkits/axes_grid1/axes_divider.py @@ -10,9 +10,10 @@ object that can be used to set the axes_locator of the axes. """ -import matplotlib.transforms as mtransforms from matplotlib import cbook from matplotlib.axes import SubplotBase +from matplotlib.gridspec import SubplotSpec, GridSpec +import matplotlib.transforms as mtransforms from . import axes_size as Size @@ -347,9 +348,6 @@ def get_subplotspec(self): return None -from matplotlib.gridspec import SubplotSpec, GridSpec - - class SubplotDivider(Divider): """ The Divider class whose rectangle area is specified as a subplot geometry. @@ -539,32 +537,26 @@ def new_horizontal(self, size, pad=None, pack_start=False, **kwargs): instance of the given class. Otherwise, the same class of the main axes will be used. """ - if pad: if not isinstance(pad, Size._Base): - pad = Size.from_any(pad, - fraction_ref=self._xref) + pad = Size.from_any(pad, fraction_ref=self._xref) if pack_start: self._horizontal.insert(0, pad) self._xrefindex += 1 else: self._horizontal.append(pad) - if not isinstance(size, Size._Base): - size = Size.from_any(size, - fraction_ref=self._xref) - + size = Size.from_any(size, fraction_ref=self._xref) if pack_start: self._horizontal.insert(0, size) self._xrefindex += 1 locator = self.new_locator(nx=0, ny=self._yrefindex) else: self._horizontal.append(size) - locator = self.new_locator(nx=len(self._horizontal)-1, ny=self._yrefindex) - + locator = self.new_locator( + nx=len(self._horizontal) - 1, ny=self._yrefindex) ax = self._get_new_axes(**kwargs) ax.set_axes_locator(locator) - return ax def new_vertical(self, size, pad=None, pack_start=False, **kwargs): @@ -589,21 +581,16 @@ def new_vertical(self, size, pad=None, pack_start=False, **kwargs): instance of the given class. Otherwise, the same class of the main axes will be used. """ - if pad: if not isinstance(pad, Size._Base): - pad = Size.from_any(pad, - fraction_ref=self._yref) + pad = Size.from_any(pad, fraction_ref=self._yref) if pack_start: self._vertical.insert(0, pad) self._yrefindex += 1 else: self._vertical.append(pad) - if not isinstance(size, Size._Base): - size = Size.from_any(size, - fraction_ref=self._yref) - + size = Size.from_any(size, fraction_ref=self._yref) if pack_start: self._vertical.insert(0, size) self._yrefindex += 1 @@ -611,10 +598,8 @@ def new_vertical(self, size, pad=None, pack_start=False, **kwargs): else: self._vertical.append(size) locator = self.new_locator(nx=self._xrefindex, ny=len(self._vertical)-1) - ax = self._get_new_axes(**kwargs) ax.set_axes_locator(locator) - return ax def append_axes(self, position, size, pad=None, add_to_figure=True, diff --git a/lib/mpl_toolkits/axes_grid1/axes_grid.py b/lib/mpl_toolkits/axes_grid1/axes_grid.py index 3254cc9b8e34..ce4673638e50 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_grid.py +++ b/lib/mpl_toolkits/axes_grid1/axes_grid.py @@ -695,7 +695,7 @@ def _update_locators(self): (self._colorbar_location == 'right' and col == self._ncols-1)): locator = self._divider.new_locator( - nx=h_cb_pos[0], ny=v_ax_pos[self._nrows -1 - row]) + nx=h_cb_pos[0], ny=v_ax_pos[self._nrows - 1 - row]) self.cbar_axes[row].set_axes_locator(locator) elif ((self._colorbar_location == 'bottom' and row == self._nrows - 1) or diff --git a/lib/mpl_toolkits/axes_grid1/axes_size.py b/lib/mpl_toolkits/axes_grid1/axes_size.py index 56120107b1d0..91aa4123f04f 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_size.py +++ b/lib/mpl_toolkits/axes_grid1/axes_size.py @@ -52,7 +52,9 @@ def get_size(self, renderer): class Fixed(_Base): - "Simple fixed size with absolute part = *fixed_size* and relative part = 0" + """ + Simple fixed size with absolute part = *fixed_size* and relative part = 0. + """ def __init__(self, fixed_size): self.fixed_size = fixed_size @@ -63,7 +65,11 @@ def get_size(self, renderer): class Scaled(_Base): - "Simple scaled(?) size with absolute part = 0 and relative part = *scalable_size*" + """ + Simple scaled(?) size with absolute part = 0 and + relative part = *scalable_size*. + """ + def __init__(self, scalable_size): self._scalable_size = scalable_size diff --git a/lib/mpl_toolkits/axes_grid1/inset_locator.py b/lib/mpl_toolkits/axes_grid1/inset_locator.py index 19002aacab26..80955039d9cb 100644 --- a/lib/mpl_toolkits/axes_grid1/inset_locator.py +++ b/lib/mpl_toolkits/axes_grid1/inset_locator.py @@ -131,12 +131,11 @@ def __init__(self, parent_axes, zoom, loc, def get_extent(self, renderer): bb = TransformedBbox(self.axes.viewLim, self.parent_axes.transData) - x, y, w, h = bb.bounds fontsize = renderer.points_to_pixels(self.prop.get_size_in_points()) pad = self.pad * fontsize - - return abs(w * self.zoom) + 2 * pad, abs(h * self.zoom) + 2 * pad, pad, pad + return (abs(w * self.zoom) + 2 * pad, abs(h * self.zoom) + 2 * pad, + pad, pad) class BboxPatch(Patch): @@ -308,7 +307,7 @@ def __init__(self, bbox1, bbox2, loc1, loc2=None, **kwargs): if 'fill' in kwargs: Patch.__init__(self, **kwargs) else: - fill = ('fc' in kwargs) or ('facecolor' in kwargs) or ('color' in kwargs) + fill = bool({'fc', 'facecolor', 'color'}.intersection(kwargs)) Patch.__init__(self, fill=fill, **kwargs) self.bbox1 = bbox1 self.bbox2 = bbox2 @@ -328,10 +327,10 @@ def __init__(self, bbox1, bbox2, loc1a, loc2a, loc1b, loc2b, **kwargs): """ Connect two bboxes with a quadrilateral. - The quadrilateral is specified by two lines that start and end at corners - of the bboxes. The four sides of the quadrilateral are defined by the two - lines given, the line between the two corners specified in *bbox1* and the - line between the two corners specified in *bbox2*. + The quadrilateral is specified by two lines that start and end at + corners of the bboxes. The four sides of the quadrilateral are defined + by the two lines given, the line between the two corners specified in + *bbox1* and the line between the two corners specified in *bbox2*. Parameters ---------- @@ -666,7 +665,7 @@ def mark_inset(parent_axes, inset_axes, loc1, loc2, **kwargs): if 'fill' in kwargs: pp = BboxPatch(rect, **kwargs) else: - fill = ('fc' in kwargs) or ('facecolor' in kwargs) or ('color' in kwargs) + fill = bool({'fc', 'facecolor', 'color'}.intersection(kwargs)) pp = BboxPatch(rect, fill=fill, **kwargs) parent_axes.add_patch(pp) diff --git a/lib/mpl_toolkits/tests/test_axes_grid1.py b/lib/mpl_toolkits/tests/test_axes_grid1.py index 90aaf371f71a..8030028ab0f2 100644 --- a/lib/mpl_toolkits/tests/test_axes_grid1.py +++ b/lib/mpl_toolkits/tests/test_axes_grid1.py @@ -77,9 +77,9 @@ def test_twin_axes_empty_and_removed(): matplotlib.rcParams.update({"font.size": 8}) matplotlib.rcParams.update({"xtick.labelsize": 8}) matplotlib.rcParams.update({"ytick.labelsize": 8}) - generators = [ "twinx", "twiny", "twin" ] - modifiers = [ "", "host invisible", "twin removed", "twin invisible", - "twin removed\nhost invisible" ] + generators = ["twinx", "twiny", "twin"] + modifiers = ["", "host invisible", "twin removed", "twin invisible", + "twin removed\nhost invisible"] # Unmodified host subplot at the beginning for reference h = host_subplot(len(modifiers)+1, len(generators), 2) h.text(0.5, 0.5, "host_subplot", horizontalalignment="center",