diff --git a/lib/matplotlib/_constrained_layout.py b/lib/matplotlib/_constrained_layout.py index 87bbfabea321..56c69335816c 100644 --- a/lib/matplotlib/_constrained_layout.py +++ b/lib/matplotlib/_constrained_layout.py @@ -344,8 +344,6 @@ def _align_spines(fig, gs): height_ratios[rownummin[n]:(rownummax[n] + 1)]) for nn, ax in enumerate(axs[:-1]): - ss0 = ax.get_subplotspec() - # now compare ax to all the axs: # # If the subplotspecs have the same colnumXmax, then line diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 5f74f9e65133..1c6d333e61c9 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -7772,7 +7772,6 @@ def matshow(self, Z, **kwargs): """ Z = np.asanyarray(Z) - nr, nc = Z.shape kw = {'origin': 'upper', 'interpolation': 'nearest', 'aspect': 'equal', # (already the imshow default) diff --git a/lib/matplotlib/axes/_base.py b/lib/matplotlib/axes/_base.py index e304a780cbc8..b732c6e5779d 100644 --- a/lib/matplotlib/axes/_base.py +++ b/lib/matplotlib/axes/_base.py @@ -27,7 +27,6 @@ import matplotlib.font_manager as font_manager import matplotlib.text as mtext import matplotlib.image as mimage -from matplotlib.artist import allow_rasterization from matplotlib.rcsetup import cycler, validate_axisbelow @@ -2540,7 +2539,7 @@ def _update_title_position(self, renderer): title.set_position((x, ymax)) # Drawing - @allow_rasterization + @martist.allow_rasterization def draw(self, renderer=None, inframe=False): """Draw everything (plot lines, axes, labels)""" if renderer is None: diff --git a/lib/matplotlib/axis.py b/lib/matplotlib/axis.py index f7cea4d1492f..5164567ae1c7 100644 --- a/lib/matplotlib/axis.py +++ b/lib/matplotlib/axis.py @@ -10,7 +10,6 @@ from matplotlib import rcParams import matplotlib.artist as artist -from matplotlib.artist import allow_rasterization import matplotlib.cbook as cbook from matplotlib.cbook import _string_to_bool import matplotlib.font_manager as font_manager @@ -286,7 +285,7 @@ def get_loc(self): 'Return the tick location (data coords) as a scalar' return self._loc - @allow_rasterization + @artist.allow_rasterization def draw(self, renderer): if not self.get_visible(): self.stale = False @@ -1174,7 +1173,7 @@ def get_tick_padding(self): values.append(self.minorTicks[0].get_tick_padding()) return max(values, default=0) - @allow_rasterization + @artist.allow_rasterization def draw(self, renderer, *args, **kwargs): 'Draw the axis lines, grid lines, tick lines and labels' diff --git a/lib/matplotlib/cbook/__init__.py b/lib/matplotlib/cbook/__init__.py index 8f86aecd68fe..41197ecf5da2 100644 --- a/lib/matplotlib/cbook/__init__.py +++ b/lib/matplotlib/cbook/__init__.py @@ -722,45 +722,29 @@ def remove(self, o): def report_memory(i=0): # argument may go away - """return the memory consumed by process""" - from subprocess import Popen, PIPE - pid = os.getpid() - if sys.platform == 'sunos5': + """Return the memory consumed by the process.""" + def call(command, os_name): try: - a2 = Popen(['ps', '-p', '%d' % pid, '-o', 'osz'], - stdout=PIPE).stdout.readlines() - except OSError: + return subprocess.check_output(command) + except subprocess.CalledProcessError: raise NotImplementedError( - "report_memory works on Sun OS only if " - "the 'ps' program is found") - mem = int(a2[-1].strip()) + "report_memory works on %s only if " + "the '%s' program is found" % (os_name, command[0]) + ) + + pid = os.getpid() + if sys.platform == 'sunos5': + lines = call(['ps', '-p', '%d' % pid, '-o', 'osz'], 'Sun OS') + mem = int(lines[-1].strip()) elif sys.platform == 'linux': - try: - a2 = Popen(['ps', '-p', '%d' % pid, '-o', 'rss,sz'], - stdout=PIPE).stdout.readlines() - except OSError: - raise NotImplementedError( - "report_memory works on Linux only if " - "the 'ps' program is found") - mem = int(a2[1].split()[1]) + lines = call(['ps', '-p', '%d' % pid, '-o', 'rss,sz'], 'Linux') + mem = int(lines[1].split()[1]) elif sys.platform == 'darwin': - try: - a2 = Popen(['ps', '-p', '%d' % pid, '-o', 'rss,vsz'], - stdout=PIPE).stdout.readlines() - except OSError: - raise NotImplementedError( - "report_memory works on Mac OS only if " - "the 'ps' program is found") - mem = int(a2[1].split()[0]) + lines = call(['ps', '-p', '%d' % pid, '-o', 'rss,vsz'], 'Mac OS') + mem = int(lines[1].split()[0]) elif sys.platform == 'win32': - try: - a2 = Popen(["tasklist", "/nh", "/fi", "pid eq %d" % pid], - stdout=PIPE).stdout.read() - except OSError: - raise NotImplementedError( - "report_memory works on Windows only if " - "the 'tasklist' program is found") - mem = int(a2.strip().split()[-2].replace(',', '')) + lines = call(["tasklist", "/nh", "/fi", "pid eq %d" % pid], 'Windows') + mem = int(lines.strip().split()[-2].replace(',', '')) else: raise NotImplementedError( "We don't have a memory monitor for %s" % sys.platform) @@ -810,7 +794,6 @@ def print_cycles(objects, outstream=sys.stdout, show_progress=False): If True, print the number of objects reached as they are found. """ import gc - from types import FrameType def print_path(path): for i, step in enumerate(path): @@ -851,7 +834,7 @@ def recurse(obj, start, all, current_path): # Don't go back through the original list of objects, or # through temporary references to the object, since those # are just an artifact of the cycle detector itself. - elif referent is objects or isinstance(referent, FrameType): + elif referent is objects or isinstance(referent, types.FrameType): continue # We haven't seen this object before, so recurse @@ -2006,7 +1989,7 @@ def _warn_external(message, category=None): etc.). """ frame = sys._getframe() - for stacklevel in itertools.count(1): + for stacklevel in itertools.count(1): # lgtm[py/unused-loop-variable] if not re.match(r"\A(matplotlib|mpl_toolkits)(\Z|\.)", frame.f_globals["__name__"]): break diff --git a/lib/matplotlib/colorbar.py b/lib/matplotlib/colorbar.py index 673d1c6b62ec..caf8b99a3d67 100644 --- a/lib/matplotlib/colorbar.py +++ b/lib/matplotlib/colorbar.py @@ -1056,7 +1056,7 @@ def __init__(self, ax, mappable, **kw): self.mappable = mappable kw['cmap'] = cmap = mappable.cmap - kw['norm'] = norm = mappable.norm + kw['norm'] = mappable.norm if isinstance(mappable, contour.ContourSet): CS = mappable diff --git a/lib/matplotlib/dviread.py b/lib/matplotlib/dviread.py index 73925bddeef0..b1bd6392e637 100644 --- a/lib/matplotlib/dviread.py +++ b/lib/matplotlib/dviread.py @@ -964,8 +964,6 @@ def __iter__(self): @staticmethod def _parse(file): - result = [] - lines = (line.split(b'%', 1)[0].strip() for line in file) data = b''.join(lines) beginning = data.find(b'[') diff --git a/lib/matplotlib/figure.py b/lib/matplotlib/figure.py index a174cc7f79d1..7798a3b34d71 100644 --- a/lib/matplotlib/figure.py +++ b/lib/matplotlib/figure.py @@ -24,15 +24,9 @@ import matplotlib.artist as martist from matplotlib.artist import Artist, allow_rasterization - import matplotlib.cbook as cbook - -from matplotlib.cbook import Stack - -from matplotlib import image as mimage -from matplotlib.image import FigureImage - import matplotlib.colorbar as cbar +import matplotlib.image as mimage from matplotlib.axes import Axes, SubplotBase, subplot_class_factory from matplotlib.blocking_input import BlockingMouseInput, BlockingKeyMouseInput @@ -57,7 +51,7 @@ def _stale_figure_callback(self, val): self.figure.stale = val -class AxesStack(Stack): +class AxesStack(cbook.Stack): """ Specialization of the `.Stack` to handle all tracking of `~matplotlib.axes.Axes` in a `.Figure`. @@ -74,7 +68,7 @@ class AxesStack(Stack): """ def __init__(self): - Stack.__init__(self) + super().__init__() self._ind = 0 def as_list(self): @@ -108,14 +102,14 @@ def _entry_from_axes(self, e): def remove(self, a): """Remove the axes from the stack.""" - Stack.remove(self, self._entry_from_axes(a)) + super().remove(self._entry_from_axes(a)) def bubble(self, a): """ Move the given axes, which must already exist in the stack, to the top. """ - return Stack.bubble(self, self._entry_from_axes(a)) + return super().bubble(self._entry_from_axes(a)) def add(self, key, a): """ @@ -137,7 +131,7 @@ def add(self, key, a): a_existing = self.get(key) if a_existing is not None: - Stack.remove(self, (key, a_existing)) + super().remove((key, a_existing)) warnings.warn( "key {!r} already existed; Axes is being replaced".format(key)) # I don't think the above should ever happen. @@ -145,7 +139,7 @@ def add(self, key, a): if a in self: return None self._ind += 1 - return Stack.push(self, (key, (self._ind, a))) + return super().push((key, (self._ind, a))) def current_key_axes(self): """ @@ -331,7 +325,7 @@ def __init__(self, :meth:`.subplot2grid`.) Defaults to :rc:`figure.constrained_layout.use`. """ - Artist.__init__(self) + super().__init__() # remove the non-figure artist _axes property # as it makes no sense for a figure to be _in_ an axes # this is used by the property methods in the artist base class @@ -859,7 +853,7 @@ def figimage(self, X, xo=0, yo=0, alpha=None, norm=None, cmap=None, figsize = [x / dpi for x in (X.shape[1], X.shape[0])] self.set_size_inches(figsize, forward=True) - im = FigureImage(self, cmap, norm, xo, yo, origin, **kwargs) + im = mimage.FigureImage(self, cmap, norm, xo, yo, origin, **kwargs) im.stale_callback = _stale_figure_callback im.set_array(X) diff --git a/lib/matplotlib/fontconfig_pattern.py b/lib/matplotlib/fontconfig_pattern.py index 299f081fe39b..76d1a8936acc 100644 --- a/lib/matplotlib/fontconfig_pattern.py +++ b/lib/matplotlib/fontconfig_pattern.py @@ -175,8 +175,6 @@ def generate_fontconfig_pattern(d): pattern string. """ props = [] - families = '' - size = '' for key in 'family style variant weight stretch file size'.split(): val = getattr(d, 'get_' + key)() if val is not None and val != []: diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index a41428a5f345..1482298b930d 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -15,7 +15,6 @@ from matplotlib import rcParams import matplotlib.artist as martist -from matplotlib.artist import allow_rasterization from matplotlib.backend_bases import FigureCanvasBase import matplotlib.colors as mcolors import matplotlib.cm as cm @@ -557,7 +556,7 @@ def _check_unsampled_image(self, renderer): """ return False - @allow_rasterization + @martist.allow_rasterization def draw(self, renderer, *args, **kwargs): # if not visible, declare victory and return if not self.get_visible(): diff --git a/lib/matplotlib/mathtext.py b/lib/matplotlib/mathtext.py index e7944ffe7d1b..efec64b7b7b8 100644 --- a/lib/matplotlib/mathtext.py +++ b/lib/matplotlib/mathtext.py @@ -854,7 +854,6 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True): new_fontname, sym, uniindex), MathTextWarning) fontname = 'rm' - new_fontname = fontname font = self._get_font(fontname) uniindex = 0xA4 # currency char, for lack of anything better glyphindex = font.get_char_index(uniindex) @@ -1168,7 +1167,7 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True): found_symbol = False if not found_symbol: - glyph = sym = '?' + glyph = '?' num = ord(glyph) symbol_name = font.get_name_char(glyph) diff --git a/lib/matplotlib/mlab.py b/lib/matplotlib/mlab.py index 717112844a61..dd1e91cb0984 100644 --- a/lib/matplotlib/mlab.py +++ b/lib/matplotlib/mlab.py @@ -3447,7 +3447,6 @@ def stineman_interp(xi, x, y, yp=None): yp = np.asarray(yp, float) xi = np.asarray(xi, float) - yi = np.zeros(xi.shape, float) # calculate linear slopes dx = x[1:] - x[:-1] diff --git a/lib/matplotlib/patches.py b/lib/matplotlib/patches.py index ab9938fcc749..5832687476fc 100644 --- a/lib/matplotlib/patches.py +++ b/lib/matplotlib/patches.py @@ -3079,9 +3079,6 @@ def connect(self, posA, posB): dd2 = (dx * dx + dy * dy) ** .5 ddx, ddy = dx / dd2, dy / dd2 - else: - dl = 0. - arm = max(armA, armB) f = self.fraction * dd + arm diff --git a/lib/matplotlib/projections/geo.py b/lib/matplotlib/projections/geo.py index 668a94f0675e..c36c970ef281 100644 --- a/lib/matplotlib/projections/geo.py +++ b/lib/matplotlib/projections/geo.py @@ -256,7 +256,6 @@ def __str__(self): return "{}({})".format(type(self).__name__, self._resolution) def transform_path_non_affine(self, path): - vertices = path.vertices ipath = path.interpolated(self._resolution) return Path(self.transform(ipath.vertices), ipath.codes) transform_path_non_affine.__doc__ = \ diff --git a/lib/matplotlib/quiver.py b/lib/matplotlib/quiver.py index 9b63e7734198..65a8f48411b7 100644 --- a/lib/matplotlib/quiver.py +++ b/lib/matplotlib/quiver.py @@ -24,7 +24,6 @@ import matplotlib.transforms as transforms import matplotlib.text as mtext import matplotlib.artist as martist -from matplotlib.artist import allow_rasterization from matplotlib import docstring import matplotlib.font_manager as font_manager from matplotlib.cbook import delete_masked_points @@ -341,7 +340,7 @@ def _text_y(self, y): else: return y - @allow_rasterization + @martist.allow_rasterization def draw(self, renderer): self._init() self.vector.draw(renderer) @@ -540,7 +539,7 @@ def get_datalim(self, transData): bbox.update_from_data_xy(XY, ignore=True) return bbox - @allow_rasterization + @martist.allow_rasterization def draw(self, renderer): self._init() verts = self._make_verts(self.U, self.V, self.angles) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index d18d3d76531b..9b25420929ef 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -82,7 +82,6 @@ def stackplot(axes, x, *args, stack += first_line elif baseline == 'weighted_wiggle': - m, n = y.shape total = np.sum(y, 0) # multiply by 1/total (or zero) to avoid infinities in the division: inv_total = np.zeros_like(total) diff --git a/lib/matplotlib/textpath.py b/lib/matplotlib/textpath.py index 5c0b668f8120..97302a6ce494 100644 --- a/lib/matplotlib/textpath.py +++ b/lib/matplotlib/textpath.py @@ -233,7 +233,6 @@ def get_glyphs_mathtext(self, prop, s, glyph_map=None, glyph_ids = [] sizes = [] - currx, curry = 0, 0 for font, fontsize, ccode, ox, oy in glyphs: char_id = self._get_char_id(font, ccode) if char_id not in glyph_map: diff --git a/setupext.py b/setupext.py index 0f1128e3c548..a4cb381effde 100644 --- a/setupext.py +++ b/setupext.py @@ -2,7 +2,6 @@ import configparser from distutils import sysconfig, version from distutils.core import Extension -import distutils.command.build_ext import glob import hashlib import importlib @@ -986,8 +985,6 @@ def add_flags(self, ext): ext.define_macros.append(('FREETYPE_BUILD_TYPE', 'system')) def do_custom_build(self): - from pathlib import Path - # We're using a system freetype if not options.get('local_freetype'): return @@ -1081,7 +1078,8 @@ def do_custom_build(self): subprocess.check_call(["make"], env=env, cwd=src_path) else: # compilation on windows - shutil.rmtree(str(Path(src_path, "objs")), ignore_errors=True) + shutil.rmtree(str(pathlib.Path(src_path, "objs")), + ignore_errors=True) FREETYPE_BUILD_CMD = r""" call "%ProgramFiles%\Microsoft SDKs\Windows\v7.0\Bin\SetEnv.Cmd" ^ /Release /{xXX} /xp @@ -1098,18 +1096,19 @@ def do_custom_build(self): vcvarsall = msvc.find_vcvarsall(10.0) if vcvarsall is None: raise RuntimeError('Microsoft VS 2010 required') - cmdfile = Path("build/build_freetype.cmd") + cmdfile = pathlib.Path("build/build_freetype.cmd") cmdfile.write_text(FREETYPE_BUILD_CMD.format( vc20xx=vc, WinXX=WinXX, xXX=xXX, vcvarsall=vcvarsall)) subprocess.check_call([str(cmdfile.resolve())], shell=True, cwd=src_path) # Move to the corresponding Unix build path. - Path(src_path, "objs/.libs").mkdir() + pathlib.Path(src_path, "objs/.libs").mkdir() # Be robust against change of FreeType version. - lib_path, = (Path(src_path, "objs", vc, xXX) + lib_path, = (pathlib.Path(src_path, "objs", vc, xXX) .glob("freetype*.lib")) - shutil.copy2(str(lib_path), - str(Path(src_path, "objs/.libs/libfreetype.lib"))) + shutil.copy2( + str(lib_path), + str(pathlib.Path(src_path, "objs/.libs/libfreetype.lib"))) class FT2Font(SetupPackage): diff --git a/tools/make_icons.py b/tools/make_icons.py index dfdcda8d43d8..f62624ebba10 100755 --- a/tools/make_icons.py +++ b/tools/make_icons.py @@ -19,11 +19,10 @@ import numpy as np -from matplotlib import pyplot as plt +import matplotlib.pyplot as plt from matplotlib.font_manager import FontProperties from matplotlib import cm -import matplotlib -import matplotlib.patheffects as PathEffects +from matploltlib import patheffects matplotlib.rcdefaults() matplotlib.rcParams['svg.fonttype'] = 'path' @@ -55,7 +54,7 @@ def make_icon(fontfile, ccode): fig.patch.set_alpha(0.0) text = fig.text(0.5, 0.48, chr(ccode), ha='center', va='center', fontproperties=prop) - text.set_path_effects([PathEffects.Normal()]) + text.set_path_effects([patheffects.Normal()]) return fig diff --git a/tools/memleak.py b/tools/memleak.py index df86ea4ce08b..e3a89128fa95 100755 --- a/tools/memleak.py +++ b/tools/memleak.py @@ -133,7 +133,7 @@ def __call__(self): matplotlib.use(args.backend[0]) if args.interactive: - from matplotlib import pyplot as plt + import matplotlib.pyplot as plt plt.ion() run_memleak_test(
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: