Skip to content

Commit e9c9b0c

Browse files
committed
test: Add data points to 3D plots
Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
1 parent 74c8d8c commit e9c9b0c

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

cubinterpp/main.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def get_test_data_2d(case='standard'):
6363
f[5:7, 5:7] = np.array([[0.25, 0.2], [0.2, 0.25]])
6464
f[7:9, 7:9] = 0.5
6565
f = 10 * np.flip(f, axis=0) + 1
66-
return x, y, f
66+
return np.array(x), np.array(y), np.array(f)
6767

6868

6969
def refine_grid(x_coord, size_fine=1000, extension=0):
@@ -139,14 +139,18 @@ def main():
139139
refinement=46
140140
)
141141
title = interp_type.capitalize().replace('_', ' ')
142-
mpg.figure(title=f'{title} interpolation', layout_type='Qt')
142+
mpg.figure(title=f'{title} interpolation')
143143
mpg.surf(x_fine, y_fine, z_fine)
144144
ax = mpg.gca()
145145
ax.azimuth = 225
146-
ax.label_fmt = '.0f'
147146
ax.xticks = 8
148147
ax.yticks = 8
149148
ax.zlim = [0, 8]
149+
x, y, f = get_test_data_2d(case='three_bumps')
150+
xp = np.repeat(x, y.size)
151+
yp = np.tile(y, x.size)
152+
zp = f.flatten()
153+
mpg.points3(xp, yp, zp, color=(0.8, 0.1, 0.1, 1), size=3)
150154

151155
x, y, f = get_test_data_2d(case='three_bumps')
152156
x_fine, y_fine = refine_grid(x, 46), refine_grid(y, 46)
@@ -155,10 +159,10 @@ def main():
155159
mpg.surf(x_fine, y_fine, z_fine_scipy)
156160
ax = mpg.gca()
157161
ax.azimuth = 225
158-
ax.label_fmt = '.0f'
159162
ax.xticks = 8
160163
ax.yticks = 8
161164
ax.zlim = [0, 8]
165+
mpg.points3(xp, yp, zp, color=(0.8, 0.1, 0.1, 1), size=3)
162166

163167

164168
if __name__ == '__main__':

cubinterpp/periodic_spline_2d.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
""" Periodic spline example in 3D """
2+
3+
import numpy as np
4+
import cubinterpp.cubinterpp_py as cubinterpp # cubinterpp_py is a pybind11 module
5+
import mlpyqtgraph as mpg
6+
7+
8+
@mpg.plotter(projection='orthographic')
9+
def main():
10+
""" Interpolation of a torus to demonstrate periodic splines in 2D """
11+
nx, ny = 5, 5
12+
tx = np.linspace(0.0, 1.0, nx)
13+
ty = np.linspace(0.0, 1.0, ny)
14+
# generate torus points
15+
r_major = 3.0 # major radius
16+
r_minor = 1.0 # minor radius
17+
18+
x = np.zeros((nx, ny))
19+
y = np.zeros((nx, ny))
20+
z = np.zeros((nx, ny))
21+
for i in range(nx):
22+
for j in range(ny):
23+
u = 2.0 * np.pi * tx[i]
24+
v = 2.0 * np.pi * ty[j]
25+
x[i, j] = (r_major + r_minor * np.cos(v)) * np.cos(u)
26+
y[i, j] = (r_major + r_minor * np.cos(v)) * np.sin(u)
27+
z[i, j] = r_minor * np.sin(v)
28+
29+
# create periodic splines in 2D
30+
spline_x = cubinterpp.NaturalPeriodicSpline2D(tx, ty, x)
31+
spline_y = cubinterpp.NaturalPeriodicSpline2D(tx, ty, y)
32+
spline_z = cubinterpp.NaturalPeriodicSpline2D(tx, ty, z)
33+
# evaluate on finer grid
34+
nxi, nyi = 30, 30
35+
txi = np.linspace(0.0, 1.0, nxi)
36+
tyi = np.linspace(0.0, 1.0, nyi)
37+
x_fine = np.zeros((nxi, nyi))
38+
y_fine = np.zeros((nxi, nyi))
39+
z_fine = np.zeros((nxi, nyi))
40+
for i in range(nxi):
41+
for j in range(nyi):
42+
x_fine[i, j] = spline_x.eval(txi[i], tyi[j])
43+
y_fine[i, j] = spline_y.eval(txi[i], tyi[j])
44+
z_fine[i, j] = spline_z.eval(txi[i], tyi[j])
45+
46+
47+
mpg.figure(title='Periodic Spline Interpolation of a Torus')
48+
mpg.surf(x_fine, y_fine, z_fine)
49+
ax = mpg.gca()
50+
ax.azimuth = 225
51+
ax.xlim = [-4, 4]
52+
ax.ylim = [-4, 4]
53+
ax.zlim = [-1.5, 1.5]
54+
xp = x.flatten()
55+
yp = y.flatten()
56+
zp = z.flatten()
57+
mpg.points3(xp, yp, zp, color=(0.8, 0.1, 0.1, 1), size=5)
58+
59+
if __name__ == '__main__':
60+
main()

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ classifiers = [
2020
]
2121
urls = { Homepage = "https://github.com/swvanbuuren/cubinterpp" }
2222
dependencies = [
23-
"mlpyqtgraph==0.9.1",
23+
"matplotlib>=3.10.8",
24+
"mlpyqtgraph==0.11.1",
2425
"scipy==1.17.0",
2526
]
2627

0 commit comments

Comments
 (0)