8000 Merge pull request #4081 from tacaswell/pep8_version_fix · matplotlib/matplotlib@a05a02a · GitHub
[go: up one dir, main page]

Skip to content

Commit a05a02a

Browse files
committed
Merge pull request #4081 from tacaswell/pep8_version_fix
Pep8 version fixes
2 parents e2a8342 + 99e60f3 commit a05a02a

File tree

25 files changed

+125
-160
lines changed

25 files changed

+125
-160
lines changed

doc/api/api_changes/code_removal.rst

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Code Removal
33

44
Legend
55
------
6-
- Removed handling of `loc` as a positional argument to `Legend`
6+
Removed handling of `loc` as a positional argument to `Legend`
77

88

99
Legend handlers
@@ -78,3 +78,10 @@ Deprecated in 2009.
7878
Remove ``NavigationToolbar2QTAgg``
7979
----------------------------------
8080
Added no functionality over the base ``NavigationToolbar2Qt``
81< 10000 /code>+
82+
83+
mpl.py
84+
------
85+
86+
Remove the module `matplotlib.mpl`. Deprecated in 1.3 by
87+
PR #1670 and commit 78ce67d161625833cacff23cfe5d74920248c5b2

examples/animation/strip_chart_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import matplotlib.animation as animation
99

1010

11-
class Scope(object)
11+
class Scope(object):
1212
def __init__(self, ax, maxt=2, dt=0.02):
1313
self.ax = ax
1414
self.dt = dt

examples/axes_grid/demo_axes_grid2.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ def add_inner_title(ax, title, loc, size=None, **kwargs):
3737
grid = ImageGrid(F, 211, # similar to subplot(111)
3838
nrows_ncols=(1, 3),
3939
direction="row",
40-
axes_pad = 0.05,
40+
axes_pad=0.05,
4141
add_all=True,
42-
label_mode = "1",
43-
share_all = True,
42+
label_mode="1",
43+
share_all=True,
4444
cbar_location="top",
4545
cbar_mode="each",
4646
cbar_size="7%",
@@ -75,10 +75,10 @@ def add_inner_title(ax, title, loc, size=None, **kwargs):
7575
grid2 = ImageGrid(F, 212,
7676
nrows_ncols=(1, 3),
7777
direction="row",
78-
axes_pad = 0.05,
78+
axes_pad=0.05,
7979
add_all=True,
80-
label_mode = "1",
81-
share_all = True,
80+
label_mode="1",
81+
share_all=True,
8282
cbar_location="right",
8383
cbar_mode="single",
8484
cbar_size="10%",

examples/axes_grid/demo_edge_colorbar.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@ def demo_bottom_cbar(fig):
1717
"""
1818
grid = AxesGrid(fig, 121, # similar to subplot(132)
1919
nrows_ncols=(2, 2),
20-
axes_pad = 0.10,
20+
axes_pad=0.10,
2121
share_all=True,
22-
label_mode = "1",
23-
cbar_location = "bottom",
22+
label_mode="1",
23+
cbar_location="bottom",
2424
cbar_mode="edge",
25-
cbar_pad = 0.25,
26-
cbar_size = "15%",
25+
cbar_pad=0.25,
26+
cbar_size="15%",
2727
direction="column"
2828
)
2929

@@ -51,9 +51,9 @@ def demo_right_cbar(fig):
5151

5252
grid = AxesGrid(F, 122, # similar to subplot(122)
5353
nrows_ncols=(2, 2),
54-
axes_pad = 0.10,
55-
label_mode = "1",
56-
share_all = True,
54+
axes_pad=0.10,
55+
label_mode="1",
56+
share_all=True,
5757
cbar_location="right",
5858
cbar_mode="edge",
5959
cbar_size="7%",

examples/event_handling/lasso_demo.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ def __init__(self, ax, data):
4343
self.collection = RegularPolyCollection(
4444
fig.dpi, 6, sizes=(100,),
4545
facecolors=facecolors,
46-
offsets = self.xys,
47-
transOffset = ax.transData)
46+
offsets=self.xys,
47+
transOffset=ax.transData)
4848

4949
ax.add_collection(self.collection)
5050

@@ -69,7 +69,9 @@ def onpress(self, event):
6969
return
7070
if event.inaxes is None:
7171
return
72-
self.lasso = Lasso(event.inaxes, (event.xdata, event.ydata), self.callback)
72+
self.lasso = Lasso(event.inaxes,
73+
(event.xdata, event.ydata),
74+
self.callback)
7375
# acquire a lock on the widget drawing
7476
self.canvas.widgetlock(self.lasso)
7577

examples/pylab_examples/contourf_demo.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@
7777

7878
CS4 = plt.contour(X, Y, Z, levels,
7979
colors=('k',),
80-
linewidths = (3,),
81-
origin = origin)
80+
linewidths=(3,),
81+
origin=origin)
8282
plt.title('Listed colors (3 masked regions)')
8383
plt.clabel(CS4, fmt='%2.1f', colors='w', fontsize=14)
8484

@@ -95,7 +95,7 @@
9595
# instead of using the "bad" colormap value for them, it draws
9696
# nothing at all in them. Therefore the following would have
9797
# no effect:
98-
#cmap.set_bad("red")
98+
# cmap.set_bad("red")
9999

100100
fig, axs = plt.subplots(2, 2)
101101
for ax, extend in zip(axs.ravel(), extends):

examples/tests/backend_driver.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,9 @@ def report_all_missing(directories):
342342

343343
failbackend = dict(
344344
svg=('tex_demo.py', ),
345-
agg = ('hyperlinks.py', ),
346-
pdf = ('hyperlinks.py', ),
347-
ps = ('hyperlinks.py', ),
345+
agg=('hyperlinks.py', ),
346+
pdf=('hyperlinks.py', ),
347+
ps=('hyperlinks.py', ),
348348
)
349349

350350

lib/matplotlib/__init__.py

Lines changed: 23 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,26 @@
107107
import distutils.version
108108
from itertools import chain
109109

110+
import io
111+
import locale
112+
import os
113+
import re
114+
import tempfile
115+
import warnings
116+
import contextlib
117+
import distutils.sysconfig
118+
119+
# cbook must import matplotlib only within function
120+
# definitions, so it is safe to import from it here.
121+
from matplotlib.cbook import is_string_like, mplDeprecation
122+
from matplotlib.compat import subprocess
123+
from matplotlib.rcsetup import (defaultParams,
124+
validate_backend)
125+
126+
import numpy
127+
from six.moves.urllib.request import urlopen
128+
from six.moves import reload_module as reload
129+
110130
__version__ = str('1.5.dev1')
111131
__version__numpy__ = str('1.6') # minimum required numpy version
112132

@@ -164,51 +184,18 @@ def _forward_ilshift(self, other):
164184
return self
165185
pyparsing.Forward.__ilshift__ = _forward_ilshift
166186

167-
try:
168-
from urllib.request import urlopen
169-
except ImportError:
170-
from urllib2 import urlopen
171-
172-
import io
173-
import locale
174-
import os
175-
import re
176-
import tempfile
177-
import warnings
178-
import contextlib
179-
import distutils.sysconfig
180-
181-
# cbook must import matplotlib only within function
182-
# definitions, so it is safe to import from it here.
183-
from matplotlib.cbook import is_string_like, mplDeprecation
184-
from matplotlib.compat import subprocess
185-
186-
try:
187-
reload
188-
except NameError:
189-
# Python 3
190-
from imp import reload
191-
192187

193188
if not hasattr(sys, 'argv'): # for modpython
194189
sys.argv = [str('modpython')]
195190

196191

197-
from matplotlib.rcsetup import (defaultParams,
198-
validate_backend)
199-
200192
major, minor1, minor2, s, tmp = sys.version_info
201-
_python24 = (major == 2 and minor1 >= 4) or major >= 3
193+
_python26 = (major == 2 and minor1 >= 6) or major >= 3
202194

203-
# the havedate check was a legacy from old matplotlib which preceeded
204-
# datetime support
205-
_havedate = True
195+
if not _python26:
196+
raise ImportError('matplotlib requires Python 2.6 or later')
206197

207-
if not _python24:
208-
raise ImportError('matplotlib requires Python 2.4 or later')
209198

210-
211-
import numpy
212199
if not compare_versions(numpy.__version__, __version__numpy__):
213200
raise ImportError(
214201
'numpy %s or later is required; you have %s' % (
@@ -1125,7 +1112,6 @@ def rc_params_from_file(fname, fail_on_error=False, use_default_template=True):
11251112
rcParams['text.usetex'] = checkdep_usetex(rcParams['text.usetex'])
11261113

11271114
if rcParams['axes.formatter.use_locale']:
1128-
import locale
11291115
locale.setlocale(locale.LC_ALL, '')
11301116

11311117

lib/matplotlib/axes/_axes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from numpy import ma
1212

1313
import matplotlib
14-
rcParams = matplotlib.rcParams
1514

1615
import matplotlib.cbook as cbook
1716
from matplotlib.cbook import _string_to_bool, mplDeprecation
@@ -40,6 +39,8 @@
4039
from matplotlib.axes._base import _AxesBase
4140
from matplotlib.axes._base import _process_plot_format
4241

42+
rcParams = matplotlib.rcParams
43+
4344
iterable = cbook.iterable
4445
is_string_like = cbook.is_string_like
4546
is_sequence_of_strings = cbook.is_sequence_of_strings

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
from numpy import ma
1414

1515
import matplotlib
16-
rcParams = matplotlib.rcParams
1716

1817
from matplotlib import cbook
1918
from matplotlib.cbook import _string_to_bool
@@ -35,6 +34,7 @@
3534

3635
from matplotlib.cbook import iterable
3736

37+
rcParams = matplotlib.rcParams
3838

3939
is_string_like = cbook.is_string_like
4040
is_sequence_of_strings = cbook.is_sequence_of_strings

lib/matplotlib/axes/_subplots.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,14 @@ def __init__(self, fig, *args, **kwargs):
7373
self._axes_class.__init__(self, fig, self.figbox, **kwargs)
7474

7575
def __reduce__(self):
76-
# get the first axes class which does not inherit from a subplotbase
77-
not_subplotbase = lambda c: issubclass(c, Axes) and \
78-
not issubclass(c, SubplotBase)
79-
axes_class = [c for c in self.__class__.mro() if not_subplotbase(c)][0]
76+
# get the first axes class which does not
77+
# inherit from a subplotbase
78+
79+
def not_subplotbase(c):
80+
return issubclass(c, Axes) and not issubclass(c, SubplotBase)
81+
82+
axes_class = [c for c in self.__class__.mro()
83+
if not_subplotbase(c)][0]
8084
r = [_PicklableSubplotClassConstructor(),
8185
(axes_class,),
8286
self.__getstate__()]

lib/matplotlib/backends/backend_pdf.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1452,7 +1452,9 @@ def writeXref(self):
14521452
def writeInfoDict(self):
14531453
"""Write out the info dictionary, checking it for good form"""
14541454

1455-
is_date = lambda x: isinstance(x, datetime)
1455+
def is_date(x):
1456+
return isinstance(x, datetime)
1457+
14561458
check_trapped = (lambda x: isinstance(x, Name) and
14571459
x.name in ('True', 'False', 'Unknown'))
14581460
keywords = {'Title': is_string_like,

lib/matplotlib/backends/qt4_compat.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import warnings
22
from matplotlib.cbook import mplDeprecation
3+
# bulk-imports because we are pretending that file is this file
4+
from .qt_compat import *
35
_warn_str = ("This module has been deprecated in 1.4 in favor "
46
"of matplotlib.backends.qt_compat\n"
57
"This module will be removed in 1.5, please update "
68
"your imports.")
7-
# bulk-imports because we are pretending that file is this file
8-
from .qt_compat import *
9-
109

1110
warnings.warn(_warn_str, mplDeprecation)

lib/matplotlib/backends/qt_editor/formsubplottool.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@
55
backend.qt4 (PyQt4|PySide) independent form of the subplot tool.
66
77
"""
8+
from matplotlib.backends.qt_compat import QtCore, QtGui, QtWidgets
89

910
__author__ = 'rudolf.hoefler@gmail.com'
1011

11-
from matplotlib.backends.qt_compat import QtCore, QtGui, QtWidgets
12-
1312

1413
class UiSubplotTool(QtWidgets.QDialog):
1514

lib/matplotlib/finance.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,7 @@
1515
import contextlib
1616
import os
1717
import warnings
18-
19-
< 10000 span class=pl-k>if six.PY3:
20-
from urllib.request import urlopen
21-
else:
22-
from urllib2 import urlopen
23-
24-
if six.PY3:
25-
import hashlib
26-
md5 = lambda x: hashlib.md5(x.encode())
27-
else:
28-
from hashlib import md5
18+
from six.moves.urllib.request import urlopen
2919

3020
import datetime
3121

@@ -41,6 +31,14 @@
4131
from matplotlib.transforms import Affine2D
4232

4333

34+
if six.PY3:
35+
import hashlib
36+
37+
def md5(x):
38+
return hashlib.md5(x.encode())
39+
else:
40+
from hashlib import md5
41+
4442
cachedir = get_cachedir()
4543
# cachedir will be None if there is no writable directory.
4644
if cachedir is not None:
@@ -802,10 +800,10 @@ def _candlestick(ax, quotes, width=0.2, colorup='k', colordown='r',
802800

803801
rect = Rectangle(
804802
xy=(t - OFFSET, lower),
805-
width = width,
806-
height = height,
807-
facecolor = color,
808-
edgecolor = color,
803+
width=width,
804+
height=height,
805+
facecolor=color,
806+
edgecolor=color,
809807
)
810808
rect.set_alpha(alpha)
811809

@@ -1075,7 +1073,7 @@ def candlestick2_ohlc(ax, open 63C2 s, highs, lows, closes, width=4,
10751073
rangeCollection = LineCollection(rangeSegments,
10761074
colors=((0, 0, 0, 1), ),
10771075
linewidths=lw,
1078-
antialiaseds = useAA,
1076+
antialiaseds=useAA,
10791077
)
10801078

10811079
barCollection = PolyCollection(barVerts,

0 commit comments

Comments
 (0)
0