8000 Use shorter function names (min, max, abs, conj). · matplotlib/matplotlib@3d00576 · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3d00576

Browse files
committed
Use shorter function names (min, max, abs, conj).
1 parent 1504540 commit 3d00576

20 files changed

+72
-90
lines changed

examples/api/collections_demo.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@
8989

9090
# 7-sided regular polygons
9191

92-
col = collections.RegularPolyCollection(7,
93-
sizes=np.fabs(xx) * 10.0, offsets=xyo,
94-
transOffset=ax3.transData)
92+
col = collections.RegularPolyCollection(
93+
7, sizes=np.abs(xx) * 10.0, offsets=xyo, transOffset=ax3.transData)
9594
trans = transforms.Affine2D().scale(fig.dpi / 72.0)
9695
col.set_transform(trans) # the points to pixels transform
9796
ax3.add_collection(col, autolim=True)
@@ -109,7 +108,7 @@
109108
offs = (0.1, 0.0)
110109

111110
yy = np.linspace(0, 2*np.pi, nverts)
112-
ym = np.amax(yy)
111+
ym = np.max(yy)
113112
xx = (0.2 + (ym - yy)/ym)**2 * np.cos(yy - 0.4)*0.5
114113
segs = []
115114
for i in range(ncurves):

examples/api/sankey_demo_old.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ def sankey(ax,
3737
import matplotlib.patches as mpatches
3838
from matplotlib.path import Path
3939

40-
outs = np.absolute(outputs)
40+
outs = np.abs(outputs)
4141
outsigns = np.sign(outputs)
4242
outsigns[-1] = 0 # Last output
4343

44-
ins = np.absolute(inputs)
44+
ins = np.abs(inputs)
4545
insigns = np.sign(inputs)
4646
insigns[0] = 0 # First input
4747

examples/event_handling/poly_editor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ def get_ind_under_point(self, event):
7070
xy = np.asarray(self.poly.xy)
7171
xyt = self.poly.get_transform().transform(xy)
7272
xt, yt = xyt[:, 0], xyt[:, 1]
73-
d = np.sqrt((xt - event.x)**2 + (yt - event.y)**2)
74-
indseq = np.nonzero(np.equal(d, np.amin(d)))[0]
73+
d = np.hypot(xt - event.x, yt - event.y)
74+
indseq, = np.nonzero(d == d.min())
7575
ind = indseq[0]
7676

7777
if d[ind] >= self.epsilon:

examples/pylab_examples/anscombe.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def fit(x):
2222
return 3 + 0.5*x
2323

2424

25-
xfit = np.array([np.amin(x), np.amax(x)])
25+
xfit = np.array([np.min(x), np.max(x)])
2626

2727
plt.subplot(221)
2828
plt.plot(x, y1, 'ks', xfit, fit(xfit), 'r-', lw=2)
@@ -43,8 +43,7 @@ def fit(x):
4343
plt.setp(plt.gca(), yticks=(4, 8, 12), xticks=(0, 10, 20))
4444

4545
plt.subplot(224)
46-
47-
xfit = np.array([np.amin(x4), np.amax(x4)])
46+
xfit = np.array([np.min(x4), np.max(x4)])
4847
plt.plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2)
4948
plt.axis([2, 20, 2, 14])
5049
plt.setp(plt.gca(), yticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20))

examples/pylab_examples/axes_demo.py

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

1515
# the main axes is subplot(111) by default
1616
plt.plot(t, s)
17-
plt.axis([0, 1, 1.1*np.amin(s), 2*np.amax(s)])
17+
plt.axis([0, 1, 1.1 * np.min(s), 2 * np.max(s)])
1818
plt.xlabel('time (s)')
1919
plt.ylabel('current (nA)')
2020
plt.title('Gaussian colored noise')

examples/pylab_examples/layer_images.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@ def func3(x, y):
2323
# for the images their apparent extent could be different due to
2424
# interpolation edge effects
2525

26-
27-
xmin, xmax, ymin, ymax = np.amin(x), np.amax(x), np.amin(y), np.amax(y)
28-
extent = xmin, xmax, ymin, ymax
26+
extent = np.min(x), np.max(x), np.min(y), np.max(y)
2927
fig = plt.figure(frameon=False)
3028

3129
Z1 = np.add.outer(range(8), range(8)) % 2 # chessboard

examples/pylab_examples/line_collection2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
# We need to set the plot limits, they will not autoscale
1515
ax = plt.axes()
16-
ax.set_xlim((np.amin(x), np.amax(x)))
17-
ax.set_ylim((np.amin(np.amin(ys)), np.amax(np.amax(ys))))
16+
ax.set_xlim(np.min(x), np.max(x))
17+
ax.set_ylim(np.min(ys), np.max(ys))
1818

1919
# colors is sequence of rgba tuples
2020
# linestyle is a string or dash tuple. Legal string values are

examples/pylab_examples/multi_image.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
from matplotlib.pyplot import figure, show, axes, sci
88
from matplotlib import cm, colors
99
from matplotlib.font_manager import FontProperties
10-
from numpy import amin, amax, ravel
11-
from numpy.random import rand
10+
import numpy as np
1211

1312
Nr = 3
1413
Nc = 2
@@ -37,12 +36,12 @@
3736
a.set_xticklabels([])
3837
# Make some fake data with a range that varies
3938
# somewhat from one plot to the next.
40-
data = ((1 + i + j)/10.0)*rand(10, 20)*1e-6
41-
dd = ravel(data)
39+
data = ((1 + i + j) / 10) * np.random.rand(10, 20) * 1e-6
40+
dd = data.ravel()
4241
# Manually find the min and max of all colors for
4342
# use in setting the color scale.
44-
vmin = min(vmin, amin(dd))
45-
vmax = max(vmax, amax(dd))
43+
vmin = min(vmin, np.min(dd))
44+
vmax = max(vmax, np.max(dd))
4645
images.append(a.imshow(data, cmap=cmap))
4746

4847
ax.append(a)
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
Z = (Z - Z.min()) / (Z.max() - Z.min())
2222

2323
# The color array can include masked values:
24-
Zm = ma.masked_where(np.fabs(Qz) < 0.5*np.amax(Qz), Z)
25-
24+
Zm = ma.masked_where(np.abs(Qz) < 0.5 * np.max(Qz), Z)
2625

2726
fig = figure()
2827
ax = fig.add_subplot(121)

examples/pylab_examples/vline_hline_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
def f(t):
1111
s1 = np.sin(2 * np.pi * t)
1212
e1 = np.exp(-t)
13-
return np.absolute((s1 * e1)) + .05
13+
return np.abs(s1 * e1) + .05
1414

1515
t = np.arange(0.0, 5.0, 0.1)
1616
s = f(t)

examples/user_interfaces/embedding_in_wx3.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def init_plot_data(self):
7474
z = np.sin(self.x) + np.cos(self.y)
7575
self.im = a.imshow(z, cmap=cm.RdBu) # , interpolation='nearest')
7676

77-
zmax = np.amax(z) - ERR_TOL
77+
zmax = np.max(z) - ERR_TOL
7878
ymax_i, xmax_i = np.nonzero(z >= zmax)
7979
if self.im.origin == 'upper':
8080
ymax_i = z.shape[0] - ymax_i
@@ -93,7 +93,7 @@ def OnWhiz(self, evt):
9393
z = np.sin(self.x) + np.cos(self.y)
9494
self.im.set_array(z)
9595

96-
zmax = np.amax(z) - ERR_TOL
96+
zmax = np.max(z) - ERR_TOL
9797
ymax_i, xmax_i = np.nonzero(z >= zmax)
9898
if self.im.origin == 'upper':
9999
ymax_i = z.shape[0] - ymax_i

lib/matplotlib/axes/_axes.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,7 +2460,7 @@ def stem(self, *args, **kwargs):
24602460
marker=linemarker, label="_nolegend_")
24612461
stemlines.append(l)
24622462

2463-
baseline, = self.plot([np.amin(x), np.amax(x)], [bottom, bottom],
2463+
baseline, = self.plot([np.min(x), np.max(x)], [bottom, bottom],
24642464
color=basecolor, linestyle=basestyle,
24652465
marker=basemarker, label="_nolegend_")
24662466

@@ -4228,8 +4228,8 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
42284228
if extent is not None:
42294229
xmin, xmax, ymin, ymax = extent
42304230
else:
4231-
xmin, xmax = (np.amin(x), np.amax(x)) if len(x) else (0, 1)
4232-
ymin, ymax = (np.amin(y), np.amax(y)) if len(y) else (0, 1)
4231+
xmin, xmax = (np.min(x), np.max(x)) if len(x) else (0, 1)
4232+
ymin, ymax = (np.min(y), np.max(y)) if len(y) else (0, 1)
42334233

42344234
# to avoid issues with singular data, expand the min/max pairs
42354235
xmin, xmax = mtrans.nonsingular(xmin, xmax, expander=0.1)
@@ -5470,10 +5470,10 @@ def pcolor(self, *args, **kwargs):
54705470

54715471
self.add_collection(collection, autolim=False)
54725472

5473-
minx = np.amin(x)
5474-
maxx = np.amax(x)
5475-
miny = np.amin(y)
5476-
maxy = np.amax(y)
5473+
minx = np.min(x)
5474+
maxx = np.max(x)
5475+
miny = np.min(y)
5476+
maxy = np.max(y)
54775477
collection.sticky_edges.x[:] = [minx, maxx]
54785478
collection.sticky_edges.y[:] = [miny, maxy]
54795479
corners = (minx, miny), (maxx, maxy)
@@ -5622,10 +5622,10 @@ def pcolormesh(self, *args, **kwargs):
56225622

56235623
self.add_collection(collection, autolim=False)
56245624

5625-
minx = np.amin(X)
5626-
maxx = np.amax(X)
5627-
miny = np.amin(Y)
5628-
maxy = np.amax(Y)
5625+
minx = np.min(X)
5626+
maxx = np.max(X)
5627+
miny = np.min(Y)
5628+
maxy = np.max(Y)
56295629
collection.sticky_edges.x[:] = [minx, maxx]
56305630
collection.sticky_edges.y[:] = [miny, maxy]
56315631
corners = (minx, miny), (maxx, maxy)
@@ -6386,7 +6386,7 @@ def _normalize_input(inp, ename='input'):
63866386
else:
63876387
labels = [six.text_type(lab) for lab in label]
63886388

6389-
for (patch, lbl) in zip_longest(patches, labels, fillvalue=None):
6389+
for patch, lbl in zip_longest(patches, labels, fillvalue=None):
63906390
if patch:
63916391
p = patch[0]
63926392
p.update(kwargs)
@@ -6724,7 +6724,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
67246724
# pxy is complex
67256725
freqs += Fc
67266726

6727-
line = self.plot(freqs, 10 * np.log10(np.absolute(pxy)), **kwargs)
6727+
line = self.plot(freqs, 10 * np.log10(np.abs(pxy)), **kwargs)
67286728
self.set_xlabel('Frequency')
67296729
self.set_ylabel('Cross Spectrum Magnitude (dB)')
67306730
self.grid(True)
@@ -7227,7 +7227,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
72277227
Z = np.flipud(Z)
72287228

72297229
if xextent is None:
7230-
xextent = 0, np.amax(t)
7230+
xextent = 0, np.max(t)
72317231
xmin, xmax = xextent
72327232
freqs += Fc
72337233
extent = xmin, xmax, freqs[0], freqs[-1]
@@ -7300,7 +7300,7 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
73007300
marker = 's'
73017301
if marker is None and markersize is None:
73027302
Z = np.asarray(Z)
7303-
mask = np.absolute(Z) > precision
7303+
mask = np.abs(Z) > precision
73047304

73057305
if 'cmap' not in kwargs:
73067306
kwargs['cmap'] = mcolors.ListedColormap(['w', 'k'],
@@ -7316,12 +7316,12 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
73167316
y = c.row
73177317
x = c.col
73187318
else:
7319-
nonzero = np.absolute(c.data) > precision
7319+
nonzero = np.abs(c.data) > precision
73207320
y = c.row[nonzero]
73217321
x = c.col[nonzero]
73227322
else:
73237323
Z = np.asarray(Z)
7324-
nonzero = np.absolute(Z) > precision
7324+
nonzero = np.abs(Z) > precision
73257325
y, x = np.nonzero(nonzero)
73267326
if marker is None:
73277327
marker = 's'

lib/matplotlib/axes/_base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1346,8 +1346,8 @@ def get_data_ratio(self):
13461346
xmin, xmax = self.get_xbound()
13471347
ymin, ymax = self.get_ybound()
13481348

1349-
xsize = max(math.fabs(xmax - xmin), 1e-30)
1350-
ysize = max(math.fabs(ymax - ymin), 1e-30)
1349+
xsize = max(abs(xmax - D7AE xmin), 1e-30)
1350+
ysize = max(abs(ymax - ymin), 1e-30)
13511351

13521352
return ysize / xsize
13531353

@@ -1359,8 +1359,8 @@ def get_data_ratio_log(self):
13591359
xmin, xmax = self.get_xbound()
13601360
ymin, ymax = self.get_ybound()
13611361

1362-
xsize = max(math.fabs(math.log10(xmax) - math.log10(xmin)), 1e-30)
1363-
ysize = max(math.fabs(math.log10(ymax) - math.log10(ymin)), 1e-30)
1362+
xsize = max(abs(math.log10(xmax) - math.log10(xmin)), 1e-30)
1363+
ysize = max(abs(math.log10(ymax) - math.log10(ymin)), 1e-30)
13641364

13651365
return ysize / xsize
13661366

@@ -1432,8 +1432,8 @@ def apply_aspect(self, position=None):
14321432
xmin, xmax = math.log10(xmin), math.log10(xmax)
14331433
ymin, ymax = math.log10(ymin), math.log10(ymax)
14341434

1435-
xsize = max(math.fabs(xmax - xmin), 1e-30)
1436-
ysize = max(math.fabs(ymax - ymin), 1e-30)
1435+
xsize = max(abs(xmax - xmin), 1e-30)
1436+
ysize = max(abs(ymax - ymin), 1e-30)
14371437

14381438
l, b, w, h = position.bounds
14391439
box_aspect = fig_aspect * (h / w)

lib/matplotlib/contour.py

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -226,20 +226,8 @@ def clabel(self, *args, **kwargs):
226226

227227
def print_label(self, linecontour, labelwidth):
228228
"Return *False* if contours are too short for a label."
229-
lcsize = len(linecontour)
230-
if lcsize > 10 * labelwidth:
231-
return True
232-
233-
xmax = np.amax(linecontour[:, 0])
234-
xmin = np.amin(linecontour[:, 0])
235-
ymax = np.amax(linecontour[:, 1])
236-
ymin = np.amin(linecontour[:, 1])
237-
238-
lw = labelwidth
239-
if (xmax - xmin) > 1.2 * lw or (ymax - ymin) > 1.2 * lw:
240-
return True
241-
else:
242-
return False
229+
return (len(linecontour) > 10 * labelwidth
230+
or (np.ptp(linecontour, axis=0) > 1.2 * labelwidth).any())
243231

244232
def too_close(self, x, y, lw):
245233
"Return *True* if a label is already near this location."
@@ -1056,8 +1044,8 @@ def _process_args(self, *args, **kwargs):
10561044
self.levels = args[0]
10571045
self.allsegs = args[1]
10581046
self.allkinds = len(args) > 2 and args[2] or None
1059-
self.zmax = np.amax(self.levels)
1060-
self.zmin = np.amin(self.levels)
1047+
self.zmax = np.max(self.levels)
1048+
self.zmin = np.min(self.levels)
10611049
self._auto = False
10621050

10631051
# Check lengths of levels and allsegs.
@@ -1180,7 +1168,7 @@ def _contour_level_args(self, z, args):
11801168
if self.filled and len(self.levels) < 2:
11811169
raise ValueError("Filled contours require at least 2 levels.")
11821170

1183-
if len(self.levels) > 1 and np.amin(np.diff(self.levels)) <= 0.0:
1171+
if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0:
11841172
if hasattr(self, '_corner_mask') and self._corner_mask == 'legacy':
11851173
warnings.warn("Contour levels are not increasing")
11861174
else:
@@ -1210,8 +1198,8 @@ def _process_levels(self):
12101198
with line contours.
12111199
"""
12121200
# following are deprecated and will be removed in 2.2
1213-
self._vmin = np.amin(self.levels)
1214-
self._vmax = np.amax(self.levels)
1201+
self._vmin = np.min(self.levels)
1202+
self._vmax = np.max(self.levels)
12151203

12161204
# Make a private _levels to include extended regions; we
12171205
# want to leave the original levels attribute unchanged.

lib/matplotlib/legend_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ def create_artists(self, legend, orig_handle,
551551
for lm, m in zip(leg_stemlines, stemlines):
552552
self.update_prop(lm, m, legend)
553553

554-
leg_baseline = Line2D([np.amin(xdata), np.amax(xdata)],
554+
leg_baseline = Line2D([np.min(xdata), np.max(xdata)],
555555
[bottom, bottom])
556556

557557
self.update_prop(leg_baseline, baseline, legend)

0 commit comments

Comments
 (0)
0