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

Skip to content

Commit c1781ec

Browse files
authored
Merge pull request #10603 from anntzer/np110
Remove workarounds for numpy<1.10.
2 parents bad022e + 6385ccf commit c1781ec

28 files changed

Lines changed: 131 additions & 318 deletions

examples/api/custom_projection_example.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -395,18 +395,17 @@ def __init__(self, resolution):
395395
self._resolution = resolution
396396

397397
def transform_non_affine(self, ll):
398-
longitude = ll[:, 0:1]
399-
latitude = ll[:, 1:2]
398+
longitude, latitude = ll.T
400399

401400
# Pre-compute some values
402-
half_long = longitude / 2.0
401+
half_long = longitude / 2
403402
cos_latitude = np.cos(latitude)
404-
sqrt2 = np.sqrt(2.0)
403+
sqrt2 = np.sqrt(2)
405404

406-
alpha = np.sqrt(1.0 + cos_latitude * np.cos(half_long))
407-
x = (2.0 * sqrt2) * (cos_latitude * np.sin(half_long)) / alpha
405+
alpha = np.sqrt(1 + cos_latitude * np.cos(half_long))
406+
x = (2 * sqrt2) * (cos_latitude * np.sin(half_long)) / alpha
408407
y = (sqrt2 * np.sin(latitude)) / alpha
409-
return np.concatenate((x, y), 1)
408+
return np.column_stack([x, y])
410409
transform_non_affine.__doc__ = Transform.transform_non_affine.__doc__
411410

412411
def transform_path_non_affine(self, path):

examples/misc/demo_ribbon_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def __init__(self, color):
3030
self.original_image.dtype)
3131

3232
im[:, :, :3] = self.b_and_h[:, :, np.newaxis]
33-
im[:, :, :3] -= self.color[:, :, np.newaxis]*(1. - np.array(rgb))
33+
im[:, :, :3] -= self.color[:, :, np.newaxis] * (1 - np.array(rgb))
3434
im[:, :, 3] = self.alpha
3535

3636
self.im = im

examples/mplot3d/hist3d.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,14 @@
2020
hist, xedges, yedges = np.histogram2d(x, y, bins=4, range=[[0, 4], [0, 4]])
2121

2222
# Construct arrays for the anchor positions of the 16 bars.
23-
# Note: np.meshgrid gives arrays in (ny, nx) so we use 'F' to flatten xpos,
24-
# ypos in column-major order. For numpy >= 1.7, we could instead call meshgrid
25-
# with indexing='ij'.
26-
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25)
27-
xpos = xpos.flatten('F')
28-
ypos = ypos.flatten('F')
29-
zpos = np.zeros_like(xpos)
23+
xpos, ypos = np.meshgrid(xedges[:-1] + 0.25, yedges[:-1] + 0.25, indexing="ij")
24+
xpos = xpos.ravel()
25+
ypos = ypos.ravel()
26+
zpos = 0
3027

3128
# Construct arrays with the dimensions for the 16 bars.
32-
dx = 0.5 * np.ones_like(zpos)
33-
dy = dx.copy()
34-
dz = hist.flatten()
29+
dx = dy = 0.5 * np.ones_like(zpos)
30+
dz = hist.ravel()
3531

3632
ax.bar3d(xpos, ypos, zpos, dx, dy, dz, color='b', zsort='average')
3733

examples/mplot3d/trisurf3d.py

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

1717
# Make radii and angles spaces (radius r=0 omitted to eliminate duplication).
1818
radii = np.linspace(0.125, 1.0, n_radii)
19-
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)
20-
21-
# Repeat all angles for each radius.
22-
angles = np.repeat(angles[..., np.newaxis], n_radii, axis=1)
19+
angles = np.linspace(0, 2*np.pi, n_angles, endpoint=False)[..., np.newaxis]
2320

2421
# Convert polar (radii, angles) coords to cartesian (x, y) coords.
2522
# (0, 0) is manually added at this stage, so there will be no duplicate

examples/pyplots/boxplot_demo_pyplot.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
center = np.ones(25) * 50
1818
flier_high = np.random.rand(10) * 100 + 100
1919
flier_low = np.random.rand(10) * -100
20-
data = np.concatenate((spread, center, flier_high, flier_low), 0)
20+
data = np.concatenate((spread, center, flier_high, flier_low))
2121

2222
###############################################################################
2323

@@ -64,7 +64,7 @@
6464
center = np.ones(25) * 40
6565
flier_high = np.random.rand(10) * 100 + 100
6666
flier_low = np.random.rand(10) * -100
67-
d2 = np.concatenate((spread, center, flier_high, flier_low), 0)
67+
d2 = np.concatenate((spread, center, flier_high, flier_low))
6868
data.shape = (-1, 1)
6969
d2.shape = (-1, 1)
7070

examples/shapes_and_collections/ellipse_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
y = np.arange(15)
1313
X, Y = np.meshgrid(x, y)
1414

15-
XY = np.hstack((X.ravel()[:, np.newaxis], Y.ravel()[:, np.newaxis]))
15+
XY = np.column_stack((X.ravel(), Y.ravel()))
1616

1717
ww = X / 10.0
1818
hh = Y / 15.0

examples/shapes_and_collections/line_collection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
# Here are many sets of y to plot vs x
2323
ys = x[:50, np.newaxis] + x[np.newaxis, :]
2424

25-
segs = np.zeros((50, 100, 2), float)
25+
segs = np.zeros((50, 100, 2))
2626
segs[:, :, 1] = ys
2727
segs[:, :, 0] = x
2828

examples/specialty_plots/mri_with_eeg.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,10 @@
4040
ax1.set_ylabel('MRI density')
4141

4242
# Load the EEG data
43-
numSamples, numRows = 800, 4
43+
n_samples, n_rows = 800, 4
4444
with cbook.get_sample_data('eeg.dat') as eegfile:
45-
data = np.fromfile(eegfile, dtype=float)
46-
data.shape = (numSamples, numRows)
47-
t = 10.0 * np.arange(numSamples) / numSamples
45+
data = np.fromfile(eegfile, dtype=float).reshape((n_samples, n_rows))
46+
t = 10 * np.arange(n_samples) / n_samples
4847

4948
# Plot the EEG
5049
ticklocs = []
@@ -55,15 +54,15 @@
5554
dmax = data.max()
5655
dr = (dmax - dmin) * 0.7 # Crowd them a bit.
5756
y0 = dmin
58-
y1 = (numRows - 1) * dr + dmax
57+
y1 = (n_rows - 1) * dr + dmax
5958
ax2.set_ylim(y0, y1)
6059

6160
segs = []
62-
for i in range(numRows):
63-
segs.append(np.hstack((t[:, np.newaxis], data[:, i, np.newaxis])))
61+
for i in range(n_rows):
62+
segs.append(np.column_stack((t, data[:, i])))
6463
ticklocs.append(i * dr)
6564

66-
offsets = np.zeros((numRows, 2), dtype=float)
65+
offsets = np.zeros((n_rows, 2), dtype=float)
6766
offsets[:, 1] = ticklocs
6867

6968
lines = LineCollection(segs, offsets=offsets, transOffset=None)

examples/statistics/boxplot_demo.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
center = np.ones(25) * 50
2424
flier_high = np.random.rand(10) * 100 + 100
2525
flier_low = np.random.rand(10) * -100
26-
data = np.concatenate((spread, center, flier_high, flier_low), 0)
26+
data = np.concatenate((spread, center, flier_high, flier_low))
2727

2828
fig, axs = plt.subplots(2, 3)
2929

@@ -59,7 +59,7 @@
5959
center = np.ones(25) * 40
6060
flier_high = np.random.rand(10) * 100 + 100
6161
flier_low = np.random.rand(10) * -100
62-
d2 = np.concatenate((spread, center, flier_high, flier_low), 0)
62+
d2 = np.concatenate((spread, center, flier_high, flier_low))
6363
data.shape = (-1, 1)
6464
d2.shape = (-1, 1)
6565
# Making a 2-D array only works if all the columns are the

lib/matplotlib/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@
141141
# definitions, so it is safe to import from it here.
142142
from . import cbook
143143
from matplotlib.cbook import (
144-
_backports, mplDeprecation, dedent, get_label, sanitize_sequence)
144+
mplDeprecation, dedent, get_label, sanitize_sequence)
145+
from matplotlib.compat import subprocess
145146
from matplotlib.rcsetup import defaultParams, validate_backend, cycler
146147

147148
import numpy
@@ -156,7 +157,7 @@
156157

157158
_log = logging.getLogger(__name__)
158159

159-
__version__numpy__ = str('1.10.0') # minimum required numpy version
160+
__version__numpy__ = '1.10.0' # minimum required numpy version
160161

161162
__bibtex__ = r"""@Article{Hunter:2007,
162163
Author = {Hunter, J. D.},

0 commit comments

Comments
 (0)