probe_0315.dat
20.00, 60.00, -0.630
0.00, 60.00, -0.690
-20.00, 60.00, -0.830
-40.00, 40.00, -0.290
-20.00, 40.00, -0.440
0.00, 40.00, -0.600
20.00, 40.00, -0.730
40.00, 40.00, -0.820
60.00, 20.00, 0.160
40.00, 20.00, -0.050
20.00, 20.00, -0.260
0.00, 20.00, -0.460
-20.00, 20.00, -0.620
-40.00, 20.00, -0.770
-60.00, 20.00, -0.890
-60.00, 0.00, 0.400
-40.00, 0.00, 0.140
-20.00, 0.00, -0.130
0.00, 0.00, -0.360
20.00, 0.00, -0.590
40.00, 0.00, -0.760
60.00, 0.00, -0.860
60.00, -20.00, 0.600
40.00, -20.00, 0.340
20.00, -20.00, 0.080
0.00, -20.00, -0.170
-20.00, -20.00, -0.410
-40.00, -20.00, -0.590
-60.00, -20.00, -0.740
-40.00, -40.00, 0.470
-20.00, -40.00, 0.160
0.00, -40.00, -0.090
20.00, -40.00, -0.330
40.00, -40.00, -0.520
20.00, -60.00, 0.300
0.00, -60.00, 0.080
-20.00, -60.00, -0.150
# http://stackoverflow.com/questions/4363857/matplotlib-color-in-3d-plotting-from-an-x-y-z-data-set-without-using-contour from mpl_toolkits.mplot3d import Axes3D from matplotlib.mlab import griddata from matplotlib import cm from matplotlib.ticker import LinearLocator, FormatStrFormatter import matplotlib.pyplot as plt import numpy as np import sys def xyz_ret(file): import codecs f = open(file, 'r') xyz = [] for line in f: if line.startswith(codecs.BOM_UTF8): line = line[3:] ret = line.replace('\n','') xyz.append(map(float,(ret.split(',')))) # xyz.append(map(float,(ret.split('\t')))) xyz = np.array(xyz) return xyz[:,0],xyz[:,1],xyz[:,2] x,y,z = xyz_ret('probe_0315.dat') fig = plt.figure() # ax = fig.add_subplot(111, projection='3d') ax = fig.gca(projection='3d') xi = np.linspace(min(x), max(x)) yi = np.linspace(min(y), max(y)) X, Y = np.meshgrid(xi, yi) Z = griddata(x, y, z, xi, yi) surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.jet, linewidth=0, antialiased=True, vmin=min(z), vmax=max(z)) ax.set_xlim(min(x), max(x)) ax.set_ylim(min(y), max(y)) ax.set_zlim(min(z), max(z)) ax.set_title('Print bed level') ax.set_xlabel('X axis [mm]') ax.set_ylabel('Y axis [mm]') ax.set_zlabel('Z height [mm]') ax.zaxis.set_major_locator(LinearLocator(10)) ax.zaxis.set_major_formatter(FormatStrFormatter('%.03f')) fig.colorbar(surf, shrink=0.5, aspect=5) # ax.set_zlim3d(min(z), max(z)) # ax.w_zaxis.set_major_locator(LinearLocator(10)): # ax.w_zaxis.set_major_formatter(FormatStrFormatter('%.03f')) # fig.colorbar(surf, shrink=0.5, aspect=5) # fig.colorbar(surf) plt.show()