8000 Merge pull request #6573 from anntzer/cleanups · matplotlib/matplotlib@7ae1b06 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7ae1b06

Browse files
authored
Merge pull request #6573 from anntzer/cleanups
Some general cleanups
2 parents 21e16c3 + 850ef93 commit 7ae1b06

29 files changed

+197
-258
lines changed

examples/misc/rec_join_demo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
r1 = r[-10:]
1212

1313
# Create a new array
14-
r2 = np.empty(12, dtype=[('date', '|O4'), ('high', np.float),
15-
('marker', np.float)])
14+
r2 = np.empty(12, dtype=[('date', '|O4'), ('high', float), ('marker', float)])
1615
r2 = r2.view(np.recarray)
1716
r2.date = r.date[-17:-5]
1817
r2.high = r.high[-17:-5]

examples/pylab_examples/demo_ribbon_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def draw(self, renderer, *args, **kwargs):
121121
interpolation="bicubic",
122122
zorder=0.1,
123123
)
124-
gradient = np.zeros((2, 2, 4), dtype=np.float)
124+
gradient = np.zeros((2, 2, 4), dtype=float)
125125
gradient[:, :, :3] = [1, 1, 0.]
126126
gradient[:, :, 3] = [[0.1, 0.3], [0.3, 0.5]] # alpha channel
127127
patch_gradient.set_array(gradient)

examples/pylab_examples/dolphin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
vertices.extend([[float(x) for x in y.split(',')] for y in
7575
parts[i + 1:i + npoints + 1]])
7676
i += npoints + 1
77-
vertices = np.array(vertices, np.float)
77+
vertices = np.array(vertices, float)
7878
vertices[:, 1] -= 160
7979

8080
dolphin_path = Path(vertices, codes)

examples/units/units_scatter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# create masked array
1616

1717

18-
xsecs = secs*np.ma.MaskedArray((1, 2, 3, 4, 5, 6, 7, 8), (1, 0, 1, 0, 0, 0, 1, 0), np.float)
18+
xsecs = secs*np.ma.MaskedArray((1, 2, 3, 4, 5, 6, 7, 8), (1, 0, 1, 0, 0, 0, 1, 0), float)
1919
#xsecs = secs*np.arange(1,10.)
2020

2121
fig = figure()

lib/matplotlib/axes/_axes.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2357,7 +2357,7 @@ def stem(self, *args, **kwargs):
23572357

23582358
# Try a second one
23592359
try:
2360-
second = np.asarray(args[0], dtype=np.float)
2360+
second = np.asarray(args[0], dtype=float)
23612361
x, y = y, second
23622362
args = args[1:]
23632363
except (IndexError, ValueError):
@@ -4739,7 +4739,7 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False,
47394739
continue
47404740

47414741
N = len(xslice)
4742-
X = np.zeros((2 * N + 2, 2), np.float)
4742+
X = np.zeros((2 * N + 2, 2), float)
47434743

47444744
if interpolate:
47454745
def get_interp_point(ind):
@@ -4889,7 +4889,7 @@ def fill_betweenx(self, y, x1, x2=0, where=None,
48894889
continue
48904890

48914891
N = len(yslice)
4892-
Y = np.zeros((2 * N + 2, 2), np.float)
4892+
Y = np.zeros((2 * N + 2, 2), float)
48934893

48944894
# the purpose of the next two lines is for when x2 is a
48954895
# scalar like 0 and we want the fill to go all the way
@@ -5387,7 +5387,7 @@ def pcolor(self, *args, **kwargs):
53875387

53885388
if t and any(t.contains_branch_seperately(self.transData)):
53895389
trans_to_data = t - self.transData
5390-
pts = np.vstack([x, y]).T.astype(np.float)
5390+
pts = np.vstack([x, y]).T.astype(float)
53915391
transformed_pts = trans_to_data.transform(pts)
53925392
x = transformed_pts[..., 0]
53935393
y = transformed_pts[..., 1]
@@ -5537,7 +5537,7 @@ def pcolormesh(self, *args, **kwargs):
55375537

55385538
if t and any(t.contains_branch_seperately(self.transData)):
55395539
trans_to_data = t - self.transData
5540-
pts = np.vstack([X, Y]).T.astype(np.float)
5540+
pts = np.vstack([X, Y]).T.astype(float)
55415541
transformed_pts = trans_to_data.transform(pts)
55425542
X = transformed_pts[..., 0]
55435543
Y = transformed_pts[..., 1]
@@ -6203,7 +6203,7 @@ def _normalize_input(inp, ename='input'):
62036203

62046204
for m, c in zip(n, color):
62056205
if bottom is None:
6206-
bottom = np.zeros(len(m), np.float)
6206+
bottom = np.zeros(len(m), float)
62076207
if stacked:
62086208
height = m - bottom
62096209
else:
@@ -6222,14 +6222,14 @@ def _normalize_input(inp, ename='input'):
62226222

62236223
elif histtype.startswith('step'):
62246224
# these define the perimeter of the polygon
6225-
x = np.zeros(4 * len(bins) - 3, np.float)
6226-
y = np.zeros(4 * len(bins) - 3, np.float)
6225+
x = np.zeros(4 * len(bins) - 3, float)
6226+
y = np.zeros(4 * len(bins) - 3, float)
62276227

62286228
x[0:2*len(bins)-1:2], x[1:2*len(bins)-1:2] = bins, bins[:-1]
62296229
x[2*len(bins)-1:] = x[1:2*len(bins)-1][::-1]
62306230

62316231
if bottom is None:
6232-
bottom = np.zeros(len(bins)-1, np.float)
6232+
bottom = np.zeros(len(bins)-1, float)
62336233

62346234
y[1:2*len(bins)-1:2], y[2:2*len(bins):2] = bottom, bottom
62356235
y[2*len(bins)-1:] = y[1:2*len(bins)-1][::-1]

lib/matplotlib/axes/_base.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from operator import itemgetter
1313

1414
import numpy as np
15-
from numpy import ma
1615

1716
import matplotlib
1817

@@ -1917,7 +1916,7 @@ def update_datalim(self, xys, updatex=True, updatey=True):
19171916

19181917
if iterable(xys) and not len(xys):
19191918
return
1920-
if not ma.isMaskedArray(xys):
1919+
if not isinstance(xys, np.ma.MaskedArray):
19211920
xys = np.asarray(xys)
19221921
self.dataLim.update_from_data_xy(xys, self.ignore_existing_data_limits,
19231922
updatex=updatex, updatey=updatey)

lib/matplotlib/backend_bases.py

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,16 +34,17 @@
3434

3535
from __future__ import (absolute_import, division, print_function,
3636
unicode_literals)
37-
from contextlib import contextmanager
3837

3938
import six
4039
from six.moves import xrange
4140

41+
from contextlib import contextmanager
42+
import importlib
43+
import io
4244
import os
4345
import sys
44-
import warnings
4546
import time
46-
import io
47+
import warnings
4748

4849
import numpy as np
4950
import matplotlib.cbook as cbook
@@ -65,14 +66,6 @@
6566
from matplotlib.cbook import mplDeprecation, warn_deprecated
6667
import matplotlib.backend_tools as tools
6768

68-
try:
69-
from importlib import import_module
70-
except:
71-
# simple python 2.6 implementation (no relative imports)
72-
def import_module(name):
73-
__import__(name)
74-
return sys.modules[name]
75-
7669
try:
7770
from PIL import Image
7871
_has_pil = True
@@ -135,7 +128,7 @@ def get_registered_canvas_class(format):
135128
return None
136129
backend_class = _default_backends[format]
137130
if cbook.is_string_like(backend_class):
138-
backend_class = import_module(backend_class).FigureCanvas
131+
backend_class = importlib.import_module(backend_class).FigureCanvas
139132
_default_backends[format] = backend_class
140133
return backend_class
141134

@@ -327,7 +320,7 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight,
327320

328321
if edgecolors is None:
329322
edgecolors = facecolors
330-
linewidths = np.array([gc.get_linewidth()], np.float_)
323+
linewidths = np.array([gc.get_linewidth()], float)
331324

332325
return self.draw_path_collection(
333326
gc, master_transform, paths, [], offsets, offsetTrans, facecolors,

lib/matplotlib/backends/backend_ps.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,7 @@
1212
def _fn_name(): return sys._getframe(1).f_code.co_name
1313
import io
1414

15-
try:
16-
from hashlib import md5
17-
except ImportError:
18-
from md5 import md5 #Deprecated in 2.5
15+
from hashlib import md5
1916

2017
from tempfile import mkstemp
2118
from matplotlib import verbose, __version__, rcParams, checkdep_ghostscript
@@ -44,10 +41,6 @@ def _fn_name(): return sys._getframe(1).f_code.co_name
4441
import numpy as np
4542
import binascii
4643
import re
47-
try:
48-
set
49-
except NameError:
50-
from sets import Set as set
5144

5245
if sys.platform.startswith('win'): cmd_split = '&'
5346
else: cmd_split = ';'

lib/matplotlib/cbook.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
from weakref import ref, WeakKeyDictionary
3232

3333
import numpy as np
34-
import numpy.ma as ma
3534

3635

3736
class MatplotlibDeprecationWarning(UserWarning):
@@ -677,7 +676,7 @@ def is_string_like(obj):
677676
if isinstance(obj, six.string_types):
678677
return True
679678
# numpy strings are subclass of str, ma strings are not
680-
if ma.isMaskedArray(obj):
679+
if isinstance(obj, np.ma.MaskedArray):
681680
if obj.ndim == 0 and obj.dtype.kind in 'SU':
682681
return True
683682
else:
@@ -1728,7 +1727,7 @@ def delete_masked_points(*args):
17281727
for i, x in enumerate(args):
17291728
if (not is_string_like(x)) and iterable(x) and len(x) == nrecs:
17301729
seqlist[i] = True
1731-
if ma.isMA(x):
1730+
if isinstance(x, np.ma.MaskedArray):
17321731
if x.ndim > 1:
17331732
raise ValueError("Masked arrays must be 1-D")
17341733
else:
@@ -1739,8 +1738,8 @@ def delete_masked_points(*args):
17391738
if seqlist[i]:
17401739
if x.ndim > 1:
17411740
continue # Don't try to get nan locations unless 1-D.
1742-
if ma.isMA(x):
1743-
masks.append(~ma.getmaskarray(x)) # invert the mask
1741+
if isinstance(x, np.ma.MaskedArray):
1742+
masks.append(~np.ma.getmaskarray(x)) # invert the mask
17441743
xd = x.data
17451744
else:
17461745
xd = x
@@ -1758,7 +1757,7 @@ def delete_masked_points(*args):
17581757
if seqlist[i]:
17591758
margs[i] = x.take(igood, axis=0)
17601759
for i, x in enumerate(margs):
1761-
if seqlist[i] and ma.isMA(x):
1760+
if seqlist[i] and isinstance(x, np.ma.MaskedArray):
17621761
margs[i] = x.filled()
17631762
return margs
17641763

@@ -2304,7 +2303,7 @@ def pts_to_prestep(x, *args):
23042303
# do normalization
23052304
vertices = _step_validation(x, *args)
23062305
# create the output array
2307-
steps = np.zeros((vertices.shape[0], 2 * len(x) - 1), np.float)
2306+
steps = np.zeros((vertices.shape[0], 2 * len(x) - 1), float)
23082307
# do the to step conversion logic
23092308
steps[0, 0::2], steps[0, 1::2] = vertices[0, :], vertices[0, :-1]
23102309
steps[1:, 0::2], steps[1:, 1:-1:2] = vertices[1:, :], vertices[1:, 1:]
@@ -2344,7 +2343,7 @@ def pts_to_poststep(x, *args):
23442343
# do normalization
23452344
vertices = _step_validation(x, *args)
23462345
# create the output array
2347-
steps = ma.zeros((vertices.shape[0], 2 * len(x) - 1), np.float)
2346+
steps = np.zeros((vertices.shape[0], 2 * len(x) - 1), float)
23482347
# do the to step conversion logic
23492348
steps[0, ::2], steps[0, 1:-1:2] = vertices[0, :], vertices[0, 1:]
23502349
steps[1:, 0::2], steps[1:, 1::2] = vertices[1:, :], vertices[1:, :-1]
@@ -2385,7 +2384,7 @@ def pts_to_midstep(x, *args):
23852384
# do normalization
23862385
vertices = _step_validation(x, *args)
23872386
# create the output array
2388-
steps = ma.zeros((vertices.shape[0], 2 * len(x)), np.float)
2387+
steps = np.zeros((vertices.shape[0], 2 * len(x)), float)
23892388
steps[0, 1:-1:2] = 0.5 * (vertices[0, :-1] + vertices[0, 1:])
23902389
steps[0, 2::2] = 0.5 * (vertices[0, :-1] + vertices[0, 1:])
23912390
steps[0, 0] = vertices[0, 0]

0 commit comments

Comments
 (0)
0