Skip to content

Commit 7353ad9

Browse files
authored
Merge pull request #15679 from anntzer/concat
np.concatenate cleanups.
2 parents e3446cb + 67dea11 commit 7353ad9

File tree

6 files changed

+21
-43
lines changed

6 files changed

+21
-43
lines changed

examples/specialty_plots/radar_chart.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ def _close_line(self, line):
6666
x, y = line.get_data()
6767
# FIXME: markers at x[0], y[0] get doubled-up
6868
if x[0] != x[-1]:
69-
x = np.concatenate((x, [x[0]]))
70-
y = np.concatenate((y, [y[0]]))
69+
x = np.append(x, x[0])
70+
y = np.append(y, y[0])
7171
line.set_data(x, y)
7272

7373
def set_varlabels(self, labels):

lib/matplotlib/bezier.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -237,16 +237,14 @@ def split_path_inout(path, inside, tolerance=0.01, reorder_inout=False):
237237

238238
ctl_points_old = ctl_points
239239

240-
concat = np.concatenate
241-
242240
iold = 0
243241
i = 1
244242

245243
for ctl_points, command in path_iter:
246244
iold = i
247245
i += len(ctl_points) // 2
248246
if inside(ctl_points[-2:]) != begin_inside:
249-
bezier_path = concat([ctl_points_old[-2:], ctl_points])
247+
bezier_path = np.concatenate([ctl_points_old[-2:], ctl_points])
250248
break
251249
ctl_points_old = ctl_points
252250
else:
@@ -271,15 +269,15 @@ def split_path_inout(path, inside, tolerance=0.01, reorder_inout=False):
271269
verts_right = right[:]
272270

273271
if path.codes is None:
274-
path_in = Path(concat([path.vertices[:i], verts_left]))
275-
path_out = Path(concat([verts_right, path.vertices[i:]]))
272+
path_in = Path(np.concatenate([path.vertices[:i], verts_left]))
273+
path_out = Path(np.concatenate([verts_right, path.vertices[i:]]))
276274

277275
else:
278-
path_in = Path(concat([path.vertices[:iold], verts_left]),
279-
concat([path.codes[:iold], codes_left]))
276+
path_in = Path(np.concatenate([path.vertices[:iold], verts_left]),
277+
np.concatenate([path.codes[:iold], codes_left]))
280278

281-
path_out = Path(concat([verts_right, path.vertices[i:]]),
282-
concat([codes_right, path.codes[i:]]))
279+
path_out = Path(np.concatenate([verts_right, path.vertices[i:]]),
280+
np.concatenate([codes_right, path.codes[i:]]))
283281

284282
if reorder_inout and not begin_inside:
285283
path_in, path_out = path_out, path_in

lib/matplotlib/mlab.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,8 @@ def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,
548548

549549
if sides == 'twosided':
550550
# center the frequency range at zero
551-
freqs = np.concatenate((freqs[freqcenter:], freqs[:freqcenter]))
552-
result = np.concatenate((result[freqcenter:, :],
553-
result[:freqcenter, :]), 0)
551+
freqs = np.roll(freqs, -freqcenter, axis=0)
552+
result = np.roll(result, -freqcenter, axis=0)
554553
elif not pad_to % 2:
555554
# get the last value correctly, it is negative otherwise
556555
freqs[-1] *= -1

lib/matplotlib/patches.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2332,8 +2332,7 @@ def transmute(self, x0, y0, width, height, mutation_size):
23322332
width, height,
23332333
mutation_size)
23342334
# Add a trailing vertex to allow us to close the polygon correctly
2335-
saw_vertices = np.concatenate([np.array(saw_vertices),
2336-
[saw_vertices[0]]], axis=0)
2335+
saw_vertices = np.concatenate([saw_vertices, [saw_vertices[0]]])
23372336
codes = ([Path.MOVETO] +
23382337
[Path.CURVE3, Path.CURVE3] * ((len(saw_vertices)-1)//2) +
23392338
[Path.CLOSEPOLY])

lib/matplotlib/tests/test_ticker.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,9 +358,7 @@ def test_minor(self, lims, expected_low_ticks):
358358
else:
359359
# subsample
360360
_LogitHelper.assert_almost_equal(
361-
np.sort(np.concatenate((major_ticks, minor_ticks))),
362-
expected_ticks,
363-
)
361+
sorted([*major_ticks, *minor_ticks]), expected_ticks)
364362

365363
def test_minor_attr(self):
366364
loc = mticker.LogitLocator(nbins=100)

lib/mpl_toolkits/axisartist/angle_helper.py

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,11 @@ def select_step_degree(dv):
2020
second_limits_ = np.array(minsec_limits_) / 3600
2121
second_factors = [3600.] * len(second_limits_)
2222

23-
degree_limits = np.concatenate([second_limits_,
24-
minute_limits_,
25-
degree_limits_])
23+
degree_limits = [*second_limits_, *minute_limits_, *degree_limits_]
24+
degree_steps = [*minsec_steps_, *minsec_steps_, *degree_steps_]
25+
degree_factors = [*second_factors, *minute_factors, *degree_factors]
2626

27-
degree_steps = np.concatenate([minsec_steps_,
28-
minsec_steps_,
29-
degree_steps_])
30-
31-
degree_factors = np.concatenate([second_factors,
32-
minute_factors,
33-
degree_factors])
34-
35-
n = degree_limits.searchsorted(dv)
27+
n = np.searchsorted(degree_limits, dv)
3628
step = degree_steps[n]
3729
factor = degree_factors[n]
3830

@@ -54,19 +46,11 @@ def select_step_hour(dv):
5446
second_limits_ = np.array(minsec_limits_) / 3600
5547
second_factors = [3600.] * len(second_limits_)
5648

57-
hour_limits = np.concatenate([second_limits_,
58-
minute_limits_,
59-
hour_limits_])
60-
61-
hour_steps = np.concatenate([minsec_steps_,
62-
minsec_steps_,
63-
hour_steps_])
64-
65-
hour_factors = np.concatenate([second_factors,
66-
minute_factors,
67-
hour_factors])
49+
hour_limits = [*second_limits_, *minute_limits_, *hour_limits_]
50+
hour_steps = [*minsec_steps_, *minsec_steps_, *hour_steps_]
51+
hour_factors = [*second_factors, *minute_factors, *hour_factors]
6852

69-
n = hour_limits.searchsorted(dv)
53+
n = np.searchsorted(hour_limits, dv)
7054
step = hour_steps[n]
7155
factor = hour_factors[n]
7256

0 commit comments

Comments
 (0)