8000 Additional cleanups by anntzer · Pull Request #7547 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Additional cleanups #7547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 5, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion boilerplate.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def format_value(value):
# A gensym-like facility in case some function takes an
# argument named washold, ax, or ret
washold, ret, ax = 'washold', 'ret', 'ax'
bad = set(args) | set((varargs, varkw))
bad = set(args) | {varargs, varkw}
while washold in bad or ret in bad or ax in bad:
washold = 'washold' + str(random.randrange(10 ** 12))
ret = 'ret' + str(random.randrange(10 ** 12))
Expand Down
10 changes: 4 additions & 6 deletions doc/sphinxext/gen_gallery.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,10 @@ def gen_gallery(app, doctree):
# images we want to skip for the gallery because they are an unusual
# size that doesn't layout well in a table, or because they may be
# redundant with other images or uninteresting
skips = set([
'mathtext_examples',
'matshow_02',
'matshow_03',
'matplotlib_icon',
])
skips = {'mathtext_examples',
'matshow_02',
'matshow_03',
'matplotlib_icon'}

thumbnails = {}
rows = []
Expand Down
13 changes: 5 additions & 8 deletions doc/utils/pylab_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,13 @@

print()
funcs, docs = zip(*modd[mod])
maxfunc = max([len(f) for f in funcs])
maxdoc = max(40, max([len(d) for d in docs]) )
border = ' '.join(['='*maxfunc, '='*maxdoc])
maxfunc = max(len(f) for f in funcs)
maxdoc = max(40, max(len(d) for d in docs))
border = '=' * maxfunc + ' ' + '=' * maxdoc
print(border)
print(' '.join(['symbol'.ljust(maxfunc), 'description'.ljust(maxdoc)]))
print('{:<{}} {:<{}}'.format('symbol', maxfunc, 'description', maxdoc))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

print inserts a space, so print('symbol.ljust(maxfunc), 'description'.ljust(maxdoc)) would have worked, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes but that looks a bit "unintended" to me.

print(border)
for func, doc in modd[mod]:
row = ' '.join([func.ljust(maxfunc), doc.ljust(maxfunc)])
print(row)

print('{:<{}} {:<{}}'.format(func, maxfunc, doc, maxdoc))
print(border)
print()
#break
7 changes: 3 additions & 4 deletions examples/api/collections_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,8 @@

# 7-sided regular polygons

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

yy = np.linspace(0, 2*np.pi, nverts)
ym = np.amax(yy)
ym = np.max(yy)
xx = (0.2 + (ym - yy)/ym)**2 * np.cos(yy - 0.4)*0.5
segs = []
for i in range(ncurves):
Expand Down
4 changes: 2 additions & 2 deletions examples/api/sankey_demo_old.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ def sankey(ax,
import matplotlib.patches as mpatches
from matplotlib.path import Path

outs = np.absolute(outputs)
outs = np.abs(outputs)
outsigns = np.sign(outputs)
outsigns[-1] = 0 # Last output

ins = np.absolute(inputs)
ins = np.abs(inputs)
insigns = np.sign(inputs)
insigns[0] = 0 # First input

Expand Down
2 changes: 1 addition & 1 deletion examples/axes_grid1/scatter_hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

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

bins = np.arange(-lim, lim + binwidth, binwidth)
Expand Down
3 changes: 1 addition & 2 deletions examples/axes_grid1/simple_axesgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
from mpl_toolkits.axes_grid1 import ImageGrid
import numpy as np

im = np.arange(100)
im.shape = 10, 10
im = np.arange(100).reshape((10, 10))

fig = plt.figure(1, (4., 4.))
grid = ImageGrid(fig, 111, # similar to subplot(111)
Expand Down
4 changes: 2 additions & 2 deletions examples/event_handling/poly_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ def get_ind_under_point(self, event):
xy = np.asarray(self.poly.xy)
xyt = self.poly.get_transform().transform(xy)
xt, yt = xyt[:, 0], xyt[:, 1]
d = np.sqrt((xt - event.x)**2 + (yt - event.y)**2)
indseq = np.nonzero(np.equal(d, np.amin(d)))[0]
d = np.hypot(xt - event.x, yt - event.y)
indseq, = np.nonzero(d == d.min())
ind = indseq[0]

if d[ind] >= self.epsilon:
Expand Down
3 changes: 1 addition & 2 deletions examples/pylab_examples/agg_buffer.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@
l, b, w, h = agg.figure.bbox.bounds
w, h = int(w), int(h)

X = np.fromstring(s, np.uint8)
X.shape = h, w, 3
X = np.fromstring(s, np.uint8).reshape((h, w, 3))

try:
im = Image.fromstring("RGB", (w, h), s)
Expand Down
5 changes: 2 additions & 3 deletions examples/pylab_examples/anscombe.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def fit(x):
return 3 + 0.5*x


xfit = np.array([np.amin(x), np.amax(x)])
xfit = np.array([np.min(x), np.max(x)])

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

plt.subplot(224)

xfit = np.array([np.amin(x4), np.amax(x4)])
xfit = np.array([np.min(x4), np.max(x4)])
plt.plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2)
plt.axis([2, 20, 2, 14])
plt.setp(plt.gca(), yticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20))
Expand Down
4 changes: 2 additions & 2 deletions examples/pylab_examples/arrow_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
rates_to_bases = {'r1': 'AT', 'r2': 'TA', 'r3': 'GA', 'r4': 'AG', 'r5': 'CA',
'r6': 'AC', 'r7': 'GT', 'r8': 'TG', 'r9': 'CT', 'r10': 'TC',
'r11': 'GC', 'r12': 'CG'}
numbered_bases_to_rates = dict([(v, k) for k, v in rates_to_bases.items()])
lettered_bases_to_rates = dict([(v, 'r' + v) for k, v in rates_to_bases.items()])
numbered_bases_to_rates = {v: k for k, v in rates_to_bases.items()}
lettered_bases_to_rates = {v: 'r' + v for k, v in rates_to_bases.items()}


def add_dicts(d1, d2):
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/axes_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# the main axes is subplot(111) by default
plt.plot(t, s)
plt.axis([0, 1, 1.1*np.amin(s), 2*np.amax(s)])
plt.axis([0, 1, 1.1 * np.min(s), 2 * np.max(s)])
plt.xlabel('time (s)')
plt.ylabel('current (nA)')
plt.title('Gaussian colored noise')
Expand Down
7 changes: 2 additions & 5 deletions examples/pylab_examples/barcode_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,12 @@
fig = plt.figure()

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

x = x.copy()
# a horizontal barcode
x.shape = 1, len(x)
ax = fig.add_axes([0.3, 0.1, 0.6, 0.1], **axprops)
ax.imshow(x, **barprops)
ax.imshow(x.reshape((1, -1)), **barprops)


plt.show()
9 changes: 4 additions & 5 deletions examples/pylab_examples/figimage_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@


fig = plt.figure()
Z = np.arange(10000.0)
Z.shape = 100, 100
Z[:, 50:] = 1.
Z = np.arange(10000).reshape((100, 100))
Z[:, 50:] = 1

im1 = plt.figimage(Z, xo=50, yo=0, origin='lower')
im2 = plt.figimage(Z, xo=100, yo=100, alpha=.8, origin='lower')
im1 = fig.figimage(Z, xo=50, yo=0, origin='lower')
im2 = fig.figimage(Z, xo=100, yo=100, alpha=.8, origin='lower')

plt.show()
5 changes: 2 additions & 3 deletions examples/pylab_examples/image_demo2.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@

datafile = cbook.get_sample_data('ct.raw.gz', asfileobj=True)
s = datafile.read()
A = np.fromstring(s, np.uint16).astype(float)
A *= 1.0 / max(A)
A.shape = w, h
A = np.fromstring(s, np.uint16).astype(float).reshape((w, h))
A /= A.max()

extent = (0, 25, 0, 25)
im = plt.imshow(A, cmap=plt.cm.hot, origin='upper', extent=extent)
Expand Down
3 changes: 1 addition & 2 deletions examples/pylab_examples/image_origin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import matplotlib.pyplot as plt
import numpy as np

x = np.arange(120)
x.shape = (10, 12)
x = np.arange(120).reshape((10, 12))

interp = 'bilinear'
fig, axs = plt.subplots(nrows=2, sharex=True, figsize=(3, 5))
Expand Down
7 changes: 2 additions & 5 deletions examples/pylab_examples/layer_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@ def func3(x, y):
# for the images their apparent extent could be different due to
# interpolation edge effects


xmin, xmax, ymin, ymax = np.amin(x), np.amax(x), np.amin(y), np.amax(y)
extent = xmin, xmax, ymin, ymax
extent = np.min(x), np.max(x), np.min(y), np.max(y)
fig = plt.figure(frameon=False)

Z1 = np.array(([0, 1]*4 + [1, 0]*4)*4)
Z1.shape = (8, 8) # chessboard
Z1 = np.add.outer(range(8), range(8)) % 2 # chessboard
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does np.add.outer do (it works, but I've never seen it used that way)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It makes the first argument a column array and the second a row array, broadcasts them and applies the ufunc.

im1 = plt.imshow(Z1, cmap=plt.cm.gray, interpolation='nearest',
extent=extent)

Expand Down
4 changes: 2 additions & 2 deletions examples/pylab_examples/line_collection2.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

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

# colors is sequence of rgba tuples
# linestyle is a string or dash tuple. Legal string values are
Expand Down
3 changes: 1 addition & 2 deletions examples/pylab_examples/mri_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

# Data are 256x256 16 bit integers
dfile = cbook.get_sample_data('s1045.ima.gz')
im = np.fromstring(dfile.read(), np.uint16).astype(float)
im.shape = (256, 256)
im = np.fromstring(dfile.read(), np.uint16).reshape((256, 256))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No astype?

Also, can write np.fromfile(dfile, np.uint16) instead of the two step process.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can imshow an integer array just as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the one below this still need astype, then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed below too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, fromfile doesn't work with gzip.open'ed files (it seems to try to construct an array from the compressed representation). Reverting to read().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, unfortunate. Based on np.fromfile seeming to need fileno (since it doesn't work with BytesIO), it looks like it tries to stream from the fd directly, which GzipFile points at the underlying file object. In a way, it's a half-a-bug in both coming together to make one.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment on numpy/numpy#7713; we'll see where it goes...

dfile.close()

ax.imshow(im, cmap=cm.gray)
Expand Down
3 changes: 1 addition & 2 deletions examples/pylab_examples/mri_with_eeg.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@

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

# Plot the MRI image
Expand Down
11 changes: 5 additions & 6 deletions examples/pylab_examples/multi_image.py
F438
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
from matplotlib.pyplot import figure, show, axes, sci
from matplotlib import cm, colors
from matplotlib.font_manager import FontProperties
from numpy import amin, amax, ravel
from numpy.random import rand
import numpy as np

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

ax.append(a)
Expand Down
3 changes: 1 addition & 2 deletions examples/pylab_examples/quadmesh_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
Z = (Z - Z.min()) / (Z.max() - Z.min())

# The color array can include masked values:
Zm = ma.masked_where(np.fabs(Qz) < 0.5*np.amax(Qz), Z)

Zm = ma.masked_where(np.abs(Qz) < 0.5 * np.max(Qz), Z)

fig = figure()
ax = fig.add_subplot(121)
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/scatter_hist.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

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

axScatter.set_xlim((-lim, lim))
Expand Down
2 changes: 1 addition & 1 deletion examples/pylab_examples/vline_hline_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
def f(t):
s1 = np.sin(2 * np.pi * t)
e1 = np.exp(-t)
return np.absolute((s1 * e1)) + .05
return np.abs(s1 * e1) + .05

t = np.arange(0.0, 5.0, 0.1)
s = f(t)
Expand Down
5 changes: 2 additions & 3 deletions examples/tests/backend_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,13 @@ def report_missing(dir, flist):
globstr = os.path.join(dir, '*.py')
fnames = glob.glob(globstr)

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

exclude = set(excluded.get(dir, []))
flist = set(flist)
missing = list(pyfiles - flist - exclude)
missing.sort()
if missing:
print('%s files not tested: %s' % (dir, ', '.join(missing)))
print('%s files not tested: %s' % (dir, ', '.join(sorted(missing))))


def report_all_missing(directories):
Expand Down
4 changes: 2 additions & 2 deletions examples/user_interfaces/embedding_in_wx3.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def init_plot_data(self):
z = np.sin(self.x) + np.cos(self.y)
self.im = a.imshow(z, cmap=cm.RdBu) # , interpolation='nearest')

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

zmax = np.amax(z) - ERR_TOL
zmax = np.max(z) - ERR_TOL
ymax_i, xmax_i = np.nonzero(z >= zmax)
if self.im.origin == 'upper':
ymax_i = z.shape[0] - ymax_i
Expand Down
3 changes: 1 addition & 2 deletions examples/user_interfaces/histogram_demo_canvasagg.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@

if 0:
# convert to a numpy array
X = numpy.fromstring(s, numpy.uint8)
X.shape = h, w, 3
X = numpy.fromstring(s, numpy.uint8).reshape((h, w, 3))

if 0:
# pass off to PIL
Expand Down
4 changes: 2 additions & 2 deletions examples/widgets/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@ def __init__(self, fig, menuitems):
self.menuitems = menuitems
self.numitems = len(menuitems)

maxw = max([item.labelwidth for item in menuitems])
maxh = max([item.labelheight for item in menuitems])
maxw = max(item.labelwidth for item in menuitems)
maxh = max(item.labelheight for item in menuitems)

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

Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class Verbose(object):
instance to handle the output. Default is sys.stdout
"""
levels = ('silent', 'helpful', 'debug', 'debug-annoying')
vald = dict([(level, i) for i, level in enumerate(levels)])
vald = {level: i for i, level in enumerate(levels)}

# parse the verbosity from the command line; flags look like
# --verbose-silent or --verbose-helpful
Expand Down Expand Up @@ -860,10 +860,10 @@ def matplotlib_fname():
_deprecated_ignore_map = {
}

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

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

_all_deprecated = set(chain(_deprecated_ignore_map,
_deprecated_map,
Expand Down
Loading
0