Skip to content

Commit 75512c5

Browse files
committed
Use np.full{,_like} where appropriate.
1 parent 9b48fd8 commit 75512c5

25 files changed

+45
-51
lines changed

examples/animation/animated_histogram.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
# in the ``verts`` array to keep the codes aligned with the vertices.
4646
nverts = nrects * (1 + 3 + 1)
4747
verts = np.zeros((nverts, 2))
48-
codes = np.ones(nverts, int) * path.Path.LINETO
48+
codes = np.full(nverts, path.Path.LINETO)
4949
codes[0::5] = path.Path.MOVETO
5050
codes[4::5] = path.Path.CLOSEPOLY
5151
verts[0::5, 0] = left

examples/api/donut.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def make_circle(r):
3232

3333
inside_vertices = make_circle(0.5)
3434
outside_vertices = make_circle(1.0)
35-
codes = np.ones(
36-
len(inside_vertices), dtype=mpath.Path.code_type) * mpath.Path.LINETO
35+
codes = np.full(len(inside_vertices), mpath.Path.LINETO)
3736
codes[0] = mpath.Path.MOVETO
3837

3938
for i, (inside, outside) in enumerate(((1, 1), (1, -1), (-1, 1), (-1, -1))):

examples/api/filled_step.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def filled_hist(ax, edges, values, bottoms=None, orientation='v',
6363
if bottoms is None:
6464
bottoms = np.zeros_like(values)
6565
if np.isscalar(bottoms):
66-
bottoms = np.ones_like(values) * bottoms
66+
bottoms = np.full_like(values, bottoms)
6767

6868
values = np.r_[values, values[-1]]
6969
bottoms = np.r_[bottoms, bottoms[-1]]

examples/mplot3d/hist3d.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@
2929
zpos = np.zeros_like(xpos)
3030

3131
# Construct arrays with the dimensions for the 16 bars.
32-
dx = 0.5 * np.ones_like(zpos)
33-
dy = dx.copy()
32+
dx = dy = np.full_like(zpos, .5)
3433
dz = hist.flatten()
3534

3635
ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b', zsort='average')

examples/pyplots/boxplot_demo_pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
# fake up some data
1616
spread = np.random.rand(50) * 100
17-
center = np.ones(25) * 50
17+
center = np.full(25, 50)
1818
flier_high = np.random.rand(10) * 100 + 100
1919
flier_low = np.random.rand(10) * -100
2020
data = np.concatenate((spread, center, flier_high, flier_low), 0)
@@ -61,7 +61,7 @@
6161
# Fake up some more data
6262

6363
spread = np.random.rand(50) * 100
64-
center = np.ones(25) * 40
64+
center = np.full(25, 40)
6565
flier_high = np.random.rand(10) * 100 + 100
6666
flier_low = np.random.rand(10) * -100
6767
d2 = np.concatenate((spread, center, flier_high, flier_low), 0)

examples/pyplots/compound_path_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929

3030
nverts = nrects*(1+3+1)
3131
verts = np.zeros((nverts, 2))
32-
codes = np.ones(nverts, int) * path.Path.LINETO
32+
codes = np.full(nverts, path.Path.LINETO)
3333
codes[0::5] = path.Path.MOVETO
3434
codes[4::5] = path.Path.CLOSEPOLY
3535
verts[0::5,0] = left

examples/specialty_plots/leftventricle_bulleye.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def bullseye_plot(ax, data, segBold=None, cmap=None, norm=None):
7878
# First segment start at 60 degrees
7979
theta0 = theta[i * 128:i * 128 + 128] + np.deg2rad(60)
8080
theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1)
81-
z = np.ones((128, 2)) * data[i]
81+
z = np.full((128, 2), data[i])
8282
ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm)
8383
if i + 1 in segBold:
8484
ax.plot(theta0, r0, '-k', lw=linewidth + 2)
@@ -92,7 +92,7 @@ def bullseye_plot(ax, data, segBold=None, cmap=None, norm=None):
9292
# First segment start at 60 degrees
9393
theta0 = theta[i * 128:i * 128 + 128] + np.deg2rad(60)
9494
theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1)
95-
z = np.ones((128, 2)) * data[i + 6]
95+
z = np.full((128, 2), data[i + 6])
9696
ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm)
9797
if i + 7 in segBold:
9898
ax.plot(theta0, r0, '-k', lw=linewidth + 2)
@@ -106,7 +106,7 @@ def bullseye_plot(ax, data, segBold=None, cmap=None, norm=None):
106106
# First segment start at 45 degrees
107107
theta0 = theta[i * 192:i * 192 + 192] + np.deg2rad(45)
108108
theta0 = np.repeat(theta0[:, np.newaxis], 2, axis=1)
109-
z = np.ones((192, 2)) * data[i + 12]
109+
z = np.full((192, 2), data[i + 12])
110110
ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm)
111111
if i + 13 in segBold:
112112
ax.plot(theta0, r0, '-k', lw=linewidth + 2)
@@ -118,7 +118,7 @@ def bullseye_plot(ax, data, segBold=None, cmap=None, norm=None):
118118
r0 = np.array([0, r[0]])
119119
r0 = np.repeat(r0[:, np.newaxis], theta.size, axis=1).T
120120
theta0 = np.repeat(theta[:, np.newaxis], 2, axis=1)
121-
z = np.ones((theta.size, 2)) * data[16]
121+
z = np.full((theta.size, 2), data[16])
122122
ax.pcolormesh(theta0, r0, z, cmap=cmap, norm=norm)
123123
if 17 in segBold:
124124
ax.plot(theta0, r0, '-k', lw=linewidth + 2)

examples/statistics/boxplot_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
# fake up some data
2222
spread = np.random.rand(50) * 100
23-
center = np.ones(25) * 50
23+
center = np.full(25, 50)
2424
flier_high = np.random.rand(10) * 100 + 100
2525
flier_low = np.random.rand(10) * -100
2626
data = np.concatenate((spread, center, flier_high, flier_low), 0)
@@ -56,7 +56,7 @@
5656

5757
# fake up some more data
5858
spread = np.random.rand(50) * 100
59-
center = np.ones(25) * 40
59+
center = np.full(25, 40)
6060
flier_high = np.random.rand(10) * 100 + 100
6161
flier_low = np.random.rand(10) * -100
6262
d2 = np.concatenate((spread, center, flier_high, flier_low), 0)

examples/text_labels_and_annotations/legend_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def create_artists(self, legend, orig_handle,
135135
leglines = []
136136
# divide the vertical space where the lines will go
137137
# into equal parts based on the number of lines
138-
ydata = ((height) / (numlines + 1)) * np.ones(xdata.shape, float)
138+
ydata = np.full_like(xdata, height / (numlines + 1))
139139
# for each line, create the line at the proper location
140140
# and set the dash pattern
141141
for i in range(numlines):

lib/matplotlib/axes/_axes.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3958,16 +3958,16 @@ def dopatch(xs, ys, **kwargs):
39583958
datalabels.append(stats.get('label', pos))
39593959

39603960
# whisker coords
3961-
whisker_x = np.ones(2) * pos
3961+
whisker_x = np.full(2, pos)
39623962
whiskerlo_y = np.array([stats['q1'], stats['whislo']])
39633963
whiskerhi_y = np.array([stats['q3'], stats['whishi']])
39643964

39653965
# cap coords
39663966
cap_left = pos - width * 0.25
39673967
cap_right = pos + width * 0.25
39683968
cap_x = np.array([cap_left, cap_right])
3969-
cap_lo = np.ones(2) * stats['whislo']
3970-
cap_hi = np.ones(2) * stats['whishi']
3969+
cap_lo = np.full(2, stats['whislo'])
3970+
cap_hi = np.full(2, stats['whishi'])
39713971

39723972
# box and median coords
39733973
box_left = pos - width * 0.5
@@ -4030,7 +4030,7 @@ def dopatch(xs, ys, **kwargs):
40304030
# maybe draw the fliers
40314031
if showfliers:
40324032
# fliers coords
4033-
flier_x = np.ones(len(stats['fliers'])) * pos
4033+
flier_x = np.full(len(stats['fliers']), pos)
40344034
flier_y = stats['fliers']
40354035

40364036
fliers.extend(doplot(

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy