Skip to content

Commit cb904b1

Browse files
authored
Merge pull request #16430 from anntzer/unarray
DOC: Remove unnecessary calls to np.array in examples.
2 parents b66fecd + b5155b7 commit cb904b1

File tree

20 files changed

+54
-58
lines changed

20 files changed

+54
-58
lines changed

examples/animation/animated_histogram.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
n, bins = np.histogram(data, 100)
2222

2323
# get the corners of the rectangles for the histogram
24-
left = np.array(bins[:-1])
25-
right = np.array(bins[1:])
24+
left = bins[:-1]
25+
right = bins[1:]
2626
bottom = np.zeros(len(left))
2727
top = bottom + n
2828
nrects = len(left)

examples/images_contours_and_fields/image_annotated_heatmap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def annotate_heatmap(im, data=None, valfmt="{x:.2f}",
271271
y = ["Prod. {}".format(i) for i in range(10, 70, 10)]
272272
x = ["Cycle {}".format(i) for i in range(1, 7)]
273273

274-
qrates = np.array(list("ABCDEFG"))
274+
qrates = list("ABCDEFG")
275275
norm = matplotlib.colors.BoundaryNorm(np.linspace(-3.5, 3.5, 8), 7)
276276
fmt = matplotlib.ticker.FuncFormatter(lambda x, pos: qrates[::-1][norm(x)])
277277

examples/lines_bars_and_markers/eventplot_demo.py

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

2525
# set different line properties for each set of positions
2626
# note that some overlap
27-
lineoffsets1 = np.array([-15, -3, 1, 1.5, 6, 10])
27+
lineoffsets1 = [-15, -3, 1, 1.5, 6, 10]
2828
linelengths1 = [5, 2, 1, 1, 3, 1.5]
2929

3030
fig, axs = plt.subplots(2, 2)

examples/lines_bars_and_markers/scatter_star_poly.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
axs[0, 1].set_title(r"marker=r'\$\alpha\$'")
2929

3030
# marker from path
31-
verts = np.array([[-1, -1], [1, -1], [1, 1], [-1, -1]])
31+
verts = [[-1, -1], [1, -1], [1, 1], [-1, -1]]
3232
axs[0, 2].scatter(x, y, s=80, c=z, marker=verts)
3333
axs[0, 2].set_title("marker=verts")
3434

examples/lines_bars_and_markers/timeline.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@
8181
markerline.set_ydata(np.zeros(len(dates)))
8282

8383
# annotate lines
84-
vert = np.array(['top', 'bottom'])[(levels > 0).astype(int)]
85-
for d, l, r, va in zip(dates, levels, names, vert):
86-
ax.annotate(r, xy=(d, l), xytext=(-3, np.sign(l)*3),
87-
textcoords="offset points", va=va, ha="right")
84+
for d, l, r in zip(dates, levels, names):
85+
ax.annotate(r, xy=(d, l),
86+
xytext=(-3, np.sign(l)*3), textcoords="offset points",
87+
horizontalalignment="right",
88+
verticalalignment="bottom" if l > 0 else "top")
8889

8990
# format xaxis with 4 month intervals
9091
ax.get_xaxis().set_major_locator(mdates.MonthLocator(interval=4))

examples/misc/histogram_path.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
n, bins = np.histogram(data, 50)
3232

3333
# get the corners of the rectangles for the histogram
34-
left = np.array(bins[:-1])
35-
right = np.array(bins[1:])
34+
left = bins[:-1]
35+
right = bins[1:]
3636
bottom = np.zeros(len(left))
3737
top = bottom + n
3838

examples/pie_and_polar_charts/nested_pie.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
cmap = plt.get_cmap("tab20c")
3434
outer_colors = cmap(np.arange(3)*4)
35-
inner_colors = cmap(np.array([1, 2, 5, 6, 9, 10]))
35+
inner_colors = cmap([1, 2, 5, 6, 9, 10])
3636

3737
ax.pie(vals.sum(axis=1), radius=1, colors=outer_colors,
3838
wedgeprops=dict(width=size, edgecolor='w'))
@@ -63,7 +63,7 @@
6363

6464
cmap = plt.get_cmap("tab20c")
6565
outer_colors = cmap(np.arange(3)*4)
66-
inner_colors = cmap(np.array([1, 2, 5, 6, 9, 10]))
66+
inner_colors = cmap([1, 2, 5, 6, 9, 10])
6767

6868
ax.bar(x=valsleft[:, 0],
6969
width=valsnorm.sum(axis=1), bottom=1-size, height=size,

examples/scales/logit_demo.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,17 @@
66
Examples of plots with logit axes.
77
"""
88

9+
import math
10+
911
import numpy as np
1012
import matplotlib.pyplot as plt
1113

1214
xmax = 10
1315
x = np.linspace(-xmax, xmax, 10000)
14-
cdf_norm = np.array([np.math.erf(w / np.sqrt(2)) / 2 + 1 / 2 for w in x])
15-
cdf_laplacian = np.array(
16-
[1 / 2 * np.exp(w) if w < 0 else 1 - 1 / 2 * np.exp(-w) for w in x]
17-
)
18-
cdf_cauchy = 1 / np.pi * np.arctan(x) + 1 / 2
16+
cdf_norm = [math.erf(w / np.sqrt(2)) / 2 + 1 / 2 for w in x]
17+
cdf_laplacian = [1 / 2 * np.exp(w) if w < 0 else 1 - 1 / 2 * np.exp(-w)
18+
for w in x]
19+
cdf_cauchy = np.arctan(x) / np.pi + 1 / 2
1920

2021
fig, axs = plt.subplots(nrows=3, ncols=2, figsize=(6.4, 8.5))
2122

examples/shapes_and_collections/artist_reference.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,13 +86,13 @@ def label(xy, text):
8686
label(grid[7], "FancyBboxPatch")
8787

8888
# add a line
89-
x, y = np.array([[-0.06, 0.0, 0.1], [0.05, -0.05, 0.05]])
89+
x, y = ([-0.06, 0.0, 0.1], [0.05, -0.05, 0.05])
9090
line = mlines.Line2D(x + grid[8, 0], y + grid[8, 1], lw=5., alpha=0.3)
9191
label(grid[8], "Line2D")
9292

9393
colors = np.linspace(0, 1, len(patches))
9494
collection = PatchCollection(patches, cmap=plt.cm.hsv, alpha=0.3)
95-
collection.set_array(np.array(colors))
95+
collection.set_array(colors)
9696
ax.add_collection(collection)
9797
ax.add_line(line)
9898

examples/shapes_and_collections/compound_path.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
and a triangle. Use ``CLOSEPOLY`` and ``MOVETO`` for the different parts of
88
the compound path
99
"""
10-
import numpy as np
10+
1111
from matplotlib.path import Path
1212
from matplotlib.patches import PathPatch
1313
import matplotlib.pyplot as plt
1414

15-
1615
vertices = []
1716
codes = []
1817

@@ -22,7 +21,6 @@
2221
codes += [Path.MOVETO] + [Path.LINETO]*2 + [Path.CLOSEPOLY]
2322
vertices += [(4, 4), (5, 5), (5, 4), (0, 0)]
2423

25-
vertices = np.array(vertices, float)
2624
path = Path(vertices, codes)
2725

2826
pathpatch = PathPatch(path, facecolor='None', edgecolor='green')

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy