Skip to content

Commit 9dd1441

Browse files
committed
Simplify unstructured data generation
There is no need to generate a regular grid and statistically choose points from that. Instead, we can immediately choose random points.
1 parent cb41936 commit 9dd1441

File tree

4 files changed

+18
-40
lines changed

4 files changed

+18
-40
lines changed

plot_types/unstructured/tricontour.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@
1010

1111
plt.style.use('_mpl-gallery-nogrid')
1212

13-
# make structured data
14-
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
15-
Z = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)
16-
levels = np.linspace(Z.min(), Z.max(), 7)
17-
18-
# sample it to make unstructured x, y, z
13+
# make data:
1914
np.random.seed(1)
20-
ysamp = np.random.randint(0, 256, size=250)
21-
xsamp = np.random.randint(0, 256, size=250)
22-
y = Y[:, 0][ysamp]
23-
x = X[0, :][xsamp]
24-
z = Z[ysamp, xsamp]
15+
x = np.random.uniform(-3, 3, 256)
16+
y = np.random.uniform(-3, 3, 256)
17+
z = (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)
18+
levels = np.linspace(z.min(), z.max(), 7)
2519

2620
# plot:
2721
fig, ax = plt.subplots()

plot_types/unstructured/tricontourf.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,12 @@
1010

1111
plt.style.use('_mpl-gallery-nogrid')
1212

13-
# make structured data
14-
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
15-
Z = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)
16-
levels = np.linspace(np.min(Z), np.max(Z), 7)
17-
18-
# sample it to make unstructured x, y, z
13+
# make data:
1914
np.random.seed(1)
20-
ysamp = np.random.randint(0, 256, size=250)
21-
xsamp = np.random.randint(0, 256, size=250)
22-
y = Y[:, 0][ysamp]
23-
x = X[0, :][xsamp]
24-
z = Z[ysamp, xsamp]
15+
x = np.random.uniform(-3, 3, 256)
16+
y = np.random.uniform(-3, 3, 256)
17+
z = (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)
18+
levels = np.linspace(z.min(), z.max(), 7)
2519

2620
# plot:
2721
fig, ax = plt.subplots()

plot_types/unstructured/tripcolor.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@
1010

1111
plt.style.use('_mpl-gallery-nogrid')
1212

13-
# make structured data
14-
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
15-
Z = (1 - X/2 + X**5 + Y**3) * np.exp(-X**2 - Y**2)
16-
17-
# sample it to make unstructured x, y, z
13+
# make data:
1814
np.random.seed(1)
19-
ysamp = np.random.randint(0, 256, size=250)
20-
xsamp = np.random.randint(0, 256, size=250)
21-
y = Y[:, 0][ysamp]
22-
x = X[0, :][xsamp]
23-
z = Z[ysamp, xsamp]
15+
x = np.random.uniform(-3, 3, 256)
16+
y = np.random.uniform(-3, 3, 256)
17+
z = (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)
2418

2519
# plot:
2620
fig, ax = plt.subplots()

plot_types/unstructured/triplot.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,11 @@
1010

1111
plt.style.use('_mpl-gallery-nogrid')
1212

13-
# make structured data
14-
X, Y = np.meshgrid(np.linspace(-3, 3, 256), np.linspace(-3, 3, 256))
15-
16-
# sample it to make x, y, z
13+
# make data:
1714
np.random.seed(1)
18-
ysamp = np.random.randint(0, 256, size=250)
19-
xsamp = np.random.randint(0, 256, size=250)
20-
y = Y[:, 0][ysamp]
21-
x = X[0, :][xsamp]
15+
x = np.random.uniform(-3, 3, 256)
16+
y = np.random.uniform(-3, 3, 256)
17+
z = (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)
2218

2319
# plot:
2420
fig, ax = plt.subplots()

0 commit comments

Comments
 (0)