|
1 | 1 | from plotter import * |
2 | 2 | import numpy as np |
3 | 3 | from scipy.interpolate import interp2d |
4 | | -from mayavi import mlab |
| 4 | +import pyvista as pv |
5 | 5 | import mpl_toolkits.mplot3d |
6 | 6 | import matplotlib.pyplot as plt |
7 | 7 |
|
|
17 | 17 | newy = np.linspace(0, np.max(y), 1000) |
18 | 18 | newz = interpfunc(newx, newy) |
19 | 19 |
|
20 | | -#extent = [np.min(newx), np.max(newx), np.min(newy), np.max(newy)] |
21 | | -#plt.contourf(newx.reshape(-1), newy.reshape(-1), newz, 20, extent=extent) |
22 | | -#plt.colorbar() |
23 | | -# |
24 | | -##3d plot |
25 | | -#fig3d = plt.figure() |
26 | | -#ax3d = fig3d.add_subplot(111, projection='3d') |
27 | | -#ax3d.plot_surface(newx, newy, newz, cmap=plt.cm.RdBu_r) |
28 | | -# |
29 | | -#plt.show() |
| 20 | +# PyVista surface plot |
| 21 | +nx, ny = len(newx), len(newy) |
| 22 | +X, Y = np.meshgrid(newx, newy, indexing='ij') |
| 23 | +Z = newz.T |
| 24 | +surface = pv.StructuredGrid(X[:, :, None], Y[:, :, None], Z[:, :, None]) |
| 25 | +surface.point_data['scalars'] = Z[:, :, None].flatten(order='F') |
30 | 26 |
|
31 | | -#mlab |
32 | | -face = mlab.surf(newx, newy, newz, warp_scale=2) |
33 | | -mlab.axes(xlabel='x', ylabel='y', zlabel='z') |
34 | | -mlab.outline(face) |
35 | | - |
36 | | -mlab.show() |
| 27 | +pl = pv.Plotter() |
| 28 | +pl.add_mesh(surface, scalars='scalars', cmap='viridis', show_scalar_bar=True) |
| 29 | +pl.add_axes(xlabel='x', ylabel='y', zlabel='z') |
| 30 | +pl.show() |
0 commit comments