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 1 commit
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
Prev Previous commit
Next Next commit
Use shorter function names (min, max, abs, conj).
  • Loading branch information
anntzer committed Dec 4, 2016
commit 3d00576eced6fa68eb34136e457510c00521baf7
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
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
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
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
4 changes: 1 addition & 3 deletions examples/pylab_examples/layer_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ 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.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.

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
11 changes: 5 additions & 6 deletions examples/pylab_examples/multi_image.py
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/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
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
34 changes: 17 additions & 17 deletions lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2460,7 +2460,7 @@ def stem(self, *args, **kwargs):
marker=linemarker, label="_nolegend_")
stemlines.append(l)

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

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

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

self.add_collection(collection, autolim=False)

minx = np.amin(x)
maxx = np.amax(x)
miny = np.amin(y)
maxy = np.amax(y)
minx = np.min(x)
maxx = np.max(x)
miny = np.min(y)
maxy = np.max(y)
collection.sticky_edges.x[:] = [minx, maxx]
collection.sticky_edges.y[:] = [miny, maxy]
corners = (minx, miny), (maxx, maxy)
Expand Down Expand Up @@ -5622,10 +5622,10 @@ def pcolormesh(self, *args, **kwargs):

self.add_collection(collection, autolim=False)

minx = np.amin(X)
maxx = np.amax(X)
miny = np.amin(Y)
maxy = np.amax(Y)
minx = np.min(X)
maxx = np.max(X)
miny = np.min(Y)
maxy = np.max(Y)
collection.sticky_edges.x[:] = [minx, maxx]
collection.sticky_edges.y[:] = [miny, maxy]
corners = (minx, miny), (maxx, maxy)
Expand Down Expand Up @@ -6386,7 +6386,7 @@ def _normalize_input(inp, ename='input'):
else:
labels = [six.text_type(lab) for lab in label]

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

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

if xextent is None:
xextent = 0, np.amax(t)
xextent = 0, np.max(t)
xmin, xmax = xextent
freqs += Fc
extent = xmin, xmax, freqs[0], freqs[-1]
Expand Down Expand Up @@ -7300,7 +7300,7 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
marker = 's'
if marker is None and markersize is None:
Z = np.asarray(Z)
mask = np.absolute(Z) > precision
mask = np.abs(Z) > precision

if 'cmap' not in kwargs:
kwargs['cmap'] = mcolors.ListedColormap(['w', 'k'],
Expand All @@ -7316,12 +7316,12 @@ def spy(self, Z, precision=0, marker=None, markersize=None,
y = c.row
x = c.col
else:
nonzero = np.absolute(c.data) > precision
nonzero = np.abs(c.data) > precision
y = c.row[nonzero]
x = c.col[nonzero]
else:
Z = np.asarray(Z)
nonzero = np.absolute(Z) > precision
nonzero = np.abs(Z) > precision
y, x = np.nonzero(nonzero)
if marker is None:
marker = 's'
Expand Down
12 changes: 6 additions & 6 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1346,8 +1346,8 @@ def get_data_ratio(self):
xmin, xmax = self.get_xbound()
ymin, ymax = self.get_ybound()

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

return ysize / xsize

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

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

return ysize / xsize

Expand Down Expand Up @@ -1432,8 +1432,8 @@ def apply_aspect(self, position=None):
xmin, xmax = math.log10(xmin), math.log10(xmax)
ymin, ymax = math.log10(ymin), math.log10(ymax)

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

l, b, w, h = position.bounds
box_aspect = fig_aspect * (h / w)
Expand Down
26 changes: 7 additions & 19 deletions lib/matplotlib/contour.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,20 +226,8 @@ def clabel(self, *args, **kwargs):

def print_label(self, linecontour, labelwidth):
"Return *False* if contours are too short for a label."
lcsize = len(linecontour)
if lcsize > 10 * labelwidth:
return True

xmax = np.amax(linecontour[:, 0])
xmin = np.amin(linecontour[:, 0])
ymax = np.amax(linecontour[:, 1])
ymin = np.amin(linecontour[:, 1])

lw = labelwidth
if (xmax - xmin) > 1.2 * lw or (ymax - ymin) > 1.2 * lw:
return True
else:
return False
return (len(linecontour) > 10 * labelwidth
or (np.ptp(linecontour, axis=0) > 1.2 * labelwidth).any())

def too_close(self, x, y, lw):
"Return *True* if a label is already near this location."
Expand Down Expand Up @@ -1056,8 +1044,8 @@ def _process_args(self, *args, **kwargs):
self.levels = args[0]
self.allsegs = args[1]
self.allkinds = len(args) > 2 and args[2] or None
self.zmax = np.amax(self.levels)
self.zmin = np.amin(self.levels)
self.zmax = np.max(self.levels)
self.zmin = np.min(self.levels)
self._auto = False

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

if len(self.levels) > 1 and np.amin(np.diff(self.levels)) <= 0.0:
if len(self.levels) > 1 and np.min(np.diff(self.levels)) <= 0.0:
if hasattr(self, '_corner_mask') and self._corner_mask == 'legacy':
warnings.warn("Contour levels are not increasing")
else:
Expand Down Expand Up @@ -1210,8 +1198,8 @@ def _process_levels(self):
with line contours.
"""
# following are deprecated and will be removed in 2.2
self._vmin = np.amin(self.levels)
self._vmax = np.amax(self.levels)
self._vmin = np.min(self.levels)
self._vmax = np.max(self.levels)

# Make a private _levels to include extended regions; we
# want to leave the original levels attribute unchanged.
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/legend_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ def create_artists(self, legend, orig_handle,
for lm, m in zip(leg_stemlines, stemlines):
self.update_prop(lm, m, legend)

leg_baseline = Line2D([np.amin(xdata), np.amax(xdata)],
leg_baseline = Line2D([np.min(xdata), np.max(xdata)],
[bottom, bottom])

self.update_prop(leg_baseline, baseline, legend)
Expand Down
Loading
0