diff --git a/examples/misc/rec_join_demo.py b/examples/misc/rec_join_demo.py index 6d365042b35b..27dd8d775bb6 100644 --- a/examples/misc/rec_join_demo.py +++ b/examples/misc/rec_join_demo.py @@ -11,8 +11,7 @@ r1 = r[-10:] # Create a new array -r2 = np.empty(12, dtype=[('date', '|O4'), ('high', np.float), - ('marker', np.float)]) +r2 = np.empty(12, dtype=[('date', '|O4'), ('high', float), ('marker', float)]) r2 = r2.view(np.recarray) r2.date = r.date[-17:-5] r2.high = r.high[-17:-5] diff --git a/examples/pylab_examples/demo_ribbon_box.py b/examples/pylab_examples/demo_ribbon_box.py index 59eeddaa9f48..39bbe39789af 100644 --- a/examples/pylab_examples/demo_ribbon_box.py +++ b/examples/pylab_examples/demo_ribbon_box.py @@ -121,7 +121,7 @@ def draw(self, renderer, *args, **kwargs): interpolation="bicubic", zorder=0.1, ) - gradient = np.zeros((2, 2, 4), dtype=np.float) + gradient = np.zeros((2, 2, 4), dtype=float) gradient[:, :, :3] = [1, 1, 0.] gradient[:, :, 3] = [[0.1, 0.3], [0.3, 0.5]] # alpha channel patch_gradient.set_array(gradient) diff --git a/examples/pylab_examples/dolphin.py b/examples/pylab_examples/dolphin.py index 90f5764914f2..10fdd88f29df 100644 --- a/examples/pylab_examples/dolphin.py +++ b/examples/pylab_examples/dolphin.py @@ -74,7 +74,7 @@ vertices.extend([[float(x) for x in y.split(',')] for y in parts[i + 1:i + npoints + 1]]) i += npoints + 1 -vertices = np.array(vertices, np.float) +vertices = np.array(vertices, float) vertices[:, 1] -= 160 dolphin_path = Path(vertices, codes) diff --git a/examples/units/units_scatter.py b/examples/units/units_scatter.py index 3457cb223865..d834da7d0891 100644 --- a/examples/units/units_scatter.py +++ b/examples/units/units_scatter.py @@ -15,7 +15,7 @@ # create masked array -xsecs = secs*np.ma.MaskedArray((1, 2, 3, 4, 5, 6, 7, 8), (1, 0, 1, 0, 0, 0, 1, 0), np.float) +xsecs = secs*np.ma.MaskedArray((1, 2, 3, 4, 5, 6, 7, 8), (1, 0, 1, 0, 0, 0, 1, 0), float) #xsecs = secs*np.arange(1,10.) fig = figure() diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 6c8317eebdf9..e45d47262aa5 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -126,7 +126,6 @@ cycler) import numpy -import numpy.ma from matplotlib.externals.six.moves.urllib.request import urlopen from matplotlib.externals.six.moves import reload_module as reload diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index edb6f0be3218..11bf166400b2 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -2357,7 +2357,7 @@ def stem(self, *args, **kwargs): # Try a second one try: - second = np.asarray(args[0], dtype=np.float) + second = np.asarray(args[0], dtype=float) x, y = y, second args = args[1:] except (IndexError, ValueError): @@ -4739,7 +4739,7 @@ def fill_between(self, x, y1, y2=0, where=None, interpolate=False, continue N = len(xslice) - X = np.zeros((2 * N + 2, 2), np.float) + X = np.zeros((2 * N + 2, 2), float) if interpolate: def get_interp_point(ind): @@ -4889,7 +4889,7 @@ def fill_betweenx(self, y, x1, x2=0, where=None, continue N = len(yslice) - Y = np.zeros((2 * N + 2, 2), np.float) + Y = np.zeros((2 * N + 2, 2), float) # the purpose of the next two lines is for when x2 is a # scalar like 0 and we want the fill to go all the way @@ -6203,7 +6203,7 @@ def _normalize_input(inp, ename='input'): for m, c in zip(n, color): if bottom is None: - bottom = np.zeros(len(m), np.float) + bottom = np.zeros(len(m), float) if stacked: height = m - bottom else: @@ -6222,14 +6222,14 @@ def _normalize_input(inp, ename='input'): elif histtype.startswith('step'): # these define the perimeter of the polygon - x = np.zeros(4 * len(bins) - 3, np.float) - y = np.zeros(4 * len(bins) - 3, np.float) + x = np.zeros(4 * len(bins) - 3, float) + y = np.zeros(4 * len(bins) - 3, float) x[0:2*len(bins)-1:2], x[1:2*len(bins)-1:2] = bins, bins[:-1] x[2*len(bins)-1:] = x[1:2*len(bins)-1][::-1] if bottom is None: - bottom = np.zeros(len(bins)-1, np.float) + bottom = np.zeros(len(bins)-1, float) y[1:2*len(bins)-1:2], y[2:2*len(bins):2] = bottom, bottom y[2*len(bins)-1:] = y[1:2*len(bins)-1][::-1] diff --git a/lib/matplotlib/backend_bases.py b/lib/matplotlib/backend_bases.py index cce7d1827160..1e0405ad5790 100644 --- a/lib/matplotlib/backend_bases.py +++ b/lib/matplotlib/backend_bases.py @@ -327,7 +327,7 @@ def draw_quad_mesh(self, gc, master_transform, meshWidth, meshHeight, if edgecolors is None: edgecolors = facecolors - linewidths = np.array([gc.get_linewidth()], np.float_) + linewidths = np.array([gc.get_linewidth()], float) return self.draw_path_collection( gc, master_transform, paths, [], offsets, offsetTrans, facecolors, diff --git a/lib/matplotlib/cbook.py b/lib/matplotlib/cbook.py index d297381c49d2..c9988971ef3b 100644 --- a/lib/matplotlib/cbook.py +++ b/lib/matplotlib/cbook.py @@ -2303,7 +2303,7 @@ def pts_to_prestep(x, *args): # do normalization vertices = _step_validation(x, *args) # create the output array - steps = np.zeros((vertices.shape[0], 2 * len(x) - 1), np.float) + steps = np.zeros((vertices.shape[0], 2 * len(x) - 1), float) # do the to step conversion logic steps[0, 0::2], steps[0, 1::2] = vertices[0, :], vertices[0, :-1] steps[1:, 0::2], steps[1:, 1:-1:2] = vertices[1:, :], vertices[1:, 1:] @@ -2343,7 +2343,7 @@ def pts_to_poststep(x, *args): # do normalization vertices = _step_validation(x, *args) # create the output array - steps = np.zeros((vertices.shape[0], 2 * len(x) - 1), np.float) + steps = np.zeros((vertices.shape[0], 2 * len(x) - 1), float) # do the to step conversion logic steps[0, ::2], steps[0, 1:-1:2] = vertices[0, :], vertices[0, 1:] steps[1:, 0::2], steps[1:, 1::2] = vertices[1:, :], vertices[1:, :-1] @@ -2384,7 +2384,7 @@ def pts_to_midstep(x, *args): # do normalization vertices = _step_validation(x, *args) # create the output array - steps = np.zeros((vertices.shape[0], 2 * len(x)), np.float) + steps = np.zeros((vertices.shape[0], 2 * len(x)), float) steps[0, 1:-1:2] = 0.5 * (vertices[0, :-1] + vertices[0, 1:]) steps[0, 2::2] = 0.5 * (vertices[0, :-1] + vertices[0, 1:]) steps[0, 0] = vertices[0, 0] diff --git a/lib/matplotlib/collections.py b/lib/matplotlib/collections.py index 45ae3fd3586b..56751497777b 100644 --- a/lib/matplotlib/collections.py +++ b/lib/matplotlib/collections.py @@ -76,7 +76,7 @@ class Collection(artist.Artist, cm.ScalarMappable): (i.e., a call to set_array has been made), at draw time a call to scalar mappable will be made to set the face colors. """ - _offsets = np.array([], np.float_) + _offsets = np.array([], float) # _offsets must be a Nx2 array! _offsets.shape = (0, 2) _transOffset = transforms.IdentityTransform() @@ -129,7 +129,7 @@ def __init__(self, self.set_zorder(zorder) self._uniform_offsets = None - self._offsets = np.array([[0, 0]], np.float_) + self._offsets = np.array([[0, 0]], float) if offsets is not None: offsets = np.asanyarray(offsets) offsets.shape = (-1, 2) # Make it Nx2 @@ -197,7 +197,7 @@ def get_datalim(self, transData): offsets = transOffset.transform_non_affine(offsets) transOffset = transOffset.get_affine() - offsets = np.asanyarray(offsets, np.float_) + offsets = np.asanyarray(offsets, float) if isinstance(offsets, np.ma.MaskedArray): offsets = offsets.filled(np.nan) # get_path_collection_extents handles nan but not masked arrays @@ -239,7 +239,7 @@ def _prepare_points(self): ys = self.convert_yunits(offsets[:, 1]) offsets = list(zip(xs, ys)) - offsets = np.asanyarray(offsets, np.float_) + offsets = np.asanyarray(offsets, float) offsets.shape = (-1, 2) # Make it Nx2 if not transform.is_affine: @@ -428,7 +428,7 @@ def set_offsets(self, offsets): ACCEPTS: float or sequence of floats """ - offsets = np.asanyarray(offsets, np.float_) + offsets = np.asanyarray(offsets, float) offsets.shape = (-1, 2) # Make it Nx2 #This decision is based on how they are initialized above if self._uniform_offsets is None: @@ -1162,7 +1162,7 @@ def set_segments(self, segments): for seg in segments: if not isinstance(seg, np.ma.MaskedArray): - seg = np.asarray(seg, np.float_) + seg = np.asarray(seg, float) _segments.append(seg) if self._uniform_offsets is not None: @@ -1752,7 +1752,7 @@ def __init__(self, meshWidth, meshHeight, coordinates, # By converting to floats now, we can avoid that on every draw. self._coordinates = self._coordinates.reshape( (meshHeight + 1, meshWidth + 1, 2)) - self._coordinates = np.array(self._coordinates, np.float_) + self._coordinates = np.array(self._coordinates, float) def get_paths(self): if self._paths is None: @@ -1850,7 +1850,7 @@ def draw(self, renderer): ys = self.convert_yunits(self._offsets[:, 1]) offsets = list(zip(xs, ys)) - offsets = np.asarray(offsets, np.float_) + offsets = np.asarray(offsets, float) offsets.shape = (-1, 2) # Make it Nx2 self.update_scalarmappable() diff --git a/lib/matplotlib/colors.py b/lib/matplotlib/colors.py index af7ce3a9fe15..24473dbc38d0 100644 --- a/lib/matplotlib/colors.py +++ b/lib/matplotlib/colors.py @@ -64,7 +64,6 @@ import warnings import numpy as np -from numpy import ma import matplotlib.cbook as cbook from ._color_data import BASE_COLORS, CSS4_COLORS, XKCD_COLORS @@ -354,7 +353,7 @@ def makeMappingArray(N, data, gamma=1.0): if six.callable(data): xind = np.linspace(0, 1, N) ** gamma - lut = np.clip(np.array(data(xind), dtype=np.float), 0, 1) + lut = np.clip(np.array(data(xind), dtype=float), 0, 1) return lut try: @@ -377,7 +376,7 @@ def makeMappingArray(N, data, gamma=1.0): "data mapping points must have x in increasing order") # begin generation of lookup table x = x * (N - 1) - lut = np.zeros((N,), np.float) + lut = np.zeros((N,), float) xind = (N - 1) * np.linspace(0, 1, N) ** gamma ind = np.searchsorted(x, xind)[1:-1] @@ -459,9 +458,9 @@ def __call__(self, X, alpha=None, bytes=False): xa = np.array([X]) else: vtype = 'array' - xma = ma.array(X, copy=True) # Copy here to avoid side effects. - mask_bad = xma.mask # Mask will be used below. - xa = xma.filled() # Fill to avoid infs, etc. + xma = np.ma.array(X, copy=True) # Copy here to avoid side effects. + mask_bad = xma.mask # Mask will be used below. + xa = xma.filled() # Fill to avoid infs, etc. del xma # Calculations with native byteorder are faster, and avoid a @@ -651,7 +650,7 @@ def __init__(self, name, segmentdata, N=256, gamma=1.0): self._gamma = gamma def _init(self): - self._lut = np.ones((self.N + 3, 4), np.float) + self._lut = np.ones((self.N + 3, 4), float) self._lut[:-3, 0] = makeMappingArray( self.N, self._segmentdata['red'], self._gamma) self._lut[:-3, 1] = makeMappingArray( @@ -802,7 +801,7 @@ def __init__(self, colors, name='from_list', N=None): def _init(self): rgba = colorConverter.to_rgba_array(self.colors) - self._lut = np.zeros((self.N + 3, 4), np.float) + self._lut = np.zeros((self.N + 3, 4), float) self._lut[:-3] = rgba self._isinit = True self._set_extremes() @@ -874,7 +873,7 @@ def process_value(value): Returns *result*, *is_scalar*, where *result* is a masked array matching *value*. Float dtypes are preserved; integer types with two bytes or smaller are converted to - np.float32, and larger types are converted to np.float. + np.float32, and larger types are converted to np.float64. Preserving float32 when possible, and using in-place operations, can greatly improve speed for large arrays. @@ -883,7 +882,7 @@ def process_value(value): """ if cbook.iterable(value): is_scalar = False - result = ma.asarray(value) + result = np.ma.asarray(value) if result.dtype.kind == 'f': # this is overkill for lists of floats, but required # to support pd.Series as input until we can reliable @@ -896,7 +895,7 @@ def process_value(value): result = result.astype(np.float32) else: is_scalar = True - result = ma.array([value]).astype(float) + result = np.ma.array([value]).astype(float) return result, is_scalar def __call__(self, value, clip=None): @@ -922,9 +921,9 @@ def __call__(self, value, clip=None): vmin = float(vmin) vmax = float(vmax) if clip: - mask = ma.getmask(result) - result = ma.array(np.clip(result.filled(vmax), vmin, vmax), - mask=mask) + mask = np.ma.getmask(result) + result = np.ma.array(np.clip(result.filled(vmax), vmin, vmax), + mask=mask) # ma division is very slow; we can take a shortcut resdat = result.data resdat -= vmin @@ -941,7 +940,7 @@ def inverse(self, value): vmax = float(self.vmax) if cbook.iterable(value): - val = ma.asarray(value) + val = np.ma.asarray(value) return vmin + val * (vmax - vmin) else: return vmin + value * (vmax - vmin) @@ -950,15 +949,15 @@ def autoscale(self, A): """ Set *vmin*, *vmax* to min, max of *A*. """ - self.vmin = ma.min(A) - self.vmax = ma.max(A) + self.vmin = np.ma.min(A) + self.vmax = np.ma.max(A) def autoscale_None(self, A): ' autoscale only None-valued vmin or vmax' if self.vmin is None and np.size(A) > 0: - self.vmin = ma.min(A) + self.vmin = np.ma.min(A) if self.vmax is None and np.size(A) > 0: - self.vmax = ma.max(A) + self.vmax = np.ma.max(A) def scaled(self): 'return true if vmin and vmax set' @@ -975,7 +974,7 @@ def __call__(self, value, clip=None): result, is_scalar = self.process_value(value) - result = ma.masked_less_equal(result, 0, copy=False) + result = np.ma.masked_less_equal(result, 0, copy=False) self.autoscale_None(result) vmin, vmax = self.vmin, self.vmax @@ -987,8 +986,8 @@ def __call__(self, value, clip=None): result.fill(0) else: if clip: - mask = ma.getmask(result) - result = ma.array(np.clip(result.filled(vmax), vmin, vmax), + mask = np.ma.getmask(result) + result = np.ma.array(np.clip(result.filled(vmax), vmin, vmax), mask=mask) # in-place equivalent of above can be much faster resdat = result.data @@ -1012,8 +1011,8 @@ def inverse(self, value): vmin, vmax = self.vmin, self.vmax if cbook.iterable(value): - val = ma.asarray(value) - return vmin * ma.power((vmax / vmin), val) + val = np.ma.asarray(value) + return vmin * np.ma.power((vmax / vmin), val) else: return vmin * pow((vmax / vmin), value) @@ -1021,19 +1020,19 @@ def autoscale(self, A): """ Set *vmin*, *vmax* to min, max of *A*. """ - A = ma.masked_less_equal(A, 0, copy=False) - self.vmin = ma.min(A) - self.vmax = ma.max(A) + A = np.ma.masked_less_equal(A, 0, copy=False) + self.vmin = np.ma.min(A) + self.vmax = np.ma.max(A) def autoscale_None(self, A): ' autoscale only None-valued vmin or vmax' if self.vmin is not None and self.vmax is not None: return - A = ma.masked_less_equal(A, 0, copy=False) + A = np.ma.masked_less_equal(A, 0, copy=False) if self.vmin is None: - self.vmin = ma.min(A) + self.vmin = np.ma.min(A) if self.vmax is None: - self.vmax = ma.max(A) + self.vmax = np.ma.max(A) class SymLogNorm(Normalize): @@ -1080,9 +1079,9 @@ def __call__(self, value, clip=None): result.fill(0) else: if clip: - mask = ma.getmask(result) - result = ma.array(np.clip(result.filled(vmax), vmin, vmax), - mask=mask) + mask = np.ma.getmask(result) + result = np.ma.array(np.clip(result.filled(vmax), vmin, vmax), + mask=mask) # in-place equivalent of above can be much faster resdat = self._transform(result.data) resdat -= self._lower @@ -1127,7 +1126,7 @@ def _transform_vmin_vmax(self): def inverse(self, value): if not self.scaled(): raise ValueError("Not invertible until scaled") - val = ma.asarray(value) + val = np.ma.asarray(value) val = val * (self._upper - self._lower) + self._lower return self._inv_transform(val) @@ -1135,8 +1134,8 @@ def autoscale(self, A): """ Set *vmin*, *vmax* to min, max of *A*. """ - self.vmin = ma.min(A) - self.vmax = ma.max(A) + self.vmin = np.ma.min(A) + self.vmax = np.ma.max(A) self._transform_vmin_vmax() def autoscale_None(self, A): @@ -1144,9 +1143,9 @@ def autoscale_None(self, A): if self.vmin is not None and self.vmax is not None: pass if self.vmin is None: - self.vmin = ma.min(A) + self.vmin = np.ma.min(A) if self.vmax is None: - self.vmax = ma.max(A) + self.vmax = np.ma.max(A) self._transform_vmin_vmax() @@ -1175,9 +1174,9 @@ def __call__(self, value, clip=None): else: res_mask = result.data < 0 if clip: - mask = ma.getmask(result) - result = ma.array(np.clip(result.filled(vmax), vmin, vmax), - mask=mask) + mask = np.ma.getmask(result) + result = np.ma.array(np.clip(result.filled(vmax), vmin, vmax), + mask=mask) resdat = result.data resdat -= vmin np.power(resdat, gamma, resdat) @@ -1196,8 +1195,8 @@ def inverse(self, value): vmin, vmax = self.vmin, self.vmax if cbook.iterable(value): - val = ma.asarray(value) - return ma.power(val, 1. / gamma) * (vmax - vmin) + vmin + val = np.ma.asarray(value) + return np.ma.power(val, 1. / gamma) * (vmax - vmin) + vmin else: return pow(value, 1. / gamma) * (vmax - vmin) + vmin @@ -1205,25 +1204,25 @@ def autoscale(self, A): """ Set *vmin*, *vmax* to min, max of *A*. """ - self.vmin = ma.min(A) + self.vmin = np.ma.min(A) if self.vmin < 0: self.vmin = 0 warnings.warn("Power-law scaling on negative values is " "ill-defined, clamping to 0.") - self.vmax = ma.max(A) + self.vmax = np.ma.max(A) def autoscale_None(self, A): ' autoscale only None-valued vmin or vmax' if self.vmin is None and np.size(A) > 0: - self.vmin = ma.min(A) + self.vmin = np.ma.min(A) if self.vmin < 0: self.vmin = 0 warnings.warn("Power-law scaling on negative values is " "ill-defined, clamping to 0.") if self.vmax is None and np.size(A) > 0: - self.vmax = ma.max(A) + self.vmax = np.ma.max(A) class BoundaryNorm(Normalize): @@ -1277,7 +1276,7 @@ def __call__(self, value, clip=None): clip = self.clip xx, is_scalar = self.process_value(value) - mask = ma.getmaskarray(xx) + mask = np.ma.getmaskarray(xx) xx = np.atleast_1d(xx.filled(self.vmax + 1)) if clip: np.clip(xx, self.vmin, self.vmax, out=xx) @@ -1292,7 +1291,7 @@ def __call__(self, value, clip=None): iret = (iret * scalefac).astype(np.int16) iret[xx < self.vmin] = -1 iret[xx >= self.vmax] = max_col - ret = ma.array(iret, mask=mask) + ret = np.ma.array(iret, mask=mask) if is_scalar: ret = int(ret[0]) # assume python scalar return ret diff --git a/lib/matplotlib/finance.py b/lib/matplotlib/finance.py index cbdb592c8b3e..240273e41a2d 100644 --- a/lib/matplotlib/finance.py +++ b/lib/matplotlib/finance.py @@ -263,7 +263,7 @@ def _parse_yahoo_historical(fh, adjusted=True, asobject=False, if not asobject: # 2-D sequence; formerly list of tuples, now ndarray - ret = np.zeros((len(d), 6), dtype=np.float) + ret = np.zeros((len(d), 6), dtype=float) ret[:, 0] = d['d'] if ochl: ret[:, 1] = d['open'] diff --git a/lib/matplotlib/image.py b/lib/matplotlib/image.py index 0d86e2b74081..7188066121e0 100644 --- a/lib/matplotlib/image.py +++ b/lib/matplotlib/image.py @@ -516,7 +516,7 @@ def set_data(self, A): self._A = cbook.safe_masked_invalid(A, copy=True) if (self._A.dtype != np.uint8 and - not np.can_cast(self._A.dtype, np.float)): + not np.can_cast(self._A.dtype, float)): raise TypeError("Image data can not convert to float") if (self._A.ndim not in (2, 3) or diff --git a/lib/matplotlib/lines.py b/lib/matplotlib/lines.py index 8ef22f354b5d..9c6cbd841f0c 100644 --- a/lib/matplotlib/lines.py +++ b/lib/matplotlib/lines.py @@ -628,31 +628,31 @@ def recache(self, always=False): if always or self._invalidx: xconv = self.convert_xunits(self._xorig) if isinstance(self._xorig, np.ma.MaskedArray): - x = np.ma.asarray(xconv, np.float_).filled(np.nan) + x = np.ma.asarray(xconv, float).filled(np.nan) else: - x = np.asarray(xconv, np.float_) + x = np.asarray(xconv, float) x = x.ravel() else: x = self._x if always or self._invalidy: yconv = self.convert_yunits(self._yorig) if isinstance(self._yorig, np.ma.MaskedArray): - y = np.ma.asarray(yconv, np.float_).filled(np.nan) + y = np.ma.asarray(yconv, float).filled(np.nan) else: - y = np.asarray(yconv, np.float_) + y = np.asarray(yconv, float) y = y.ravel() else: y = self._y if len(x) == 1 and len(y) > 1: - x = x * np.ones(y.shape, np.float_) + x = x * np.ones(y.shape, float) if len(y) == 1 and len(x) > 1: - y = y * np.ones(x.shape, np.float_) + y = y * np.ones(x.shape, float) if len(x) != len(y): raise RuntimeError('xdata and ydata must be the same length') - self._xy = np.empty((len(x), 2), dtype=np.float_) + self._xy = np.empty((len(x), 2), dtype=float) self._xy[:, 0] = x self._xy[:, 1] = y diff --git a/lib/matplotlib/mlab.py b/lib/matplotlib/mlab.py index f7c68070dd99..b952ecebabc8 100644 --- a/lib/matplotlib/mlab.py +++ b/lib/matplotlib/mlab.py @@ -516,7 +516,7 @@ def detrend_linear(y): if not y.ndim: return np.array(0., dtype=y.dtype) - x = np.arange(y.size, dtype=np.float_) + x = np.arange(y.size, dtype=float) C = np.cov(x, y, bias=1) b = C[0, 1]/C[0, 0] @@ -1828,7 +1828,7 @@ def center_matrix(M, dim=0): If *dim* = 1 operate on columns instead of rows. (*dim* is opposite to the numpy axis kwarg.) """ - M = np.asarray(M, np.float_) + M = np.asarray(M, float) if dim: M = (M - M.mean(axis=0)) / M.std(axis=0) else: @@ -1886,9 +1886,9 @@ def derivs(x,t): try: Ny = len(y0) except TypeError: - yout = np.zeros((len(t),), np.float_) + yout = np.zeros((len(t),), float) else: - yout = np.zeros((len(t), Ny), np.float_) + yout = np.zeros((len(t), Ny), float) yout[0] = y0 i = 0 @@ -1968,9 +1968,9 @@ def dist_point_to_segment(p, s0, s1): This algorithm from http://softsurfer.com/Archive/algorithm_0102/algorithm_0102.htm#Distance%20to%20Ray%20or%20Segment """ - p = np.asarray(p, np.float_) - s0 = np.asarray(s0, np.float_) - s1 = np.asarray(s1, np.float_) + p = np.asarray(p, float) + s0 = np.asarray(s0, float) + s1 = np.asarray(s1, float) v = s1 - s0 w = p - s0 @@ -2032,7 +2032,7 @@ def movavg(x, n): """ Compute the len(*n*) moving average of *x*. """ - w = np.empty((n,), dtype=np.float_) + w = np.empty((n,), dtype=float) w[:] = 1.0/n return np.convolve(x, w, mode='valid') @@ -3519,10 +3519,10 @@ def slopes(x, y): Icelandic Meteorological Office, March 2006 halldor at vedur.is) """ # Cast key variables as float. - x = np.asarray(x, np.float_) - y = np.asarray(y, np.float_) + x = np.asarray(x, float) + y = np.asarray(y, float) - yp = np.zeros(y.shape, np.float_) + yp = np.zeros(y.shape, float) dx = x[1:] - x[:-1] dy = y[1:] - y[:-1] @@ -3576,18 +3576,18 @@ def stineman_interp(xi, x, y, yp=None): """ # Cast key variables as float. - x = np.asarray(x, np.float_) - y = np.asarray(y, np.float_) + x = np.asarray(x, float) + y = np.asarray(y, float) if x.shape != y.shape: raise ValueError("'x' and 'y' must be of same shape") if yp is None: yp = slopes(x, y) else: - yp = np.asarray(yp, np.float_) + yp = np.asarray(yp, float) - xi = np.asarray(xi, np.float_) - yi = np.zeros(xi.shape, np.float_) + xi = np.asarray(xi, float) + yi = np.zeros(xi.shape, float) # calculate linear slopes dx = x[1:] - x[:-1] @@ -3764,7 +3764,7 @@ def evaluate(self, points): dim, self.dim) raise ValueError(msg) - result = np.zeros((num_m,), dtype=np.float) + result = np.zeros((num_m,), dtype=float) if num_m >= self.num_dp: # there are more points than data, so loop over data @@ -3817,7 +3817,7 @@ def poly_below(xmin, xs, ys): xv, yv = poly_below(0, x, y) ax.fill(xv, yv) """ - if isinstance(xs, np.ma.MaskedArray) or isinstance(ys, np.ma.MaskedArray): + if any(isinstance(var, np.ma.MaskedArray) for var in [xs, ys]): numpy = np.ma else: numpy = np @@ -3846,9 +3846,7 @@ def poly_between(x, ylower, yupper): Return value is *x*, *y* arrays for use with :meth:`matplotlib.axes.Axes.fill`. """ - if (isinstance(ylower, np.ma.MaskedArray) or - isinstance(yupper, np.ma.MaskedArray) or - isinstance(x, np.ma.MaskedArray)): + if any(isinstance(var, np.ma.MaskedArray) for var in [ylower, yupper, x]): numpy = np.ma else: numpy = np diff --git a/lib/matplotlib/path.py b/lib/matplotlib/path.py index af43241ca371..be73fa657edf 100644 --- a/lib/matplotlib/path.py +++ b/lib/matplotlib/path.py @@ -133,7 +133,7 @@ def __init__(self, vertices, codes=None, _interpolation_steps=1, if isinstance(vertices, np.ma.MaskedArray): vertices = vertices.astype(float).filled(np.nan) else: - vertices = np.asarray(vertices, np.float_) + vertices = np.asarray(vertices, float) if (vertices.ndim != 2) or (vertices.shape[1] != 2): msg = "'vertices' must be a 2D list or array with shape Nx2" @@ -189,7 +189,7 @@ def _fast_from_codes_and_verts(cls, verts, codes, internals=None): if isinstance(verts, np.ma.MaskedArray): verts = verts.astype(float).filled(np.nan) else: - verts = np.asarray(verts, np.float_) + verts = np.asarray(verts, float) pth._vertices = verts pth._codes = codes pth._readonly = internals.pop('readonly', False) @@ -775,7 +775,7 @@ def circle(cls, center=(0., 0.), radius=1., readonly=False): [0.0, -1.0], [0.0, -1.0]], - dtype=np.float_) + dtype=float) codes = [cls.CURVE4] * 26 codes[0] = cls.MOVETO @@ -821,7 +821,7 @@ def unit_circle_righthalf(cls): [0.0, -1.0]], - np.float_) + float) codes = cls.CURVE4 * np.ones(14) codes[0] = cls.MOVETO @@ -881,7 +881,7 @@ def arc(cls, theta1, theta2, n=None, is_wedge=False): if is_wedge: length = n * 3 + 4 - vertices = np.zeros((length, 2), np.float_) + vertices = np.zeros((length, 2), float) codes = cls.CURVE4 * np.ones((length, ), cls.code_type) vertices[1] = [xA[0], yA[0]] codes[0:2] = [cls.MOVETO, cls.LINETO] @@ -890,7 +890,7 @@ def arc(cls, theta1, theta2, n=None, is_wedge=False): end = length - 2 else: length = n * 3 + 1 - vertices = np.empty((length, 2), np.float_) + vertices = np.empty((length, 2), float) codes = cls.CURVE4 * np.ones((length, ), cls.code_type) vertices[0] = [xA[0], yA[0]] codes[0] = cls.MOVETO diff --git a/lib/matplotlib/projections/geo.py b/lib/matplotlib/projections/geo.py index 0e8c66d86938..3c66b7ce4027 100644 --- a/lib/matplotlib/projections/geo.py +++ b/lib/matplotlib/projections/geo.py @@ -440,7 +440,7 @@ def d(theta): clat = np.pi/2 - np.abs(latitude) ihigh = clat < 0.087 # within 5 degrees of the poles ilow = ~ihigh - aux = np.empty(latitude.shape, dtype=np.float) + aux = np.empty(latitude.shape, dtype=float) if ilow.any(): # Newton-Raphson iteration pi_sin_l = np.pi * np.sin(latitude[ilow]) @@ -456,7 +456,7 @@ def d(theta): d = 0.5 * (3 * np.pi * e**2) ** (1.0/3) aux[ihigh] = (np.pi/2 - d) * np.sign(latitude[ihigh]) - xy = np.empty(ll.shape, dtype=np.float) + xy = np.empty(ll.shape, dtype=float) xy[:,0] = (2.0 * np.sqrt(2.0) / np.pi) * longitude * np.cos(aux) xy[:,1] = np.sqrt(2.0) * np.sin(aux) diff --git a/lib/matplotlib/projections/polar.py b/lib/matplotlib/projections/polar.py index a52e343bb07e..7d16da446b49 100644 --- a/lib/matplotlib/projections/polar.py +++ b/lib/matplotlib/projections/polar.py @@ -40,7 +40,7 @@ def __init__(self, axis=None, use_rmin=True): self._use_rmin = use_rmin def transform_non_affine(self, tr): - xy = np.empty(tr.shape, np.float_) + xy = np.empty(tr.shape, float) if self._axis is not None: if self._use_rmin: rmin = self._axis.viewLim.ymin @@ -522,7 +522,7 @@ def set_thetagrids(self, angles, labels=None, frac=None, fmt=None, """ # Make sure we take into account unitized data angles = self.convert_yunits(angles) - angles = np.asarray(angles, np.float_) + angles = np.asarray(angles, float) self.set_xticks(angles * (np.pi / 180.0)) if labels is not None: self.set_xticklabels(labels) @@ -712,7 +712,7 @@ def drag_pan(self, button, key, x, y): # vertices = self.transform(vertices) -# result = np.zeros((len(vertices) * 3 - 2, 2), np.float_) +# result = np.zeros((len(vertices) * 3 - 2, 2), float) # codes = mpath.Path.CURVE4 * np.ones((len(vertices) * 3 - 2, ), mpath.Path.code_type) # result[0] = vertices[0] # codes[0] = mpath.Path.MOVETO @@ -769,7 +769,7 @@ def drag_pan(self, button, key, x, y): # if interpolate > 1.0: # vertices = self.interpolate(vertices, interpolate) -# result = np.zeros((len(vertices) * 3 - 2, 2), np.float_) +# result = np.zeros((len(vertices) * 3 - 2, 2), float) # codes = mpath.Path.CURVE4 * np.ones((len(vertices) * 3 - 2, ), mpath.Path.code_type) # result[0] = vertices[0] # codes[0] = mpath.Path.MOVETO diff --git a/lib/matplotlib/streamplot.py b/lib/matplotlib/streamplot.py index 51409fad6828..469fb0893515 100644 --- a/lib/matplotlib/streamplot.py +++ b/lib/matplotlib/streamplot.py @@ -133,7 +133,7 @@ def streamplot(axes, x, y, u, v, density=1, linewidth=None, color=None, if t is not None: trajectories.append(t) else: - sp2 = np.asanyarray(start_points, dtype=np.float).copy() + sp2 = np.asanyarray(start_points, dtype=float).copy() # Check if start_points are outside the data boundaries for xs, ys in sp2: diff --git a/lib/matplotlib/tests/test_colors.py b/lib/matplotlib/tests/test_colors.py index d9fd93f40a47..523e4e92c09b 100644 --- a/lib/matplotlib/tests/test_colors.py +++ b/lib/matplotlib/tests/test_colors.py @@ -157,12 +157,12 @@ def test_LogNorm(): def test_PowerNorm(): - a = np.array([0, 0.5, 1, 1.5], dtype=np.float) + a = np.array([0, 0.5, 1, 1.5], dtype=float) pnorm = mcolors.PowerNorm(1) norm = mcolors.Normalize() assert_array_almost_equal(norm(a), pnorm(a)) - a = np.array([-0.5, 0, 2, 4, 8], dtype=np.float) + a = np.array([-0.5, 0, 2, 4, 8], dtype=float) expected = [0, 0, 1/16, 1/4, 1] pnorm = mcolors.PowerNorm(2, vmin=0, vmax=8) assert_array_almost_equal(pnorm(a), expected) @@ -171,7 +171,7 @@ def test_PowerNorm(): assert_array_almost_equal(a[1:], pnorm.inverse(pnorm(a))[1:]) # Clip = True - a = np.array([-0.5, 0, 1, 8, 16], dtype=np.float) + a = np.array([-0.5, 0, 1, 8, 16], dtype=float) expected = [0, 0, 0, 1, 1] pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=True) assert_array_almost_equal(pnorm(a), expected) @@ -179,7 +179,7 @@ def test_PowerNorm(): assert_equal(pnorm(a[-1]), expected[-1]) # Clip = True at call time - a = np.array([-0.5, 0, 1, 8, 16], dtype=np.float) + a = np.array([-0.5, 0, 1, 8, 16], dtype=float) expected = [0, 0, 0, 1, 1] pnorm = mcolors.PowerNorm(2, vmin=2, vmax=8, clip=False) assert_array_almost_equal(pnorm(a, clip=True), expected) @@ -189,7 +189,7 @@ def test_PowerNorm(): def test_Normalize(): norm = mcolors.Normalize() - vals = np.arange(-10, 10, 1, dtype=np.float) + vals = np.arange(-10, 10, 1, dtype=float) _inverse_tester(norm, vals) _scalar_tester(norm, vals) _mask_tester(norm, vals) @@ -200,7 +200,7 @@ def test_SymLogNorm(): Test SymLogNorm behavior """ norm = mcolors.SymLogNorm(3, vmax=5, linscale=1.2) - vals = np.array([-30, -1, 2, 6], dtype=np.float) + vals = np.array([-30, -1, 2, 6], dtype=float) normed_vals = norm(vals) expected = [0., 0.53980074, 0.826991, 1.02758204] assert_array_almost_equal(normed_vals, expected) diff --git a/lib/matplotlib/tests/test_image.py b/lib/matplotlib/tests/test_image.py index 37cef625d253..bd157a2758b0 100644 --- a/lib/matplotlib/tests/test_image.py +++ b/lib/matplotlib/tests/test_image.py @@ -488,7 +488,7 @@ def test_jpeg_alpha(): plt.figure(figsize=(1, 1), dpi=300) # Create an image that is all black, with a gradient from 0-1 in # the alpha channel from left to right. - im = np.zeros((300, 300, 4), dtype=np.float) + im = np.zeros((300, 300, 4), dtype=float) im[..., 3] = np.linspace(0.0, 1.0, 300) plt.figimage(im) diff --git a/lib/matplotlib/tests/test_mlab.py b/lib/matplotlib/tests/test_mlab.py index 5eca224813c8..ae7de531f793 100644 --- a/lib/matplotlib/tests/test_mlab.py +++ b/lib/matplotlib/tests/test_mlab.py @@ -316,9 +316,9 @@ def tearDown(self): def test_recarray_csv_roundtrip(self): expected = np.recarray((99,), - [(str('x'), np.float), - (str('y'), np.float), - (str('t'), np.float)]) + [(str('x'), float), + (str('y'), float), + (str('t'), float)]) # initialising all values: uninitialised memory sometimes produces # floats that do not round-trip to string and back. expected['x'][:] = np.linspace(-1e9, -1, 99) @@ -334,8 +334,8 @@ def test_recarray_csv_roundtrip(self): assert_allclose(expected['t'], actual['t']) def test_rec2csv_bad_shape_ValueError(self): - bad = np.recarray((99, 4), [(str('x'), np.float), - (str('y'), np.float)]) + bad = np.recarray((99, 4), [(str('x'), float), + (str('y'), float)]) # the bad recarray should trigger a ValueError for having ndim > 1. assert_raises(ValueError, mlab.rec2csv, bad, self.fd) @@ -2869,7 +2869,7 @@ def test_kde_integer_input(self): np.testing.assert_array_almost_equal(kde(x1), y_expected, decimal=6) def test_gaussian_kde_covariance_caching(self): - x1 = np.array([-7, -5, 1, 4, 5], dtype=np.float) + x1 = np.array([-7, -5, 1, 4, 5], dtype=float) xs = np.linspace(-10, 10, num=5) # These expected values are from scipy 0.10, before some changes to # gaussian_kde. They were not compared with any external reference. diff --git a/lib/matplotlib/texmanager.py b/lib/matplotlib/texmanager.py index c1a2010c957f..1752866fe6ee 100644 --- a/lib/matplotlib/texmanager.py +++ b/lib/matplotlib/texmanager.py @@ -636,7 +636,7 @@ def get_rgba(self, tex, fontsize=None, dpi=None, rgb=(0, 0, 0)): if Z is None: alpha = self.get_grey(tex, fontsize, dpi) - Z = np.zeros((alpha.shape[0], alpha.shape[1], 4), np.float) + Z = np.zeros((alpha.shape[0], alpha.shape[1], 4), float) Z[:, :, 0] = r Z[:, :, 1] = g diff --git a/lib/matplotlib/text.py b/lib/matplotlib/text.py index 2e4957a3e7fa..fe9370cd483b 100644 --- a/lib/matplotlib/text.py +++ b/lib/matplotlib/text.py @@ -399,8 +399,7 @@ def _get_layout(self, renderer): # the corners of the unrotated bounding box cornersHoriz = np.array( - [(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)], - np.float_) + [(xmin, ymin), (xmin, ymax), (xmax, ymax), (xmax, ymin)], float) cornersHoriz[:, 1] -= descent # now rotate the bbox diff --git a/lib/matplotlib/transforms.py b/lib/matplotlib/transforms.py index a0e28ffcc9de..4bafef1415ef 100644 --- a/lib/matplotlib/transforms.py +++ b/lib/matplotlib/transforms.py @@ -784,7 +784,7 @@ def __init__(self, points, **kwargs): :meth:`from_bounds` and :meth:`from_extents`. """ BboxBase.__init__(self, **kwargs) - points = np.asarray(points, np.float_) + points = np.asarray(points, float) if points.shape != (2, 2): raise ValueError('Bbox points must be of the form ' '"[[x0, y0], [x1, y1]]".') @@ -812,7 +812,7 @@ def unit(): (staticmethod) Create a new unit :class:`Bbox` from (0, 0) to (1, 1). """ - return Bbox(np.array([[0.0, 0.0], [1.0, 1.0]], np.float)) + return Bbox(np.array([[0.0, 0.0], [1.0, 1.0]], float)) @staticmethod def null(): @@ -820,7 +820,7 @@ def null(): (staticmethod) Create a new null :class:`Bbox` from (inf, inf) to (-inf, -inf). """ - return Bbox(np.array([[np.inf, np.inf], [-np.inf, -np.inf]], np.float)) + return Bbox(np.array([[np.inf, np.inf], [-np.inf, -np.inf]], float)) @staticmethod def from_bounds(x0, y0, width, height): @@ -840,7 +840,7 @@ def from_extents(*args): The *y*-axis increases upwards. """ - points = np.array(args, dtype=np.float_).reshape(2, 2) + points = np.array(args, dtype=float).reshape(2, 2) return Bbox(points) def __format__(self, fmt): @@ -994,7 +994,7 @@ def _set_intervaly(self, interval): def _set_bounds(self, bounds): l, b, w, h = bounds - points = np.array([[l, b], [l + w, b + h]], np.float_) + points = np.array([[l, b], [l + w, b + h]], float) if np.any(self._points != points): self._points = points self.invalidate() @@ -1758,7 +1758,7 @@ def matrix_from_values(a, b, c, d, e, f): b d f 0 0 1 """ - return np.array([[a, c, e], [b, d, f], [0.0, 0.0, 1.0]], np.float_) + return np.array([[a, c, e], [b, d, f], [0.0, 0.0, 1.0]], float) def transform_affine(self, points): mtx = self.get_matrix() @@ -1818,7 +1818,7 @@ def __init__(self, matrix=None, **kwargs): if matrix is None: matrix = np.identity(3) elif DEBUG: - matrix = np.asarray(matrix, np.float_) + matrix = np.asarray(matrix, float) assert matrix.shape == (3, 3) self._mtx = matrix self._invalid = 0 @@ -1846,8 +1846,7 @@ def from_values(a, b, c, d, e, f): . """ return Affine2D( - np.array([a, c, e, b, d, f, 0.0, 0.0, 1.0], np.float_) - .reshape((3, 3))) + np.array([a, c, e, b, d, f, 0.0, 0.0, 1.0], float).reshape((3, 3))) def get_matrix(self): """ @@ -1916,9 +1915,8 @@ def rotate(self, theta): """ a = np.cos(theta) b = np.sin(theta) - rotate_mtx = np.array( - [[a, -b, 0.0], [b, a, 0.0], [0.0, 0.0, 1.0]], - np.float_) + rotate_mtx = np.array([[a, -b, 0.0], [b, a, 0.0], [0.0, 0.0, 1.0]], + float) self._mtx = np.dot(rotate_mtx, self._mtx) self.invalidate() return self @@ -1962,8 +1960,7 @@ def translate(self, tx, ty): and :meth:`scale`. """ translate_mtx = np.array( - [[1.0, 0.0, tx], [0.0, 1.0, ty], [0.0, 0.0, 1.0]], - np.float_) + [[1.0, 0.0, tx], [0.0, 1.0, ty], [0.0, 0.0, 1.0]], float) self._mtx = np.dot(translate_mtx, self._mtx) self.invalidate() return self @@ -1982,8 +1979,7 @@ def scale(self, sx, sy=None): if sy is None: sy = sx scale_mtx = np.array( - [[sx, 0.0, 0.0], [0.0, sy, 0.0], [0.0, 0.0, 1.0]], - np.float_) + [[sx, 0.0, 0.0], [0.0, sy, 0.0], [0.0, 0.0, 1.0]], float) self._mtx = np.dot(scale_mtx, self._mtx) self.invalidate() return self @@ -2002,8 +1998,7 @@ def skew(self, xShear, yShear): rotX = np.tan(xShear) rotY = np.tan(yShear) skew_mtx = np.array( - [[1.0, rotX, 0.0], [rotY, 1.0, 0.0], [0.0, 0.0, 1.0]], - np.float_) + [[1.0, rotX, 0.0], [rotY, 1.0, 0.0], [0.0, 0.0, 1.0]], float) self._mtx = np.dot(skew_mtx, self._mtx) self.invalidate() return self @@ -2530,9 +2525,9 @@ def get_matrix(self): if DEBUG and (x_scale == 0 or y_scale == 0): raise ValueError("Transforming from or to a singular bounding box.") self._mtx = np.array([[x_scale, 0.0 , (-inl*x_scale+outl)], - [0.0 , y_scale, (-inb*y_scale+outb)], - [0.0 , 0.0 , 1.0 ]], - np.float_) + [0.0 , y_scale, (-inb*y_scale+outb)], + [0.0 , 0.0 , 1.0 ]], + float) self._inverted = None self._invalid = 0 return self._mtx @@ -2570,9 +2565,9 @@ def get_matrix(self): if DEBUG and (outw == 0 or outh == 0): raise ValueError("Transforming to a singular bounding box.") self._mtx = np.array([[outw, 0.0, outl], - [ 0.0, outh, outb], - [ 0.0, 0.0, 1.0]], - np.float_) + [ 0.0, outh, outb], + [ 0.0, 0.0, 1.0]], + float) self._inverted = None self._invalid = 0 return self._mtx @@ -2596,7 +2591,7 @@ def get_matrix(self): self._mtx = np.array([[xmax, 0.0, 0.0], [ 0.0, ymax, 0.0], [ 0.0, 0.0, 1.0]], - np.float_) + float) self._inverted = None self._invalid = 0 return self._mtx @@ -2631,9 +2626,9 @@ def get_matrix(self): x_scale = 1.0 / inw y_scale = 1.0 / inh self._mtx = np.array([[x_scale, 0.0 , (-inl*x_scale)], - [0.0 , y_scale, (-inb*y_scale)], - [0.0 , 0.0 , 1.0 ]], - np.float_) + [0.0 , y_scale, (-inb*y_scale)], + [0.0 , 0.0 , 1.0 ]], + float) self._inverted = None self._invalid = 0 return self._mtx @@ -2660,9 +2655,9 @@ def get_matrix(self): if self._invalid: xt, yt = self._scale_trans.transform_point(self._t) self._mtx = np.array([[1.0, 0.0, xt], - [0.0, 1.0, yt], - [0.0, 0.0, 1.0]], - np.float_) + [0.0, 1.0, yt], + [0.0, 0.0, 1.0]], + float) self._invalid = 0 self._inverted = None return self._mtx