Created
December 17, 2023 16:56
-
-
Save nero-dv/779af79071f6d66fa0cc3e8457a92c13 to your computer and use it in GitHub Desktop.
ABL bed level mesh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from scipy.interpolate import interp2d | |
from mpl_toolkits.mplot3d import Axes3D | |
# Define the grid point values | |
z = np.array( | |
[ | |
[1.016, 0.515, 0.112, -0.193, -0.431], | |
[0.907, 0.426, 0.054, -0.243, -0.478], | |
[0.796, 0.356, 0.007, -0.304, -0.552], | |
[0.630, 0.209, -0.142, -0.432, -0.662], | |
[0.344, -0.043, -0.385, -0.660, -0.866], | |
] | |
) | |
# Define the x and y coordinates | |
x = np.array([0, 1, 2, 3, 4]) | |
y = np.array([0, 1, 2, 3, 4]) | |
# Perform the bilinear interpolation | |
interp_func = interp2d(x, y, z, kind="linear") | |
# Create a finer grid for the interpolation result | |
xnew = np.linspace(0, 4, num=100, endpoint=True) | |
ynew = np.linspace(0, 4, num=100, endpoint=True) | |
# Compute the interpolated values | |
znew = interp_func(xnew, ynew) | |
fig = plt.figure(figsize=(12, 6)) | |
ax = fig.add_subplot(111, projection="3d") | |
X, Y = np.meshgrid(xnew, ynew) | |
# Plot the surface | |
surf = ax.plot_surface(X, Y, znew, cmap=plt.cm.coolwarm, linewidth=0, antialiased=False) | |
# Add a color bar which maps values to colors | |
fig.colorbar(surf, shrink=0.5, aspect=5) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment