diff --git a/doc/sphinxext/github.py b/doc/sphinxext/github.py index 75c5ce10ae9d..d0b586256b9f 100644 --- a/doc/sphinxext/github.py +++ b/doc/sphinxext/github.py @@ -103,7 +103,6 @@ def ghuser_role(name, rawtext, text, lineno, inliner, options={}, content=[]): :param options: Directive options for customization. :param content: The directive content for customization. """ - app = inliner.document.settings.env.app ref = 'https://www.github.com/' + text node = nodes.reference(rawtext, text, refuri=ref, **options) return [node], [] diff --git a/examples/axes_grid1/demo_axes_grid.py b/examples/axes_grid1/demo_axes_grid.py index b21b288c355e..9cf356a1ba93 100644 --- a/examples/axes_grid1/demo_axes_grid.py +++ b/examples/axes_grid1/demo_axes_grid.py @@ -28,13 +28,10 @@ def demo_simple_grid(fig): axes_pad=0.05, label_mode="1", ) - Z, extent = get_demo_image() for ax in grid: - im = ax.imshow(Z, extent=extent, interpolation="nearest") - - # This only affects axes in first column and second row as share_all = - # False. + ax.imshow(Z, extent=extent, interpolation="nearest") + # This only affects axes in first column and second row as share_all=False. grid.axes_llc.set_xticks([-2, 0, 2]) grid.axes_llc.set_yticks([-2, 0, 2]) diff --git a/examples/axes_grid1/demo_edge_colorbar.py b/examples/axes_grid1/demo_edge_colorbar.py index 313790a9edfc..6603d5bb263a 100644 --- a/examples/axes_grid1/demo_edge_colorbar.py +++ b/examples/axes_grid1/demo_edge_colorbar.py @@ -41,7 +41,7 @@ def demo_bottom_cbar(fig): im = grid[i].imshow(Z, extent=extent, interpolation="nearest", cmap=cmaps[i//2]) if i % 2: - cbar = grid.cbar_axes[i//2].colorbar(im) + grid.cbar_axes[i//2].colorbar(im) for cax in grid.cbar_axes: cax.toggle_label(True) diff --git a/examples/event_handling/pick_event_demo.py b/examples/event_handling/pick_event_demo.py index 31b52cf4bed8..ad004abf3fa2 100644 --- a/examples/event_handling/pick_event_demo.py +++ b/examples/event_handling/pick_event_demo.py @@ -83,7 +83,7 @@ def pick_simple(): line, = ax1.plot(rand(100), 'o', picker=5) # 5 points tolerance # pick the rectangle - bars = ax2.bar(range(10), rand(10), picker=True) + ax2.bar(range(10), rand(10), picker=True) for label in ax2.get_xticklabels(): # make the xtick labels pickable label.set_picker(True) @@ -157,18 +157,17 @@ def onpick3(event): print('onpick3 scatter:', ind, x[ind], y[ind]) fig, ax = plt.subplots() - col = ax.scatter(x, y, 100*s, c, picker=True) - #fig.savefig('pscoll.eps') + ax.scatter(x, y, 100*s, c, picker=True) fig.canvas.mpl_connect('pick_event', onpick3) def pick_image(): # picking images (matplotlib.image.AxesImage) fig, ax = plt.subplots() - im1 = ax.imshow(rand(10, 5), extent=(1, 2, 1, 2), picker=True) - im2 = ax.imshow(rand(5, 10), extent=(3, 4, 1, 2), picker=True) - im3 = ax.imshow(rand(20, 25), extent=(1, 2, 3, 4), picker=True) - im4 = ax.imshow(rand(30, 12), extent=(3, 4, 3, 4), picker=True) + ax.imshow(rand(10, 5), extent=(1, 2, 1, 2), picker=True) + ax.imshow(rand(5, 10), extent=(3, 4, 1, 2), picker=True) + ax.imshow(rand(20, 25), extent=(1, 2, 3, 4), picker=True) + ax.imshow(rand(30, 12), extent=(3, 4, 3, 4), picker=True) ax.axis([0, 5, 0, 5]) def onpick4(event): diff --git a/examples/misc/demo_agg_filter.py b/examples/misc/demo_agg_filter.py index 8e638688a71d..a8e61de383de 100644 --- a/examples/misc/demo_agg_filter.py +++ b/examples/misc/demo_agg_filter.py @@ -187,8 +187,8 @@ def filtered_text(ax): Z = (Z1 - Z2) * 2 # draw - im = ax.imshow(Z, interpolation='bilinear', origin='lower', - cmap=cm.gray, extent=(-3, 3, -2, 2)) + ax.imshow(Z, interpolation='bilinear', origin='lower', + cmap=cm.gray, extent=(-3, 3, -2, 2)) levels = np.arange(-1.2, 1.6, 0.2) CS = ax.contour(Z, levels, origin='lower', diff --git a/examples/units/basic_units.py b/examples/units/basic_units.py index 50ca20675c5b..56ca528162c8 100644 --- a/examples/units/basic_units.py +++ b/examples/units/basic_units.py @@ -25,9 +25,7 @@ def __get__(self, obj, objtype=None): class TaggedValueMeta(type): def __init__(self, name, bases, dict): for fn_name in self._proxies: - try: - dummy = getattr(self, fn_name) - except AttributeError: + if not hasattr(self, fn_name): setattr(self, fn_name, ProxyDelegate(fn_name, self._proxies[fn_name])) diff --git a/examples/widgets/menu.py b/examples/widgets/menu.py index 326e28fd81a1..21fa00edbdaa 100644 --- a/examples/widgets/menu.py +++ b/examples/widgets/menu.py @@ -132,8 +132,6 @@ def __init__(self, fig, menuitems): maxw = max(item.labelwidth for item in menuitems) maxh = max(item.labelheight for item in menuitems) - totalh = self.numitems*maxh + (self.numitems + 1)*2*MenuItem.pady - x0 = 100 y0 = 400 diff --git a/lib/matplotlib/axes/_secondary_axes.py b/lib/matplotlib/axes/_secondary_axes.py index b5b4598439c6..3f0766fb3058 100644 --- a/lib/matplotlib/axes/_secondary_axes.py +++ b/lib/matplotlib/axes/_secondary_axes.py @@ -295,16 +295,14 @@ def _set_lims(self): if self._orientation == 'x': lims = self._parent.get_xlim() set_lim = self.set_xlim - trans = self.xaxis.get_transform() if self._orientation == 'y': lims = self._parent.get_ylim() set_lim = self.set_ylim - trans = self.yaxis.get_transform() order = lims[0] < lims[1] lims = self._functions[0](np.array(lims)) neworder = lims[0] < lims[1] if neworder != order: - # flip because the transform will take care of the flipping.. + # Flip because the transform will take care of the flipping. lims = lims[::-1] set_lim(lims) diff --git a/lib/matplotlib/backends/backend_gtk3.py b/lib/matplotlib/backends/backend_gtk3.py index 9f6d1f693c29..77df07a2733b 100644 --- a/lib/matplotlib/backends/backend_gtk3.py +++ b/lib/matplotlib/backends/backend_gtk3.py @@ -235,7 +235,7 @@ def motion_notify_event(self, widget, event): if event.is_hint: t, x, y, state = event.window.get_pointer() else: - x, y, state = event.x, event.y, event.get_state() + x, y = event.x, event.y # flipy so y=0 is bottom of canvas y = self.get_allocation().height - y @@ -582,7 +582,8 @@ def configure_subplots(self, button): toolfig = Figure(figsize=(6, 3)) canvas = self._get_canvas(toolfig) toolfig.subplots_adjust(top=0.9) - tool = SubplotTool(self.canvas.figure, toolfig) + # Need to keep a reference to the tool. + _tool = SubplotTool(self.canvas.figure, toolfig) w = int(toolfig.bbox.width) h = int(toolfig.bbox.height) diff --git a/lib/matplotlib/backends/backend_gtk3agg.py b/lib/matplotlib/backends/backend_gtk3agg.py index 8e5b991daf80..82ba6ef1cc9e 100644 --- a/lib/matplotlib/backends/backend_gtk3agg.py +++ b/lib/matplotlib/backends/backend_gtk3agg.py @@ -61,9 +61,8 @@ def blit(self, bbox=None): bbox = self.figure.bbox allocation = self.get_allocation() - w, h = allocation.width, allocation.height x = int(bbox.x0) - y = h - int(bbox.y1) + y = allocation.height - int(bbox.y1) width = int(bbox.x1) - int(bbox.x0) height = int(bbox.y1) - int(bbox.y0) diff --git a/lib/matplotlib/backends/backend_macosx.py b/lib/matplotlib/backends/backend_macosx.py index f88bf2bb8edc..ca32842ae55a 100644 --- a/lib/matplotlib/backends/backend_macosx.py +++ b/lib/matplotlib/backends/backend_macosx.py @@ -160,7 +160,8 @@ def prepare_configure_subplots(self): toolfig = Figure(figsize=(6, 3)) canvas = FigureCanvasMac(toolfig) toolfig.subplots_adjust(top=0.9) - tool = SubplotTool(self.canvas.figure, toolfig) + # Need to keep a reference to the tool. + _tool = SubplotTool(self.canvas.figure, toolfig) return canvas def set_message(self, message): diff --git a/lib/matplotlib/backends/backend_svg.py b/lib/matplotlib/backends/backend_svg.py index 220ece3911e2..6cdc3ffd7594 100644 --- a/lib/matplotlib/backends/backend_svg.py +++ b/lib/matplotlib/backends/backend_svg.py @@ -1026,15 +1026,10 @@ def _draw_text_as_text(self, gc, x, y, s, prop, angle, ismath, mtext=None): font = self._get_font(prop) font.set_text(s, 0.0, flags=LOAD_NO_HINTING) - fontsize = prop.get_size_in_points() - - fontfamily = font.family_name - fontstyle = prop.get_style() - attrib = {} # Must add "px" to workaround a Firefox bug - style['font-size'] = short_float_fmt(fontsize) + 'px' - style['font-family'] = str(fontfamily) + style['font-size'] = short_float_fmt(prop.get_size()) + 'px' + style['font-family'] = str(font.family_name) style['font-style'] = prop.get_style().lower() style['font-weight'] = str(prop.get_weight()).lower() attrib['style'] = generate_css(style) diff --git a/lib/matplotlib/cbook/deprecation.py b/lib/matplotlib/cbook/deprecation.py index c3393fc84a80..8920e55044fc 100644 --- a/lib/matplotlib/cbook/deprecation.py +++ b/lib/matplotlib/cbook/deprecation.py @@ -394,9 +394,7 @@ def _make_keyword_only(since, name, func=None): kwonly = [name for name in names[names.index(name):] if signature.parameters[name].kind == POK] func.__signature__ = signature.replace(parameters=[ - param.replace(kind=inspect.Parameter.KEYWORD_ONLY) - if param.name in kwonly - else param + param.replace(kind=KWO) if param.name in kwonly else param for param in signature.parameters.values()]) @functools.wraps(func) diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index ab2a40bda23b..049cdfeef7bc 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -1497,7 +1497,6 @@ def get_positions(self): ''' return an array containing the floating-point values of the positions ''' - segments = self.get_segments() pos = 0 if self.is_horizontal() else 1 return [segment[0, pos] for segment in self.get_segments()] diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index cc873c26cc9f..9372a66eaa5b 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -596,14 +596,9 @@ def update_ticks(self): called whenever the tick locator and/or tick formatter changes. """ ax = self.ax - # get the locator and formatter. Defaults to - # self.locator if not None.. + # Get the locator and formatter; defaults to self.locator if not None. locator, formatter = self._get_ticker_locator_formatter() - if self.orientation == 'vertical': - long_axis, short_axis = ax.yaxis, ax.xaxis - else: - long_axis, short_axis = ax.xaxis, ax.yaxis - + long_axis = ax.yaxis if self.orientation == 'vertical' else ax.xaxis if self._use_auto_colorbar_locator(): _log.debug('Using auto colorbar locator on colorbar') _log.debug('locator: %r', locator) @@ -643,10 +638,8 @@ def get_ticks(self, minor=False): """Return the x ticks as a list of locations.""" if self._manual_tick_data_values is None: ax = self.ax - if self.orientation == 'vertical': - long_axis, short_axis = ax.yaxis, ax.xaxis - else: - long_axis, short_axis = ax.xaxis, ax.yaxis + long_axis = ( + ax.yaxis if self.orientation == 'vertical' else ax.xaxis) return long_axis.get_majorticklocs() else: # We made the axes manually, the old way, and the ylim is 0-1, diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index d77d8a50b54e..e1f40be2841f 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -455,7 +455,7 @@ def _fnt_def_real(self, k, c, s, d, a, l): @_dispatch(247, state=_dvistate.pre, args=('u1', 'u4', 'u4', 'u4', 'u1')) def _pre(self, i, num, den, mag, k): - comment = self.file.read(k) + self.file.read(k) # comment in the dvi file if i != 2: raise ValueError("Unknown dvi format %d" % i) if num != 25400000 or den != 7227 * 2**16: diff --git a/lib/matplotlib/rcsetup.py b/lib/matplotlib/rcsetup.py index ea707a3068a8..ad68ef23a4fa 100644 --- a/lib/matplotlib/rcsetup.py +++ b/lib/matplotlib/rcsetup.py @@ -965,7 +965,7 @@ def validate_webagg_address(s): import socket try: socket.inet_aton(s) - except socket.error as e: + except socket.error: raise ValueError("'webagg.address' is not a valid IP address") return s raise ValueError("'webagg.address' is not a valid IP address") diff --git a/lib/matplotlib/sphinxext/plot_directive.py b/lib/matplotlib/sphinxext/plot_directive.py index 5b8f15fd5f49..58570c263716 100644 --- a/lib/matplotlib/sphinxext/plot_directive.py +++ b/lib/matplotlib/sphinxext/plot_directive.py @@ -518,7 +518,7 @@ def run_code(code, code_path, ns=None, function_name=None): if function_name is not None: exec(function_name + "()", ns) - except (Exception, SystemExit) as err: + except (Exception, SystemExit): raise PlotError(traceback.format_exc()) finally: os.chdir(pwd) @@ -584,11 +584,11 @@ def render_figures(code, code_path, output_dir, output_base, context, output_dir) else: img = ImageFile('%s_%02d' % (output_base, j), output_dir) - for format, dpi in formats: - if out_of_date(code_path, img.filename(format)): + for fmt, dpi in formats: + if out_of_date(code_path, img.filename(fmt)): all_exists = False break - img.formats.append(format) + img.formats.append(fmt) # assume that if we have one, we have them all if not all_exists: @@ -636,12 +636,12 @@ def render_figures(code, code_path, output_dir, output_base, context, img = ImageFile("%s_%02d_%02d" % (output_base, i, j), output_dir) images.append(img) - for format, dpi in formats: + for fmt, dpi in formats: try: - figman.canvas.figure.savefig(img.filename(format), dpi=dpi) - except Exception as err: + figman.canvas.figure.savefig(img.filename(fmt), dpi=dpi) + except Exception: raise PlotError(traceback.format_exc()) - img.formats.append(format) + img.formats.append(fmt) results.append((code_piece, images)) diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index 8b9840341bf5..0b1773bd5648 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -227,7 +227,7 @@ def make_tex(self, tex, fontsize): else: try: fh.write(s.encode('ascii')) - except UnicodeEncodeError as err: + except UnicodeEncodeError: _log.info("You are using unicode and latex, but have not " "enabled the 'text.latex.unicode' rcParam.") raise @@ -289,7 +289,7 @@ def make_tex_preview(self, tex, fontsize): else: try: fh.write(s.encode('ascii')) - except UnicodeEncodeError as err: + except UnicodeEncodeError: _log.info("You are using unicode and latex, but have not " "enabled the 'text.latex.unicode' rcParam.") raise diff --git a/lib/matplotlib/textpath.py b/lib/matplotlib/textpath.py index ae289f35f8f6..8122f24644c5 100644 --- a/lib/matplotlib/textpath.py +++ b/lib/matplotlib/textpath.py @@ -254,7 +254,7 @@ def get_glyphs_mathtext(self, prop, s, glyph_map=None, if char_id not in glyph_map: font.clear() font.set_size(self.FONT_SCALE, self.DPI) - glyph = font.load_char(ccode, flags=LOAD_NO_HINTING) + font.load_char(ccode, flags=LOAD_NO_HINTING) glyph_map_new[char_id] = font.get_path() xpositions.append(ox) @@ -371,9 +371,9 @@ def _get_ps_font_and_encoding(texname): # FreeType-synthesized charmap but the native ones (we can't # directly identify it but it's typically an Adobe charmap), and # directly load the dvi glyph indices using FT_Load_Char/load_char. - for charmap_name, charmap_code in [ - ("ADOBE_CUSTOM", 1094992451), - ("ADOBE_STANDARD", 1094995778), + for charmap_code in [ + 1094992451, # ADOBE_CUSTOM. + 1094995778, # ADOBE_STANDARD. ]: try: font.select_charmap(charmap_code) @@ -382,7 +382,6 @@ def _get_ps_font_and_encoding(texname): else: break else: - charmap_name = "" _log.warning("No supported encoding in font (%s).", font_bunch.filename) enc = None diff --git a/lib/mpl_toolkits/axes_grid1/axes_size.py b/lib/mpl_toolkits/axes_grid1/axes_size.py index 4edc50d323fc..112843c95ce6 100644 --- a/lib/mpl_toolkits/axes_grid1/axes_size.py +++ b/lib/mpl_toolkits/axes_grid1/axes_size.py @@ -111,7 +111,7 @@ def get_size(self, renderer): l1, l2 = self._axes.get_xlim() if self._aspect == "axes": ref_aspect = _get_axes_aspect(self._ref_ax) - aspect = ref_aspect/_get_axes_aspect(self._axes) + aspect = ref_aspect / _get_axes_aspect(self._axes) else: aspect = self._aspect diff --git a/lib/mpl_toolkits/axes_grid1/colorbar.py b/lib/mpl_toolkits/axes_grid1/colorbar.py index d12cc1dc4bf1..cb2bc8edea21 100644 --- a/lib/mpl_toolkits/axes_grid1/colorbar.py +++ b/lib/mpl_toolkits/axes_grid1/colorbar.py @@ -788,7 +788,7 @@ def on_changed(m): cb.set_clim(m.get_clim()) cb.update_bruteforce(m) - cbid = mappable.callbacksSM.connect('changed', on_changed) + mappable.callbacksSM.connect('changed', on_changed) mappable.colorbar = cb ax.figure.sca(ax) return cb diff --git a/lib/mpl_toolkits/axisartist/angle_helper.py b/lib/mpl_toolkits/axisartist/angle_helper.py index 58c0772c6f10..a4423f6367df 100644 --- a/lib/mpl_toolkits/axisartist/angle_helper.py +++ b/lib/mpl_toolkits/axisartist/angle_helper.py @@ -108,15 +108,16 @@ def select_step(v1, v2, nv, hour=False, include_last=True, cycle = 360. # for degree - if dv > 1./threshold_factor: + if dv > 1 / threshold_factor: step, factor = _select_step(dv) else: step, factor = select_step_sub(dv*threshold_factor) factor = factor * threshold_factor - f1, f2, fstep = v1*factor, v2*factor, step/factor - levs = np.arange(np.floor(f1/step), np.ceil(f2/step)+0.5, dtype=int) * step + levs = np.arange(np.floor(v1 * factor / step), + np.ceil(v2 * factor / step) + 0.5, + dtype=int) * step # n : number of valid levels. If there is a cycle, e.g., [0, 90, 180, # 270, 360], the grid line needs to be extended from 0 to 360, so @@ -128,7 +129,7 @@ def select_step(v1, v2, nv, hour=False, include_last=True, # we need to check the range of values # for example, -90 to 90, 0 to 360, - if factor == 1. and levs[-1] >= levs[0]+cycle: # check for cycle + if factor == 1. and levs[-1] >= levs[0] + cycle: # check for cycle nv = int(cycle / step) if include_last: levs = levs[0] + np.arange(0, nv+1, 1) * step diff --git a/lib/mpl_toolkits/axisartist/axis_artist.py b/lib/mpl_toolkits/axisartist/axis_artist.py index 2a6ca8fe4756..657adbc25776 100644 --- a/lib/mpl_toolkits/axisartist/axis_artist.py +++ b/lib/mpl_toolkits/axisartist/axis_artist.py @@ -1194,10 +1194,6 @@ def _draw_label2(self, renderer): if not self.label.get_visible(): return - fontprops = font_manager.FontProperties( - size=rcParams['axes.labelsize'], - weight=rcParams['axes.labelweight']) - if self._ticklabel_add_angle != self._axislabel_add_angle: if ((self.major_ticks.get_visible() and not self.major_ticks.get_tick_out())