Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6acf838

Browse files
committed
Use shorter function names (min, max, abs, conj).
1 parent 5a551cf commit 6acf838

20 files changed

+73
-91
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)

examples/pylab_examples/quadmesh_demo.py

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: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2465,7 +2465,7 @@ def stem(self, *args, **kwargs):
24652465
marker=linemarker, label="_nolegend_")
24662466
stemlines.append(l)
24672467

2468-
baseline, = self.plot([np.amin(x), np.amax(x)], [bottom, bottom],
2468+
baseline, = self.plot([np.min(x), np.max(x)], [bottom, bottom],
24692469
color=basecolor, linestyle=basestyle,
24702470
marker=basemarker, label="_nolegend_")
24712471

@@ -4233,8 +4233,8 @@ def hexbin(self, x, y, C=None, gridsize=100, bins=None,
42334233
if extent is not None:
42344234
xmin, xmax, ymin, ymax = extent
42354235
else:
4236-
xmin, xmax = (np.amin(x), np.amax(x)) if len(x) else (0, 1)
4237-
ymin, ymax = (np.amin(y), np.amax(y)) if len(y) else (0, 1)
4236+
xmin, xmax = (np.min(x), np.max(x)) if len(x) else (0, 1)
4237+
ymin, ymax = (np.min(y), np.max(y)) if len(y) else (0, 1)
42384238

42394239
# to avoid issues with singular data, expand the min/max pairs
42404240
xmin, xmax = mtrans.nonsingular(xmin, xmax, expander=0.1)
@@ -5471,10 +5471,10 @@ def pcolor(self, *args, **kwargs):
54715471
x = transformed_pts[..., 0]
54725472
y = transformed_pts[..., 1]
54735473

5474-
minx = np.amin(x)
5475-
maxx = np.amax(x)
5476-
miny = np.amin(y)
5477-
maxy = np.amax(y)
5474+
minx = np.min(x)
5475+
maxx = np.max(x)
5476+
miny = np.min(y)
5477+
maxy = np.max(y)
54785478

54795479
corners = (minx, miny), (maxx, maxy)
54805480
self.add_collection(collection, autolim=False)
@@ -5622,10 +5622,10 @@ def pcolormesh(self, *args, **kwargs):
56225622
X = transformed_pts[..., 0]
56235623
Y = transformed_pts[..., 1]
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

56305630
corners = (minx, miny), (maxx, maxy)
56315631
self.add_collection(collection, autolim=False)
@@ -6388,7 +6388,7 @@ def _normalize_input(inp, ename='input'):
63886388
# make sure there are counts
63896389
if np.sum(m) > 0:
63906390
# filter out the 0 height bins
6391-
xmin = np.amin(m[m != 0])
6391+
xmin = np.min(m[m != 0])
63926392
# If no counts, set min to zero
63936393
else:
63946394
xmin = 0.0
@@ -6403,7 +6403,7 @@ def _normalize_input(inp, ename='input'):
64036403
# make sure there are counts
64046404
if np.sum(m) > 0:
64056405
# filter out the 0 height bins
6406-
ymin = np.amin(m[m != 0])
6406+
ymin = np.min(m[m != 0])
64076407
# If no counts, set min to zero
64086408
else:
64096409
ymin = 0.0
@@ -6764,7 +6764,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
67646764
# pxy is complex
67656765
freqs += Fc
67666766

6767-
line = self.plot(freqs, 10 * np.log10(np.absolute(pxy)), **kwargs)
6767+
line = self.plot(freqs, 10 * np.log10(np.abs(pxy)), **kwargs)
67686768
self.set_xlabel('Frequency')
67696769
self.set_ylabel('Cross Spectrum Magnitude (dB)')
67706770
self.grid(True)
@@ -7267,7 +7267,7 @@ def specgram(self, x, NFFT=None, Fs=None, Fc=None, detrend=None,
72677267
Z = np.flipud(Z)
72687268

72697269
if xextent is None:
7270-
xextent = 0, np.amax(t)
7270+
xextent = 0, np.max(t)
72717271
xmin, xmax = xextent
72727272
freqs += Fc
72737273
extent = xmin, xmax, freqs[0], freqs[-1]
@@ -7340,7 +7340,7 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
73407340
marker = 's'
73417341
if marker is None and markersize is None:
73427342
Z = np.asarray(Z)
7343-
mask = np.absolute(Z) > precision
7343+
mask = np.abs(Z) > precision
73447344

73457345
if 'cmap' not in kwargs:
73467346
kwargs['cmap'] = mcolors.ListedColormap(['w', 'k'],
@@ -7356,12 +7356,12 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
73567356
y = c.row
73577357
x = c.col
73587358
else:
7359-
nonzero = np.absolute(c.data) > precision
7359+
nonzero = np.abs(c.data) > precision
73607360
y = c.row[nonzero]
73617361
x = c.col[nonzero]
73627362
else:
73637363
Z = np.asarray(Z)
7364-
nonzero = np.absolute(Z) > precision
7364+
nonzero = np.abs(Z) > precision
73657365
y, x = np.nonzero(nonzero)
73667366
if marker is None:
73677367
marker = 's'

lib/matplotlib/axes/_base.py

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

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

13511351
return ysize / xsize
13521352

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

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

13641364
return ysize / xsize
13651365

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

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

14371437
l, b, w, h = position.bounds
14381438
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."
@@ -1050,8 +1038,8 @@ def _process_args(self, *args, **kwargs):
10501038
self.levels = args[0]
10511039
self.allsegs = args[1]
10521040
self.allkinds = len(args) > 2 and args[2] or None
1053-
self.zmax = np.amax(self.levels)
1054-
self.zmin = np.amin(self.levels)
1041+
self.zmax = np.max(self.levels)
1042+
self.zmin = np.min(self.levels)
10551043
self._auto = False
10561044

10571045
# Check lengths of levels and allsegs.
@@ -1185,7 +1173,7 @@ def _contour_level_args(self, z, args):
11851173
if self.filled and len(self.levels) < 2:
11861174
raise ValueError("Filled contours require at least 2 levels.")
11871175

1188-
if len(self.levels) > 1 and np.amin(np.diff(self.levels)) <= 0.0:
1176+
if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0:
11891177
if hasattr(self, '_corner_mask') and self._corner_mask == 'legacy':
11901178
warnings.warn("Contour levels are not increasing")
11911179
else:
@@ -1215,8 +1203,8 @@ def _process_levels(self):
12151203
with line contours.
12161204
"""
12171205
# following are deprecated and will be removed in 2.2
1218-
self._vmin = np.amin(self.levels)
1219-
self._vmax = np.amax(self.levels)
1206+
self._vmin = np.min(self.levels)
1207+
self._vmax = np.max(self.levels)
12201208

12211209
# Make a private _levels to include extended regions; we
12221210
# 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)