Skip to content

Commit 6a4e7d9

Browse files
committed
Cleanup unused variables and imports
1 parent b6a3400 commit 6a4e7d9

24 files changed

+49
-105
lines changed

lib/matplotlib/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,6 @@
119119
import contextlib
120120
import distutils.version
121121
import functools
122-
import io
123122
import importlib
124123
import inspect
125124
from inspect import Parameter

lib/matplotlib/_constrained_layout.py

-2
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

-2
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

-1
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

+1-2
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

+2-3
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

+20-40
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
@@ -725,45 +722,29 @@ def remove(self, o):
725722

726723

727724
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':
725+
"""Return the memory consumed by the process."""
726+
def call(command, os_name):
732727
try:
733-
a2 = Popen(['ps', '-p', '%d' % pid, '-o', 'osz'],
734-
stdout=PIPE).stdout.readlines()
735-
except OSError:
728+
return subprocess.check_output(command)
729+
except subprocess.CalledProcessError:
736730
raise NotImplementedError(
737-
"report_memory works on Sun OS only if "
738-
"the 'ps' program is found")
739-
mem = int(a2[-1].strip())
731+
"report_memory works on %s only if "
732+
"the '%s' program is found" % (os_name, command[0])
733+
)
734+
735+
pid = os.getpid()
736+
if sys.platform == 'sunos5':
737+
lines = call(['ps', '-p', '%d' % pid, '-o', 'osz'], 'Sun OS')
738+
mem = int(lines[-1].strip())
740739
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])
740+
lines = call(['ps', '-p', '%d' % pid, '-o', 'rss,sz'], 'Linux')
741+
mem = int(lines[1].split()[1])
749742
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])
743+
lines = call(['ps', '-p', '%d' % pid, '-o', 'rss,vsz'], 'Mac OS')
744+
mem = int(lines[1].split()[0])
758745
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(',', ''))
746+
lines = call(["tasklist", "/nh", "/fi", "pid eq %d" % pid], 'Windows')
747+
mem = int(lines.strip().split()[-2].replace(',', ''))
767748
else:
768749
raise NotImplementedError(
769750
"We don't have a memory monitor for %s" % sys.platform)
@@ -813,7 +794,6 @@ def print_cycles(objects, outstream=sys.stdout, show_progress=False):
813794
If True, print the number of objects reached as they are found.
814795
"""
815796
import gc
816-
from types import FrameType
817797

818798
def print_path(path):
819799
for i, step in enumerate(path):
@@ -854,7 +834,7 @@ def recurse(obj, start, all, current_path):
854834
# Don't go back through the original list of objects, or
855835
# through temporary references to the object, since those
856836
# are just an artifact of the cycle detector itself.
857-
elif referent is objects or isinstance(referent, FrameType):
837+
elif referent is objects or isinstance(referent, types.FrameType):
858838
continue
859839

860840
# We haven't seen this object before, so recurse
@@ -2009,7 +1989,7 @@ def _warn_external(message, category=None):
20091989
etc.).
20101990
"""
20111991
frame = sys._getframe()
2012-
for stacklevel in itertools.count(1):
1992+
for stacklevel in itertools.count(1): # lgtm[py/unused-loop-variable]
20131993
if not re.match(r"\A(matplotlib|mpl_toolkits)(\Z|\.)",
20141994
frame.f_globals["__name__"]):
20151995
break

lib/matplotlib/colorbar.py

+1-2
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

-3
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

-2
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

+9-15
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,9 @@
2424

2525
import matplotlib.artist as martist
2626
from matplotlib.artist import Artist, allow_rasterization
27-
2827
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-
3528
import matplotlib.colorbar as cbar
29+
import matplotlib.image as mimage
3630

3731
from matplotlib.axes import Axes, SubplotBase, subplot_class_factory
3832
from matplotlib.blocking_input import BlockingMouseInput, BlockingKeyMouseInput
@@ -57,7 +51,7 @@ def _stale_figure_callback(self, val):
5751
self.figure.stale = val
5852

5953

60-
class AxesStack(Stack):
54+
class AxesStack(cbook.Stack):
6155
"""
6256
Specialization of the `.Stack` to handle all tracking of
6357
`~matplotlib.axes.Axes` in a `.Figure`.
@@ -74,7 +68,7 @@ class AxesStack(Stack):
7468
7569
"""
7670
def __init__(self):
77-
Stack.__init__(self)
71+
super().__init__()
7872
self._ind = 0
7973

8074
def as_list(self):
@@ -108,14 +102,14 @@ def _entry_from_axes(self, e):
108102

109103
def remove(self, a):
110104
"""Remove the axes from the stack."""
111-
Stack.remove(self, self._entry_from_axes(a))
105+
super().remove(self._entry_from_axes(a))
112106

113107
def bubble(self, a):
114108
"""
115109
Move the given axes, which must already exist in the
116110
stack, to the top.
117111
"""
118-
return Stack.bubble(self, self._entry_from_axes(a))
112+
return super().bubble(self._entry_from_axes(a))
119113

120114
def add(self, key, a):
121115
"""
@@ -137,15 +131,15 @@ def add(self, key, a):
137131

138132
a_existing = self.get(key)
139133
if a_existing is not None:
140-
Stack.remove(self, (key, a_existing))
134+
super().remove((key, a_existing))
141135
warnings.warn(
142136
"key {!r} already existed; Axes is being replaced".format(key))
143137
# I don't think the above should ever happen.
144138

145139
if a in self:
146140
return None
147141
self._ind += 1
148-
return Stack.push(self, (key, (self._ind, a)))
142+
return super().push((key, (self._ind, a)))
149143

150144
def current_key_axes(self):
151145
"""
@@ -331,7 +325,7 @@ def __init__(self,
331325
:meth:`.subplot2grid`.)
332326
Defaults to :rc:`figure.constrained_layout.use`.
333327
"""
334-
Artist.__init__(self)
328+
super().__init__()
335329
# remove the non-figure artist _axes property
336330
# as it makes no sense for a figure to be _in_ an axes
337331
# 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,
859853
figsize = [x / dpi for x in (X.shape[1], X.shape[0])]
860854
self.set_size_inches(figsize, forward=True)
861855

862-
im = FigureImage(self, cmap, norm, xo, yo, origin, **kwargs)
856+
im = mimage.FigureImage(self, cmap, norm, xo, yo, origin, **kwargs)
863857
im.stale_callback = _stale_figure_callback
864858

865859
im.set_array(X)

lib/matplotlib/fontconfig_pattern.py

-2
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

+1-2
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():

lib/matplotlib/mathtext.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,6 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
850850
new_fontname, sym, uniindex),
851851
MathTextWarning)
852852
fontname = 'rm'
853-
new_fontname = fontname
854853
font = self._get_font(fontname)
855854
uniindex = 0xA4 # currency char, for lack of anything better
856855
glyphindex = font.get_char_index(uniindex)
@@ -1164,7 +1163,7 @@ def _get_info(self, fontname, font_class, sym, fontsize, dpi, math=True):
11641163
found_symbol = False
11651164

11661165
if not found_symbol:
1167-
glyph = sym = '?'
1166+
glyph = '?'
11681167
num = ord(glyph)
11691168
symbol_name = font.get_name_char(glyph)
11701169

lib/matplotlib/mlab.py

-1
Original file line numberDiff line numberDiff line change
@@ -3447,7 +3447,6 @@ def stineman_interp(xi, x, y, yp=None):
34473447
yp = np.asarray(yp, float)
34483448

34493449
xi = np.asarray(xi, float)
3450-
yi = np.zeros(xi.shape, float)
34513450

34523451
# calculate linear slopes
34533452
dx = x[1:] - x[:-1]

lib/matplotlib/offsetbox.py

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
from matplotlib.patches import bbox_artist as mbbox_artist
3636
from matplotlib.text import _AnnotationBase
3737

38-
3938
DEBUG = False
4039

4140

lib/matplotlib/patches.py

-3
Original file line numberDiff line numberDiff line change
@@ -3079,9 +3079,6 @@ def connect(self, posA, posB):
30793079
dd2 = (dx * dx + dy * dy) ** .5
30803080
ddx, ddy = dx / dd2, dy / dd2
30813081

3082-
else:
3083-
dl = 0.
3084-
30853082
arm = max(armA, armB)
30863083
f = self.fraction * dd + arm
30873084

lib/matplotlib/projections/geo.py

-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import numpy as np
22

3-
import matplotlib
43
from matplotlib import rcParams
54
from matplotlib.axes import Axes
65
import matplotlib.axis as maxis
@@ -258,7 +257,6 @@ def __str__(self):
258257
return "{}({})".format(type(self).__name__, self._resolution)
259258

260259
def transform_path_non_affine(self, path):
261-
vertices = path.vertices
262260
ipath = path.interpolated(self._resolution)
263261
return Path(self.transform(ipath.vertices), ipath.codes)
264262
transform_path_non_affine.__doc__ = \

0 commit comments

Comments
 (0)