From fca65edaf167aeb07f1be655ba5724cf5168af91 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Mon, 30 Dec 2019 14:54:52 +0100 Subject: [PATCH] Code style cleanup --- .../contourf_log.py | 2 +- .../images_contours_and_fields/pcolor_demo.py | 2 +- .../mathtext_examples.py | 4 ++-- examples/userdemo/colormap_normalizations.py | 4 ++-- .../userdemo/colormap_normalizations_power.py | 2 +- lib/matplotlib/_layoutbox.py | 4 ++-- lib/matplotlib/animation.py | 2 +- lib/matplotlib/artist.py | 1 - lib/matplotlib/axes/_axes.py | 2 +- lib/matplotlib/axes/_base.py | 4 ++-- lib/matplotlib/backend_bases.py | 2 +- lib/matplotlib/backend_tools.py | 2 +- lib/matplotlib/backends/backend_svg.py | 4 +--- lib/matplotlib/contour.py | 2 +- lib/matplotlib/dates.py | 19 +++++++++---------- lib/matplotlib/hatch.py | 2 +- lib/matplotlib/image.py | 2 +- lib/matplotlib/legend.py | 2 +- lib/matplotlib/mathtext.py | 4 ++-- lib/matplotlib/tests/test_figure.py | 4 ++-- lib/matplotlib/tests/test_triangulation.py | 2 +- lib/matplotlib/ticker.py | 4 ++-- lib/matplotlib/tri/triinterpolate.py | 2 +- lib/mpl_toolkits/axisartist/axis_artist.py | 6 +++--- lib/mpl_toolkits/mplot3d/axis3d.py | 4 ++-- tutorials/colors/colormapnorms.py | 4 ++-- 26 files changed, 44 insertions(+), 48 deletions(-) diff --git a/examples/images_contours_and_fields/contourf_log.py b/examples/images_contours_and_fields/contourf_log.py index f728946dae6c..813282249cd9 100644 --- a/examples/images_contours_and_fields/contourf_log.py +++ b/examples/images_contours_and_fields/contourf_log.py @@ -20,7 +20,7 @@ # A low hump with a spike coming out. # Needs to have z/colour axis on a log scale so we see both hump and spike. # linear scale only shows the spike. -Z1 = np.exp(-(X)**2 - (Y)**2) +Z1 = np.exp(-X**2 - Y**2) Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2) z = Z1 + 50 * Z2 diff --git a/examples/images_contours_and_fields/pcolor_demo.py b/examples/images_contours_and_fields/pcolor_demo.py index bd8bf89ae281..398188c9de8e 100644 --- a/examples/images_contours_and_fields/pcolor_demo.py +++ b/examples/images_contours_and_fields/pcolor_demo.py @@ -89,7 +89,7 @@ # A low hump with a spike coming out. # Needs to have z/colour axis on a log scale so we see both hump and spike. # linear scale only shows the spike. -Z1 = np.exp(-(X)**2 - (Y)**2) +Z1 = np.exp(-X**2 - Y**2) Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2) Z = Z1 + 50 * Z2 diff --git a/examples/text_labels_and_annotations/mathtext_examples.py b/examples/text_labels_and_annotations/mathtext_examples.py index 34b4456381b9..6d8be49599cf 100644 --- a/examples/text_labels_and_annotations/mathtext_examples.py +++ b/examples/text_labels_and_annotations/mathtext_examples.py @@ -72,7 +72,7 @@ def doall(): plt.gca().set_yticklabels("", visible=False) # Gap between lines in axes coords - line_axesfrac = (1. / (n_lines)) + line_axesfrac = 1 / n_lines # Plotting header demonstration formula full_demo = mathext_demos[0] @@ -82,7 +82,7 @@ def doall(): # Plotting features demonstration formulae for i_line in range(1, n_lines): - baseline = 1 - (i_line) * line_axesfrac + baseline = 1 - i_line * line_axesfrac baseline_next = baseline - line_axesfrac title = mathtext_titles[i_line] + ":" fill_color = ['white', mpl_blue_rvb][i_line % 2] diff --git a/examples/userdemo/colormap_normalizations.py b/examples/userdemo/colormap_normalizations.py index b13d7f213cf5..419a4b5051aa 100644 --- a/examples/userdemo/colormap_normalizations.py +++ b/examples/userdemo/colormap_normalizations.py @@ -21,7 +21,7 @@ # z/colour axis on a log scale so we see both hump and spike. linear # scale only shows the spike. -Z1 = np.exp(-(X)**2 - (Y)**2) +Z1 = np.exp(-X**2 - Y**2) Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2) Z = Z1 + 50 * Z2 @@ -41,7 +41,7 @@ # sine wave in Y. We can remove the power law using a PowerNorm. X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)] -Z1 = (1 + np.sin(Y * 10.)) * X**(2.) +Z1 = (1 + np.sin(Y * 10.)) * X**2 fig, ax = plt.subplots(2, 1) diff --git a/examples/userdemo/colormap_normalizations_power.py b/examples/userdemo/colormap_normalizations_power.py index 77f052b28ac6..6ea9a01ceca2 100644 --- a/examples/userdemo/colormap_normalizations_power.py +++ b/examples/userdemo/colormap_normalizations_power.py @@ -18,7 +18,7 @@ sine wave in Y. We can remove the power law using a PowerNorm. ''' X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)] -Z1 = (1 + np.sin(Y * 10.)) * X**(2.) +Z1 = (1 + np.sin(Y * 10.)) * X**2 fig, ax = plt.subplots(2, 1) diff --git a/lib/matplotlib/_layoutbox.py b/lib/matplotlib/_layoutbox.py index 8d680d85f936..a57171da76f2 100644 --- a/lib/matplotlib/_layoutbox.py +++ b/lib/matplotlib/_layoutbox.py @@ -350,7 +350,7 @@ def _is_subplotspec_layoutbox(self): Helper to check if this layoutbox is the layoutbox of a subplotspec ''' - name = (self.name).split('.')[-1] + name = self.name.split('.')[-1] return name[:2] == 'ss' def _is_gridspec_layoutbox(self): @@ -358,7 +358,7 @@ def _is_gridspec_layoutbox(self): Helper to check if this layoutbox is the layoutbox of a gridspec ''' - name = (self.name).split('.')[-1] + name = self.name.split('.')[-1] return name[:8] == 'gridspec' def find_child_subplots(self): diff --git a/lib/matplotlib/animation.py b/lib/matplotlib/animation.py index 54c9016283c0..bc4d0149fa81 100644 --- a/lib/matplotlib/animation.py +++ b/lib/matplotlib/animation.py @@ -89,7 +89,7 @@ def correct_roundoff(x, dpi, n): wnew = int(w * dpi / n) * n / dpi hnew = int(h * dpi / n) * n / dpi - return (correct_roundoff(wnew, dpi, n), correct_roundoff(hnew, dpi, n)) + return correct_roundoff(wnew, dpi, n), correct_roundoff(hnew, dpi, n) # A registry for available MovieWriter classes diff --git a/lib/matplotlib/artist.py b/lib/matplotlib/artist.py index 32b44caac643..67208a60a608 100644 --- a/lib/matplotlib/artist.py +++ b/lib/matplotlib/artist.py @@ -200,7 +200,6 @@ def axes(self, new_axes): self._axes = new_axes if new_axes is not None and new_axes is not self: self.stale_callback = _stale_axes_callback - return new_axes @property def stale(self): diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 702b6a0db813..2af0a2da6811 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -610,7 +610,7 @@ def invert(x): secax.set_xlabel('Period [s]') plt.show() """ - if (location in ['top', 'bottom'] or isinstance(location, Number)): + if location in ['top', 'bottom'] or isinstance(location, Number): secondary_ax = SecondaryAxis(self, 'x', location, functions, **kwargs) self.add_child_axes(secondary_ax) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index c5aee3b45320..eb22bcd2b4e4 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -2523,7 +2523,7 @@ def tol(x): return 1e-5 * abs(x) + 1e-8 'minposy', self.yaxis, self._ymargin, y_stickies, self.set_ybound) def _get_axis_list(self): - return (self.xaxis, self.yaxis) + return self.xaxis, self.yaxis def _get_axis_map(self): """ @@ -3954,7 +3954,7 @@ def _get_view(self): """ xmin, xmax = self.get_xlim() ymin, ymax = self.get_ylim() - return (xmin, xmax, ymin, ymax) + return xmin, xmax, ymin, ymax def _set_view(self, view): """ diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index 4ad82687ebc3..33f190b1eb11 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -2876,7 +2876,7 @@ def press_zoom(self, event): """Callback for mouse button press in zoom to rect mode.""" # If we're already in the middle of a zoom, pressing another # button works to "cancel" - if self._ids_zoom != []: + if self._ids_zoom: for zoom_id in self._ids_zoom: self.canvas.mpl_disconnect(zoom_id) self.release(event) diff --git a/lib/matplotlib/backend_tools.py b/lib/matplotlib/backend_tools.py index c95df5deb320..08ed565dff77 100644 --- a/lib/matplotlib/backend_tools.py +++ b/lib/matplotlib/backend_tools.py @@ -868,7 +868,7 @@ def _press(self, event): # If we're already in the middle of a zoom, pressing another # button works to "cancel" - if self._ids_zoom != []: + if self._ids_zoom: self._cancel_action() if event.button == 1: diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index 493bb362d12d..2b08ab1d5696 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -1193,15 +1193,13 @@ def print_svg(self, filename, *args, **kwargs): fh = TextIOWrapper(fh, 'utf-8') detach = True - result = self._print_svg(filename, fh, **kwargs) + self._print_svg(filename, fh, **kwargs) # Detach underlying stream from wrapper so that it remains open in # the caller. if detach: fh.detach() - return result - def print_svgz(self, filename, *args, **kwargs): with cbook.open_file_cm(filename, "wb") as fh, \ gzip.GzipFile(mode='w', fileobj=fh) as gzipwriter: diff --git a/lib/matplotlib/contour.py b/lib/matplotlib/contour.py index b85b85761845..5c3b1e3ca358 100644 --- a/lib/matplotlib/contour.py +++ b/lib/matplotlib/contour.py @@ -1429,7 +1429,7 @@ def _process_args(self, *args, **kwargs): if (t != self.ax.transData and any(t.contains_branch_seperately(self.ax.transData))): trans_to_data = t - self.ax.transData - pts = (np.vstack([x.flat, y.flat]).T) + pts = np.vstack([x.flat, y.flat]).T transformed_pts = trans_to_data.transform(pts) x = transformed_pts[..., 0] y = transformed_pts[..., 1] diff --git a/lib/matplotlib/dates.py b/lib/matplotlib/dates.py index 8c88a6a35c8b..7f4b52e54439 100644 --- a/lib/matplotlib/dates.py +++ b/lib/matplotlib/dates.py @@ -889,16 +889,15 @@ def __init__(self, locator, tz=None, defaultfmt='%Y-%m-%d'): self._tz = tz self.defaultfmt = defaultfmt self._formatter = DateFormatter(self.defaultfmt, tz) - self.scaled = {DAYS_PER_YEAR: rcParams['date.autoformatter.year'], - DAYS_PER_MONTH: rcParams['date.autoformatter.month'], - 1.0: rcParams['date.autoformatter.day'], - 1. / HOURS_PER_DAY: rcParams['date.autoformatter.hour'], - 1. / (MINUTES_PER_DAY): - rcParams['date.autoformatter.minute'], - 1. / (SEC_PER_DAY): - rcParams['date.autoformatter.second'], - 1. / (MUSECONDS_PER_DAY): - rcParams['date.autoformatter.microsecond']} + self.scaled = { + DAYS_PER_YEAR: rcParams['date.autoformatter.year'], + DAYS_PER_MONTH: rcParams['date.autoformatter.month'], + 1: rcParams['date.autoformatter.day'], + 1 / HOURS_PER_DAY: rcParams['date.autoformatter.hour'], + 1 / MINUTES_PER_DAY: rcParams['date.autoformatter.minute'], + 1 / SEC_PER_DAY: rcParams['date.autoformatter.second'], + 1 / MUSECONDS_PER_DAY: rcParams['date.autoformatter.microsecond'] + } def _set_locator(self, locator): self._locator = locator diff --git a/lib/matplotlib/hatch.py b/lib/matplotlib/hatch.py index cc426e7310b1..a1e3172bb066 100644 --- a/lib/matplotlib/hatch.py +++ b/lib/matplotlib/hatch.py @@ -95,7 +95,7 @@ def __init__(self, hatch, density): self.num_vertices = 0 else: self.num_shapes = ((self.num_rows // 2 + 1) * (self.num_rows + 1) + - (self.num_rows // 2) * (self.num_rows)) + (self.num_rows // 2) * self.num_rows) self.num_vertices = (self.num_shapes * len(self.shape_vertices) * (1 if self.filled else 2)) diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 6f7addebc159..ae6e0fa0b131 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -684,7 +684,7 @@ def set_data(self, A): raise TypeError("Image data of dtype {} cannot be converted to " "float".format(self._A.dtype)) - if (self._A.ndim == 3 and self._A.shape[-1] == 1): + if self._A.ndim == 3 and self._A.shape[-1] == 1: # If just one dimension assume scalar and apply colormap self._A = self._A[:, :, 0] diff --git a/lib/matplotlib/legend.py b/lib/matplotlib/legend.py index ba2750eac6f4..5b8d6aeed31e 100644 --- a/lib/matplotlib/legend.py +++ b/lib/matplotlib/legend.py @@ -1048,7 +1048,7 @@ def _get_anchored_bbox(self, loc, bbox, parentbbox, renderer): c = anchor_coefs[loc] fontsize = renderer.points_to_pixels(self._fontsize) - container = parentbbox.padded(-(self.borderaxespad) * fontsize) + container = parentbbox.padded(-self.borderaxespad * fontsize) anchored_box = bbox.anchored(c, container=container) return anchored_box.x0, anchored_box.y0 diff --git a/lib/matplotlib/mathtext.py b/lib/matplotlib/mathtext.py index bfcff195f13a..9f1417a01a73 100644 --- a/lib/matplotlib/mathtext.py +++ b/lib/matplotlib/mathtext.py @@ -568,7 +568,7 @@ def _get_font(self, font): def _get_offset(self, font, glyph, fontsize, dpi): if font.postscript_name == 'Cmex10': - return ((glyph.height/64.0/2.0) + (fontsize/3.0 * dpi/72.0)) + return (glyph.height / 64 / 2) + (fontsize/3 * dpi/72) return 0. def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True): @@ -2025,7 +2025,7 @@ def __init__(self, c, height, depth, state, always=False, factor=None): shift = 0 if state.font != 0: if factor is None: - factor = (target_total) / (char.height + char.depth) + factor = target_total / (char.height + char.depth) state.fontsize *= factor char = Char(sym, state) diff --git a/lib/matplotlib/tests/test_figure.py b/lib/matplotlib/tests/test_figure.py index 884947fdd6d0..8374717f3238 100644 --- a/lib/matplotlib/tests/test_figure.py +++ b/lib/matplotlib/tests/test_figure.py @@ -42,8 +42,8 @@ def test_align_labels(): for i in range(3): ax = fig.add_subplot(gs[2, i]) - ax.set_xlabel('XLabel2 %d' % (i)) - ax.set_ylabel('YLabel2 %d' % (i)) + ax.set_xlabel(f'XLabel2 {i}') + ax.set_ylabel(f'YLabel2 {i}') if i == 2: ax.plot(np.arange(0, 1e4, 10)) diff --git a/lib/matplotlib/tests/test_triangulation.py b/lib/matplotlib/tests/test_triangulation.py index de694da34062..fe4f9c16979d 100644 --- a/lib/matplotlib/tests/test_triangulation.py +++ b/lib/matplotlib/tests/test_triangulation.py @@ -941,7 +941,7 @@ def meshgrid_triangles(n): tri = [] for i in range(n-1): for j in range(n-1): - a = i + j*(n) + a = i + j*n b = (i+1) + j*n c = i + (j+1)*n d = (i+1) + (j+1)*n diff --git a/lib/matplotlib/ticker.py b/lib/matplotlib/ticker.py index 842f506eb55d..1e6880e4b818 100644 --- a/lib/matplotlib/ticker.py +++ b/lib/matplotlib/ticker.py @@ -1977,7 +1977,7 @@ def le(self, x): 'Return the largest n: n*step <= x.' d, m = divmod(x, self.step) if self.closeto(m / self.step, 1): - return (d + 1) + return d + 1 return d def ge(self, x): @@ -1985,7 +1985,7 @@ def ge(self, x): d, m = divmod(x, self.step) if self.closeto(m / self.step, 0): return d - return (d + 1) + return d + 1 class MaxNLocator(Locator): diff --git a/lib/matplotlib/tri/triinterpolate.py b/lib/matplotlib/tri/triinterpolate.py index 3a5a123b7ce1..399fe2764fcb 100644 --- a/lib/matplotlib/tri/triinterpolate.py +++ b/lib/matplotlib/tri/triinterpolate.py @@ -1125,7 +1125,7 @@ def compute_geom_weights(self): weights = np.zeros([np.size(self._triangles, 0), 3]) tris_pts = self._tris_pts for ipt in range(3): - p0 = tris_pts[:, (ipt) % 3, :] + p0 = tris_pts[:, ipt % 3, :] p1 = tris_pts[:, (ipt+1) % 3, :] p2 = tris_pts[:, (ipt-1) % 3, :] alpha1 = np.arctan2(p1[:, 1]-p0[:, 1], p1[:, 0]-p0[:, 0]) diff --git a/lib/mpl_toolkits/axisartist/axis_artist.py b/lib/mpl_toolkits/axisartist/axis_artist.py index 1f449caa407e..8dfad4c5a98e 100644 --- a/lib/mpl_toolkits/axisartist/axis_artist.py +++ b/lib/mpl_toolkits/axisartist/axis_artist.py @@ -334,7 +334,7 @@ def draw(self, renderer): text_ref_angle = self._get_text_ref_angle() offset_ref_angle = self._get_offset_ref_angle() - theta = (offset_ref_angle)/180.*np.pi + theta = np.deg2rad(offset_ref_angle) dd = self._get_offset_radius() dx, dy = dd * np.cos(theta), dd * np.sin(theta) offset_tr.translate(dx, dy) @@ -357,7 +357,7 @@ def get_window_extent(self, renderer): text_ref_angle = self._get_text_ref_angle() offset_ref_angle = self._get_offset_ref_angle() - theta = (offset_ref_angle)/180.*np.pi + theta = np.deg2rad(offset_ref_angle) dd = self._get_offset_radius() dx, dy = dd * np.cos(theta), dd * np.sin(theta) offset_tr.translate(dx, dy) @@ -722,7 +722,7 @@ def LABELPAD(self): @LABELPAD.setter def LABELPAD(self, v): - return self.label.set_pad(v) + self.label.set_pad(v) def __init__(self, axes, helper, diff --git a/lib/mpl_toolkits/mplot3d/axis3d.py b/lib/mpl_toolkits/mplot3d/axis3d.py index bee7a4446b01..ff140647f0c0 100644 --- a/lib/mpl_toolkits/mplot3d/axis3d.py +++ b/lib/mpl_toolkits/mplot3d/axis3d.py @@ -389,7 +389,7 @@ def d_interval(self): @d_interval.setter def d_interval(self, minmax): - return self.set_data_interval(*minmax) + self.set_data_interval(*minmax) @property def v_interval(self): @@ -397,7 +397,7 @@ def v_interval(self): @d_interval.setter def v_interval(self, minmax): - return self.set_view_interval(*minmax) + self.set_view_interval(*minmax) # Use classes to look at different data limits diff --git a/tutorials/colors/colormapnorms.py b/tutorials/colors/colormapnorms.py index 84244b15e6b6..ccb419a810e1 100644 --- a/tutorials/colors/colormapnorms.py +++ b/tutorials/colors/colormapnorms.py @@ -54,7 +54,7 @@ # A low hump with a spike coming out of the top right. Needs to have # z/colour axis on a log scale so we see both hump and spike. linear # scale only shows the spike. -Z1 = np.exp(-(X)**2 - (Y)**2) +Z1 = np.exp(-X**2 - Y**2) Z2 = np.exp(-(X * 10)**2 - (Y * 10)**2) Z = Z1 + 50 * Z2 @@ -126,7 +126,7 @@ N = 100 X, Y = np.mgrid[0:3:complex(0, N), 0:2:complex(0, N)] -Z1 = (1 + np.sin(Y * 10.)) * X**(2.) +Z1 = (1 + np.sin(Y * 10.)) * X**2 fig, ax = plt.subplots(2, 1) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy