8000 Merge pull request #7547 from anntzer/additional-cleanups · matplotlib/matplotlib@409d8b7 · GitHub
[go: up one dir, main page]

Skip to content

Commit 409d8b7

Browse files
authored
Merge pull request #7547 from anntzer/additional-cleanups
Additional cleanups
2 parents 3612616 + f1b25e6 commit 409d8b7

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+271
-406
lines changed

boilerplate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ def format_value(value):
317317
# A gensym-like facility in case some function takes an
318318
# argument named washold, ax, or ret
319319
washold, ret, ax = 'washold', 'ret', 'ax'
320-
bad = set(args) | set((varargs, varkw))
320+
bad = set(args) | {varargs, varkw}
321321
while washold in bad or ret in bad or ax in bad:
322322
washold = 'washold' + str(random.randrange(10 ** 12))
323323
ret = 'ret' + str(random.randrange(10 ** 12))

doc/sphinxext/gen_gallery.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,10 @@ def gen_gallery(app, doctree):
7676
# images we want to skip for the gallery because they are an unusual
7777
# size that doesn't layout well in a table, or because they may be
7878
# redundant with other images or uninteresting
79-
skips = set([
80-
'mathtext_examples',
81-
'matshow_02',
82-
'matshow_03',
83-
'matplotlib_icon',
84-
])
79+
skips = {'mathtext_examples',
80+
'matshow_02',
81+
'matshow_03',
82+
'matplotlib_icon'}
8583

8684
thumbnails = {}
8785
rows = []

doc/utils/pylab_names.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,13 @@
4646

4747
print()
4848
funcs, docs = zip(*modd[mod])
49-
maxfunc = max([len(f) for f in funcs])
50-
maxdoc = max(40, max([len(d) for d in docs]) )
51-
border = ' '.join(['='*maxfunc, '='*maxdoc])
49+
maxfunc = max(len(f) for f in funcs)
50+
maxdoc = max(40, max(len(d) for d in docs))
51+
border = '=' * maxfunc + ' ' + '=' * maxdoc
5252
print(border)
53-
print(' '.join(['symbol'.ljust(maxfunc), 'description'.ljust(maxdoc)]))
53+
print('{:<{}} {:<{}}'.format('symbol', maxfunc, 'description', maxdoc))
5454
print(border)
5555
for func, doc in modd[mod]:
56-
row = ' '.join([func.ljust(maxfunc), doc.ljust(maxfunc)])
57-
print(row)
58-
56+
print('{:<{}} {:<{}}'.format(func, maxfunc, doc, maxdoc))
5957
print(border)
6058
print()
61-
#break

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/axes_grid1/scatter_hist.py

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

3131
# now determine nice limits by hand:
3232
binwidth = 0.25
33-
xymax = np.max([np.max(np.fabs(x)), np.max(np.fabs(y))])
33+
xymax = max(np.max(np.abs(x)), np.max(np.abs(y)))
3434
lim = (int(xymax/binwidth) + 1)*binwidth
3535

3636
bins = np.arange(-lim, lim + binwidth, binwidth)

examples/axes_grid1/simple_axesgrid.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@
22
from mpl_toolkits.axes_grid1 import ImageGrid
33
import numpy as np
44

5-
im = np.arange(100)
6-
im.shape = 10, 10
5+
im = np.arange(100).reshape((10, 10))
76

87
fig = plt.figure(1, (4., 4.))
98
grid = ImageGrid(fig, 111, # similar to subplot(111)

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/agg_buffer.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
l, b, w, h = agg.figure.bbox.bounds
2727
w, h = int(w), int(h)
2828

29-
X = np.fromstring(s, np.uint8)
30-
X.shape = h, w, 3
29+
X = np.fromstring(s, np.uint8).reshape((h, w, 3))
3130

3231
try:
3332
im = Image.fromstring("RGB", (w, h), s)

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/arrow_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
rates_to_bases = {'r1': 'AT', 'r2': 'TA', 'r3': 'GA', 'r4': 'AG', 'r5': 'CA',
1515
'r6': 'AC', 'r7': 'GT', 'r8': 'TG', 'r9': 'CT', 'r10': 'TC',
1616
'r11': 'GC', 'r12': 'CG'}
17-
numbered_bases_to_rates = dict([(v, k) for k, v in rates_to_bases.items()])
18-
lettered_bases_to_rates = dict([(v, 'r' + v) for k, v in rates_to_bases.items()])
17+
numbered_bases_to_rates = {v: k for k, v in rates_to_bases.items()}
18+
lettered_bases_to_rates = {v: 'r' + v for k, v in rates_to_bases.items()}
1919

2020

2121
def add_dicts(d1, d2):

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/barcode_demo.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,12 @@
1414
fig = plt.figure()
1515

1616
# a vertical barcode -- this is broken at present
17-
x.shape = len(x), 1
1817
ax = fig.add_axes([0.1, 0.3, 0.1, 0.6], **axprops)
19-
ax.imshow(x, **barprops)
18+
ax.imshow(x.reshape((-1, 1)), **barprops)
2019

21-
x = x.copy()
2220
# a horizontal barcode
23-
x.shape = 1, len(x)
2421
ax = fig.add_axes([0.3, 0.1, 0.6, 0.1], **axprops)
25-
ax.imshow(x, **barprops)
22+
ax.imshow(x.reshape((1, -1)), **barprops)
2623

2724

2825
plt.show()

examples/pylab_examples/figimage_demo.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99

1010

1111
fig = plt.figure()
12-
Z = np.arange(10000.0)
13-
Z.shape = 100, 100
14-
Z[:, 50:] = 1.
12+
Z = np.arange(10000).reshape((100, 100))
13+
Z[:, 50:] = 1
1514

16-
im1 = plt.figimage(Z, xo=50, yo=0, origin='lower')
17-
im2 = plt.figimage(Z, xo=100, yo=100, alpha=.8, origin='lower')
15+
im1 = fig.figimage(Z, xo=50, yo=0, origin='lower')
16+
im2 = fig.figimage(Z, xo=100, yo=100, alpha=.8, origin='lower')
1817

1918
plt.show()

examples/pylab_examples/image_demo2.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@
77

88
datafile = cbook.get_sample_data('ct.raw.gz', asfileobj=True)
99
s = datafile.read()
10-
A = np.fromstring(s, np.uint16).astype(float)
11-
A *= 1.0 / max(A)
12-
A.shape = w, h
10+
A = np.fromstring(s, np.uint16).astype(float).reshape((w, h))
11+
A /= A.max()
1312

1413
extent = (0, 25, 0, 25)
1514
im = plt.imshow(A, cmap=plt.cm.hot, origin='upper', extent=extent)

examples/pylab_examples/image_origin.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@
77
import matplotlib.pyplot as plt
88
import numpy as np
99

10-
x = np.arange(120)
11-
x.shape = (10, 12)
10+
x = np.arange(120).reshape((10, 12))
1211

1312
interp = 'bilinear'
1413
fig, axs = plt.subplots(nrows=2, sharex=True, figsize=(3, 5))

examples/pylab_examples/layer_images.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@ 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

31-
Z1 = np.array(([0, 1]*4 + [1, 0]*4)*4)
32-
Z1.shape = (8, 8) # chessboard
29+
Z1 = np.add.outer(range(8), range(8)) % 2 # chessboard
3330
im1 = plt.imshow(Z1, cmap=plt.cm.gray, interpolation='nearest',
3431
extent=extent)
3532

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/mri_demo.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99

1010
# Data are 256x256 16 bit integers
1111
dfile = cbook.get_sample_data('s1045.ima.gz')
12-
im = np.fromstring(dfile.read(), np.uint16).astype(float)
13-
im.shape = (256, 256)
12+
im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256))
1413
dfile.close()
1514

1615
ax.imshow(im, cmap=cm.gray)

examples/pylab_examples/mri_with_eeg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717
# Load the MRI data (256x256 16 bit integers)
1818
dfile = cbook.get_sample_data('s1045.ima.gz')
19-
im = np.fromstring(dfile.read(), np.uint16).astype(float)
20-
im.shape = (256, 256)
19+
im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256))
2120
dfile.close()
2221

2322
# Plot the MRI image

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/scatter_hist.py

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

3838
# now determine nice limits by hand:
3939
binwidth = 0.25
40-
xymax = np.max([np.max(np.fabs(x)), np.max(np.fabs(y))])
40+
xymax = max(np.max(np.abs(x)), np.max(np.abs(y)))
4141
lim = (int(xymax/binwidth) + 1) * binwidth
4242

4343
axScatter.set_xlim((-lim, lim))

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/tests/backend_driver.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,14 +321,13 @@ def report_missing(dir, flist):
321321
globstr = os.path.join(dir, '*.py')
322322
fnames = glob.glob(globstr)
323323

324-
pyfiles = set([os.path.split(fullpath)[-1] for fullpath in set(fnames)])
324+
pyfiles = {os.path.split(fullpath)[-1] for fullpath in set(fnames)}
325325

326326
exclude = set(excluded.get(dir, []))
327327
flist = set(flist)
328328
missing = list(pyfiles - flist - exclude)
329-
missing.sort()
330329
if missing:
331-
print('%s files not tested: %s' % (dir, ', '.join(missing)))
330+
print('%s files not tested: %s' % (dir, ', '.join(sorted(missing))))
332331

333332

334333
def report_all_missing(directories):

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

examples/user_interfaces/histogram_demo_canvasagg.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@
4848

4949
if 0:
5050
# convert to a numpy array
51-
X = numpy.fromstring(s, numpy.uint8)
52-
X.shape = h, w, 3
51+
X = numpy.fromstring(s, numpy.uint8).reshape((h, w, 3))
5352

5453
if 0:
5554
# pass off to PIL

examples/widgets/menu.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ def __init__(self, fig, menuitems):
126126
self.menuitems = menuitems
127127
self.numitems = len(menuitems)
128128

129-
maxw = max([item.labelwidth for item in menuitems])
130-
maxh = max([item.labelheight for item in menuitems])
129+
maxw = max(item.labelwidth for item in menuitems)
130+
maxh = max(item.labelheight for item in menuitems)
131131

132132
totalh = self.numitems*maxh + (self.numitems + 1)*2*MenuItem.pady
133133

lib/matplotlib/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ class Verbose(object):
263263
instance to handle the output. Default is sys.stdout
264264
"""
265265
levels = ('silent', 'helpful', 'debug', 'debug-annoying')
266-
vald = dict([(level, i) for i, level in enumerate(levels)])
266+
vald = {level: i for i, level in enumerate(levels)}
267267

268268
# parse the verbosity from the command line; flags look like
269269
# --verbose-silent or --verbose-helpful
@@ -860,10 +860,10 @@ def matplotlib_fname():
860860
_deprecated_ignore_map = {
861861
}
862862

863-
_obsolete_set = set(['tk.pythoninspect', 'legend.isaxes'])
863+
_obsolete_set = {'tk.pythoninspect', 'legend.isaxes'}
864864

865865
# The following may use a value of None to suppress the warning.
866-
_deprecated_set = set(['axes.hold']) # do NOT include in _all_deprecated
866+
_deprecated_set = {'axes.hold'} # do NOT include in _all_deprecated
867867

868868
_all_deprecated = set(chain(_deprecated_ignore_map,
869869
_deprecated_map,

0 commit comments

Comments
 (0)
0