Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 814768f

Browse filesBrowse files
committed
Cleanup unused variables and imports
1 parent b6a3400 commit 814768f
Copy full SHA for 814768f
Expand file treeCollapse file tree

25 files changed

+64
-123
lines changed

‎lib/matplotlib/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/__init__.py
+5-6Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,8 @@
119119
import contextlib
120120
import distutils.version
121121
import functools
122-
import io
123-
import importlib
124122
import inspect
125-
from inspect import Parameter
123+
import importlib
126124
import locale
127125
import logging
128126
import os
@@ -1606,13 +1604,14 @@ def param(func):
16061604
_arg_names = []
16071605
params = list(sig.parameters.values())
16081606
for p in params:
1609-
if p.kind is Parameter.VAR_POSITIONAL:
1607+
if p.kind is inspect.Parameter.VAR_POSITIONAL:
16101608
_has_varargs = True
1611-
elif p.kind is Parameter.VAR_KEYWORD:
1609+
elif p.kind is inspect.Parameter.VAR_KEYWORD:
16121610
_has_varkwargs = True
16131611
else:
16141612
_arg_names.append(p.name)
1615-
data_param = Parameter('data', Parameter.KEYWORD_ONLY, default=None)
1613+
data_param = inspect.Parameter(
1614+
'data', inspect.Parameter.KEYWORD_ONLY, default=None)
16161615
if _has_varkwargs:
16171616
params.insert(-1, data_param)
16181617
else:

‎lib/matplotlib/_constrained_layout.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_constrained_layout.py
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,8 +344,6 @@ def _align_spines(fig, gs):
344344
height_ratios[rownummin[n]:(rownummax[n] + 1)])
345345

346346
for nn, ax in enumerate(axs[:-1]):
347-
ss0 = ax.get_subplotspec()
348-
349347
# now compare ax to all the axs:
350348
#
351349
# If the subplotspecs have the same colnumXmax, then line

‎lib/matplotlib/_layoutbox.py

Copy file name to clipboardExpand all lines: lib/matplotlib/_layoutbox.py
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
import logging
2121
import numpy as np
2222

23-
import matplotlib
24-
2523
_log = logging.getLogger(__name__)
2624

2725

‎lib/matplotlib/axes/_axes.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_axes.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7770,7 +7770,6 @@ def matshow(self, Z, **kwargs):
77707770
77717771
"""
77727772
Z = np.asanyarray(Z)
7773-
nr, nc = Z.shape
77747773
kw = {'origin': 'upper',
77757774
'interpolation': 'nearest',
77767775
'aspect': 'equal', # (already the imshow default)

‎lib/matplotlib/axes/_base.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axes/_base.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import matplotlib.font_manager as font_manager
2828
import matplotlib.text as mtext
2929
import matplotlib.image as mimage
30-
from matplotlib.artist import allow_rasterization
3130

3231
from matplotlib.rcsetup import cycler, validate_axisbelow
3332

@@ -2542,7 +2541,7 @@ def _update_title_position(self, renderer):
25422541
title.set_position((x, ymax))
25432542

25442543
# Drawing
2545-
@allow_rasterization
2544+
@martist.allow_rasterization
25462545
def draw(self, renderer=None, inframe=False):
25472546
"""Draw everything (plot lines, axes, labels)"""
25482547
if renderer is None:

‎lib/matplotlib/axis.py

Copy file name to clipboardExpand all lines: lib/matplotlib/axis.py
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
from matplotlib import rcParams
1212
import matplotlib.artist as artist
13-
from matplotlib.artist import allow_rasterization
1413
import matplotlib.cbook as cbook
1514
from matplotlib.cbook import _string_to_bool
1615
import matplotlib.font_manager as font_manager
@@ -286,7 +285,7 @@ def get_loc(self):
286285
'Return the tick location (data coords) as a scalar'
287286
return self._loc
288287

289-
@allow_rasterization
288+
@artist.allow_rasterization
290289
def draw(self, renderer):
291290
if not self.get_visible():
292291
self.stale = False
@@ -1174,7 +1173,7 @@ def get_tick_padding(self):
11741173
values.append(self.minorTicks[0].get_tick_padding())
11751174
return max(values, default=0)
11761175

1177-
@allow_rasterization
1176+
@artist.allow_rasterization
11781177
def draw(self, renderer, *args, **kwargs):
11791178
'Draw the axis lines, grid lines, tick lines and labels'
11801179

‎lib/matplotlib/cbook/__init__.py

Copy file name to clipboardExpand all lines: lib/matplotlib/cbook/__init__.py
+21-42Lines changed: 21 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,9 @@
99
import collections
1010
import collections.abc
1111
import contextlib
12-
import datetime
13-
import errno
1412
import functools
1513
import glob
1614
import gzip
17-
import io
1815
import itertools
1916
import locale
2017
import numbers
@@ -29,7 +26,6 @@
2926
import types
3027
import warnings
3128
import weakref
32-
from weakref import WeakMethod
3329

3430
import numpy as np
3531

@@ -165,7 +161,7 @@ def connect(self, s, func):
165161
"""
166162
self._func_cid_map.setdefault(s, {})
167163
try:
168-
proxy = WeakMethod(func, self._remove_proxy)
164+
proxy = weakref.WeakMethod(func, self._remove_proxy)
169165
except TypeError:
170166
proxy = _StrongRef(func)
171167
if proxy in self._func_cid_map[s]:
@@ -725,45 +721,29 @@ def remove(self, o):
725721

726722

727723
def report_memory(i=0): # argument may go away
728-
"""return the memory consumed by process"""
729-
from subprocess import Popen, PIPE
730-
pid = os.getpid()
731-
if sys.platform == 'sunos5':
724+
"""Return the memory consumed by the process."""
725+
def call(command, os_name):
732726
try:
733-
a2 = Popen(['ps', '-p', '%d' % pid, '-o', 'osz'],
734-
stdout=PIPE).stdout.readlines()
735-
except OSError:
727+
return subprocess.check_output(command)
728+
except subprocess.CalledProcessError:
736729
raise NotImplementedError(
737-
"report_memory works on Sun OS only if "
738-
"the 'ps' program is found")
739-
mem = int(a2[-1].strip())
730+
"report_memory works on %s only if "
731+
"the '%s' program is found" % (os_name, command[0])
732+
)
733+
734+
pid = os.getpid()
735+
if sys.platform == 'sunos5':
736+
lines = call(['ps', '-p', '%d' % pid, '-o', 'osz'], 'Sun OS')
737+
mem = int(lines[-1].strip())
740738
elif sys.platform == 'linux':
741-
try:
742-
a2 = Popen(['ps', '-p', '%d' % pid, '-o', 'rss,sz'],
743-
stdout=PIPE).stdout.readlines()
744-
except OSError:
745-
raise NotImplementedError(
746-
"report_memory works on Linux only if "
747-
"the 'ps' program is found")
748-
mem = int(a2[1].split()[1])
739+
lines = call(['ps', '-p', '%d' % pid, '-o', 'rss,sz'], 'Linux')
740+
mem = int(lines[1].split()[1])
749741
elif sys.platform == 'darwin':
750-
try:
751-
a2 = Popen(['ps', '-p', '%d' % pid, '-o', 'rss,vsz'],
752-
stdout=PIPE).stdout.readlines()
753-
except OSError:
754-
raise NotImplementedError(
755-
"report_memory works on Mac OS only if "
756-
"the 'ps' program is found")
757-
mem = int(a2[1].split()[0])
742+
lines = call(['ps', '-p', '%d' % pid, '-o', 'rss,vsz'], 'Mac OS')
743+
mem = int(lines[1].split()[0])
758744
elif sys.platform == 'win32':
759-
try:
760-
a2 = Popen(["tasklist", "/nh", "/fi", "pid eq %d" % pid],
761-
stdout=PIPE).stdout.read()
762-
except OSError:
763-
raise NotImplementedError(
764-
"report_memory works on Windows only if "
765-
"the 'tasklist' program is found")
766-
mem = int(a2.strip().split()[-2].replace(',', ''))
745+
lines = call(["tasklist", "/nh", "/fi", "pid eq %d" % pid], 'Windows')
746+
mem = int(lines.strip().split()[-2].replace(',', ''))
767747
else:
768748
raise NotImplementedError(
769749
"We don't have a memory monitor for %s" % sys.platform)
@@ -813,7 +793,6 @@ def print_cycles(objects, outstream=sys.stdout, show_progress=False):
813793
If True, print the number of objects reached as they are found.
814794
"""
815795
import gc
816-
from types import FrameType
817796

818797
def print_path(path):
819798
for i, step in enumerate(path):
@@ -854,7 +833,7 @@ def recurse(obj, start, all, current_path):
854833
# Don't go back through the original list of objects, or
855834
# through temporary references to the object, since those
856835
# are just an artifact of the cycle detector itself.
857-
elif referent is objects or isinstance(referent, FrameType):
836+
elif referent is objects or isinstance(referent, types.FrameType):
858837
continue
859838

860839
# We haven't seen this object before, so recurse
@@ -2009,7 +1988,7 @@ def _warn_external(message, category=None):
20091988
etc.).
20101989
"""
20111990
frame = sys._getframe()
2012-
for stacklevel in itertools.count(1):
1991+
for stacklevel in itertools.count(1): # lgtm[py/unused-loop-variable]
20131992
if not re.match(r"\A(matplotlib|mpl_toolkits)(\Z|\.)",
20141993
frame.f_globals["__name__"]):
20151994
break

‎lib/matplotlib/colorbar.py

Copy file name to clipboardExpand all lines: lib/matplotlib/colorbar.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import matplotlib as mpl
2828
import matplotlib.artist as martist
29-
import matplotlib.cbook as cbook
3029
import matplotlib.collections as collections
3130
import matplotlib.colors as colors
3231
import matplotlib.contour as contour
@@ -1057,7 +1056,7 @@ def __init__(self, ax, mappable, **kw):
10571056

10581057
self.mappable = mappable
10591058
kw['cmap'] = cmap = mappable.cmap
1060-
kw['norm'] = norm = mappable.norm
1059+
kw['norm'] = mappable.norm
10611060

10621061
if isinstance(mappable, contour.ContourSet):
10631062
CS = mappable

‎lib/matplotlib/docstring.py

Copy file name to clipboardExpand all lines: lib/matplotlib/docstring.py
-3Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import sys
2-
import types
3-
41
from matplotlib import cbook
52

63

‎lib/matplotlib/dviread.py

Copy file name to clipboardExpand all lines: lib/matplotlib/dviread.py
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,6 @@ def __iter__(self):
964964

965965
@staticmethod
966966
def _parse(file):
967-
result = []
968-
969967
lines = (line.split(b'%', 1)[0].strip() for line in file)
970968
data = b''.join(lines)
971969
beginning = data.find(b'[')

‎lib/matplotlib/figure.py

Copy file name to clipboardExpand all lines: lib/matplotlib/figure.py
+11-18Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,9 @@
2323
from matplotlib import get_backend
2424

2525
import matplotlib.artist as martist
26-
from matplotlib.artist import Artist, allow_rasterization
27-
2826
import matplotlib.cbook as cbook
29-
30-
from matplotlib.cbook import Stack
31-
32-
from matplotlib import image as mimage
33-
from matplotlib.image import FigureImage
34-
3527
import matplotlib.colorbar as cbar
28+
import matplotlib.image as mimage
3629

3730
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
3831
from matplotlib.blocking_input import BlockingMouseInput, BlockingKeyMouseInput
@@ -57,7 +50,7 @@ def _stale_figure_callback(self, val):
5750
self.figure.stale = val
5851

5952

60-
class AxesStack(Stack):
53+
class AxesStack(cbook.Stack):
6154
"""
6255
Specialization of the `.Stack` to handle all tracking of
6356
`~matplotlib.axes.Axes` in a `.Figure`.
@@ -74,7 +67,7 @@ class AxesStack(Stack):
7467
7568
"""
7669
def __init__(self):
77-
Stack.__init__(self)
70+
super().__init__()
7871
self._ind = 0
7972

8073
def as_list(self):
@@ -108,14 +101,14 @@ def _entry_from_axes(self, e):
108101

109102
def remove(self, a):
110103
"""Remove the axes from the stack."""
111-
Stack.remove(self, self._entry_from_axes(a))
104+
super().remove(self._entry_from_axes(a))
112105

113106
def bubble(self, a):
114107
"""
115108
Move the given axes, which must already exist in the
116109
stack, to the top.
117110
"""
118-
return Stack.bubble(self, self._entry_from_axes(a))
111+
return super().bubble(self._entry_from_axes(a))
119112

120113
def add(self, key, a):
121114
"""
@@ -137,15 +130,15 @@ def add(self, key, a):
137130

138131
a_existing = self.get(key)
139132
if a_existing is not None:
140-
Stack.remove(self, (key, a_existing))
133+
super().remove((key, a_existing))
141134
warnings.warn(
142135
"key {!r} already existed; Axes is being replaced".format(key))
143136
# I don't think the above should ever happen.
144137

145138
if a in self:
146139
return None
147140
self._ind += 1
148-
return Stack.push(self, (key, (self._ind, a)))
141+
return super().push((key, (self._ind, a)))
149142

150143
def current_key_axes(self):
151144
"""
@@ -247,7 +240,7 @@ def _update_this(self, s, val):
247240
setattr(self, s, val)
248241

249242

250-
class Figure(Artist):
243+
class Figure(martist.Artist):
251244
"""
252245
The top level container for all the plot elements.
253246
@@ -331,7 +324,7 @@ def __init__(self,
331324
:meth:`.subplot2grid`.)
332325
Defaults to :rc:`figure.constrained_layout.use`.
333326
"""
334-
Artist.__init__(self)
327+
super().__init__()
335328
# remove the non-figure artist _axes property
336329
# as it makes no sense for a figure to be _in_ an axes
337330
# this is used by the property methods in the artist base class
@@ -859,7 +852,7 @@ def figimage(self, X, xo=0, yo=0, alpha=None, norm=None, cmap=None,
859852
figsize = [x / dpi for x in (X.shape[1], X.shape[0])]
860853
self.set_size_inches(figsize, forward=True)
861854

862-
im = FigureImage(self, cmap, norm, xo, yo, origin, **kwargs)
855+
im = mimage.FigureImage(self, cmap, norm, xo, yo, origin, **kwargs)
863856
im.stale_callback = _stale_figure_callback
864857

865858
im.set_array(X)
@@ -1615,7 +1608,7 @@ def clear(self, keep_observers=False):
16151608
"""
16161609
self.clf(keep_observers=keep_observers)
16171610

1618-
@allow_rasterization
1611+
@martist.allow_rasterization
16191612
def draw(self, renderer):
16201613
"""
16211614
Render the figure using :class:`matplotlib.backend_bases.RendererBase`

‎lib/matplotlib/font_manager.py

Copy file name to clipboardExpand all lines: lib/matplotlib/font_manager.py
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1293,7 +1293,6 @@ def get_font(filename, hinting_factor=None):
12931293

12941294
def fc_match(pattern, fontext):
12951295
fontexts = get_fontext_synonyms(fontext)
1296-
ext = "." + fontext
12971296
try:
12981297
pipe = subprocess.Popen(
12991298
['fc-match', '-s', '--format=%{file}\\n', pattern],

‎lib/matplotlib/fontconfig_pattern.py

Copy file name to clipboardExpand all lines: lib/matplotlib/fontconfig_pattern.py
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,6 @@ def generate_fontconfig_pattern(d):
174174
pattern string.
175175
"""
176176
props = []
177-
families = ''
178-
size = ''
179177
for key in 'family style variant weight stretch file size'.split():
180178
val = getattr(d, 'get_' + key)()
181179
if val is not None and val != []:

‎lib/matplotlib/image.py

Copy file name to clipboardExpand all lines: lib/matplotlib/image.py
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
from matplotlib import rcParams
1717
import matplotlib.artist as martist
18-
from matplotlib.artist import allow_rasterization
1918
from matplotlib.backend_bases import FigureCanvasBase
2019
import matplotlib.colors as mcolors
2120
import matplotlib.cm as cm
@@ -557,7 +556,7 @@ def _check_unsampled_image(self, renderer):
557556
"""
558557
return False
559558

560-
@allow_rasterization
559+
@martist.allow_rasterization
561560
def draw(self, renderer, *args, **kwargs):
562561
# if not visible, declare victory and return
563562
if not self.get_visible():

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.