diff --git a/lib/matplotlib/axes/_axes.py b/lib/matplotlib/axes/_axes.py index 70472e05758a..1548df33d97c 100644 --- a/lib/matplotlib/axes/_axes.py +++ b/lib/matplotlib/axes/_axes.py @@ -4000,7 +4000,7 @@ def dopatch(xs, ys, **kwargs): # maybe draw the fliers if showfliers: # fliers coords - flier_x = np.ones(len(stats['fliers'])) * pos + flier_x = np.full(len(stats['fliers']), pos, dtype=np.float64) flier_y = stats['fliers'] fliers.extend(doplot( diff --git a/lib/matplotlib/hatch.py b/lib/matplotlib/hatch.py index 532840624d26..f52c03c36fb2 100644 --- a/lib/matplotlib/hatch.py +++ b/lib/matplotlib/hatch.py @@ -169,7 +169,8 @@ def __init__(self, hatch, density): self.num_rows = (hatch.count('*')) * density path = Path.unit_regular_star(5) self.shape_vertices = path.vertices - self.shape_codes = np.ones(len(self.shape_vertices)) * Path.LINETO + self.shape_codes = np.full(len(self.shape_vertices), Path.LINETO, + dtype=Path.code_type) self.shape_codes[0] = Path.MOVETO Shapes.__init__(self, hatch, density) diff --git a/lib/matplotlib/legend_handler.py b/lib/matplotlib/legend_handler.py index 5d4e55a351da..b2cd85d4677f 100644 --- a/lib/matplotlib/legend_handler.py +++ b/lib/matplotlib/legend_handler.py @@ -231,7 +231,7 @@ def create_artists(self, legend, orig_handle, xdata, xdata_marker = self.get_xdata(legend, xdescent, ydescent, width, height, fontsize) - ydata = ((height - ydescent) / 2.) * np.ones(xdata.shape, float) + ydata = np.full_like(xdata, ((height - ydescent) / 2)) legline = Line2D(xdata, ydata) self.update_prop(legline, orig_handle, legend) diff --git a/lib/matplotlib/path.py b/lib/matplotlib/path.py index 24dee6e58071..f8a4b9e05d53 100644 --- a/lib/matplotlib/path.py +++ b/lib/matplotlib/path.py @@ -312,7 +312,7 @@ def make_compound_path_from_polys(cls, XY): stride = numsides + 1 nverts = numpolys * stride verts = np.zeros((nverts, 2)) - codes = np.ones(nverts, int) * cls.LINETO + codes = np.full(nverts, cls.LINETO, dtype=cls.code_type) codes[0::stride] = cls.MOVETO codes[numsides::stride] = cls.CLOSEPOLY for i in range(numsides): @@ -552,7 +552,8 @@ def interpolated(self, steps): vertices = simple_linear_interpolation(self.vertices, steps) codes = self.codes if codes is not None: - new_codes = Path.LINETO * np.ones(((len(codes) - 1) * steps + 1, )) + new_codes = np.full((len(codes) - 1) * steps + 1, Path.LINETO, + dtype=self.code_type) new_codes[0::steps] = codes else: new_codes = None @@ -802,7 +803,7 @@ def unit_circle_righthalf(cls): float) - codes = cls.CURVE4 * np.ones(14) + codes = np.full(14, cls.CURVE4, dtype=cls.code_type) codes[0] = cls.MOVETO codes[-1] = cls.CLOSEPOLY @@ -864,7 +865,7 @@ def arc(cls, theta1, theta2, n=None, is_wedge=False): if is_wedge: length = n * 3 + 4 vertices = np.zeros((length, 2), float) - codes = cls.CURVE4 * np.ones((length, ), cls.code_type) + codes = np.full(length, cls.CURVE4, dtype=cls.code_type) vertices[1] = [xA[0], yA[0]] codes[0:2] = [cls.MOVETO, cls.LINETO] codes[-2:] = [cls.LINETO, cls.CLOSEPOLY] @@ -873,7 +874,7 @@ def arc(cls, theta1, theta2, n=None, is_wedge=False): else: length = n * 3 + 1 vertices = np.empty((length, 2), float) - codes = cls.CURVE4 * np.ones((length, ), cls.code_type) + codes = np.full(length, cls.CURVE4, dtype=cls.code_type) vertices[0] = [xA[0], yA[0]] codes[0] = cls.MOVETO vertex_offset = 1 diff --git a/lib/matplotlib/tri/triinterpolate.py b/lib/matplotlib/tri/triinterpolate.py index 070bd85700c9..2e235580508c 100644 --- a/lib/matplotlib/tri/triinterpolate.py +++ b/lib/matplotlib/tri/triinterpolate.py @@ -959,7 +959,7 @@ def get_Kff_and_Ff(self, J, ecc, triangles, Uc): """ ntri = np.size(ecc, 0) vec_range = np.arange(ntri, dtype=np.int32) - c_indices = -np.ones(ntri, dtype=np.int32) # for unused dofs, -1 + c_indices = np.full(ntri, -1, dtype=np.int32) # for unused dofs, -1 f_dof = [1, 2, 4, 5, 7, 8] c_dof = [0, 3, 6] diff --git a/lib/matplotlib/tri/trirefine.py b/lib/matplotlib/tri/trirefine.py index 4f55c1fa94b3..2ca862114731 100644 --- a/lib/matplotlib/tri/trirefine.py +++ b/lib/matplotlib/tri/trirefine.py @@ -111,7 +111,7 @@ def refine_triangulation(self, return_tri_index=False, subdiv=3): # We have to initialize found_index with -1 because some nodes # may very well belong to no triangle at all, e.g., in case of # Delaunay Triangulation with DuplicatePointWarning. - found_index = - np.ones(refi_npts, dtype=np.int32) + found_index = np.full(refi_npts, -1, dtype=np.int32) tri_mask = self._triangulation.mask if tri_mask is None: found_index[refi_triangles] = np.repeat(ancestors, @@ -238,12 +238,8 @@ def _refine_triangulation_once(triangulation, ancestors=None): # (can be -1 if border edge) # For slave and master we will identify the apex pointing to the edge # start - edge_elems = np.ravel(np.vstack([np.arange(ntri, dtype=np.int32), - np.arange(ntri, dtype=np.int32), - np.arange(ntri, dtype=np.int32)])) - edge_apexes = np.ravel(np.vstack([np.zeros(ntri, dtype=np.int32), - np.ones(ntri, dtype=np.int32), - np.ones(ntri, dtype=np.int32)*2])) + edge_elems = np.tile(np.arange(ntri, dtype=np.int32), 3) + edge_apexes = np.repeat(np.arange(3, dtype=np.int32), ntri) edge_neighbors = neighbors[edge_elems, edge_apexes] mask_masters = (edge_elems > edge_neighbors) diff --git a/lib/matplotlib/tri/tritools.py b/lib/matplotlib/tri/tritools.py index 94da837a1f5d..af5f75dbba75 100644 --- a/lib/matplotlib/tri/tritools.py +++ b/lib/matplotlib/tri/tritools.py @@ -292,7 +292,7 @@ def _total_to_compress_renum(mask, n=None): if n is None: n = np.size(mask) if mask is not None: - renum = -np.ones(n, dtype=np.int32) # Default num is -1 + renum = np.full(n, -1, dtype=np.int32) # Default num is -1 valid = np.arange(n, dtype=np.int32).compress(~mask, axis=0) renum[valid] = np.arange(np.size(valid, 0), dtype=np.int32) return renum