matplotlib examples‎ > ‎Posts‎ > ‎

3D surface, wireframe, regression

posted May 8, 2011, 11:08 PM by Mart Objartel   [ updated May 9, 2011, 12:32 AM ]
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
import mpl_toolkits.mplot3d.axes3d as axes3d

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')

#Data
fx = [0.673574075,0.727952994,0.6746285,0.797313558,0.37664721,0.67939197,0.748490102,0.722048276,0.767189284,0.768296082,0.732383162,0.748429373,0.751570337,0.698977802,0.703398777,0.802607746,0.786242535,0.366661714,0.792490268,0.698636545,0.769904493,0.762656928,0.478595152,0.759151743,0.728607906,0.778099194,0.728575153,0.703794547]
fy = [0.331657721,0.447817839,0.37733386,0.306640864,0.107229109,0.329287287,0.758907052,0.310634309,0.277462605,0.333935925,0.326699919,0.72242944,0.358848707,0.298222369,0.306303486,0.43058538,0.373973649,0.117132288,0.432939444,0.255479494,0.384761779,0.382446444,0.35914706,0.298360515,0.391041147,0.363895412,0.312359532,0.343344197]
fz = [18.13629648,8.620699842,9.807536512,17.40105183,24.44101897,18.81025228,8.075948931,18.10817229,22.24192367,13.8497555,13.28436202,4.472128831,14.53195939,15.93922217,0,0,11.28194885,0,0,26.12423918,9.200498046,14.01392223,14.14545413,17.8320704,8.985897324,10.53443457,12.48561226,11.80438073]

#generate data for regression equation
Xs = np.arange(0.4, 0.8, 0.005)
Ys = np.arange(0.2, 0.7, 0.005)
Xs, Ys = np.meshgrid(Xs, Ys)

#3D regression solved using DataFit(R), http://www.oakdaleengr.com/
Zs = 41.0909875400163+15.3581432751401*np.log(Xs)+-90.9714747515509*Ys+64.9652271333282*Ys**2

ax.plot(fx, fy, fz, linestyle="none", marker="o", mfc="none", markeredgecolor="red")

#plot wireframe
#ax.plot_wireframe(Xs, Ys, Zs, rstride=4, cstride=4, alpha=0.4)

#plot surface, more colormaps: http://matplotlib.sourceforge.net/examples/pylab_examples/show_colormaps.html
ax.plot_surface(Xs, Ys, Zs, rstride=4, cstride=4, alpha=0.4,cmap=cm.jet)

plt.show()

ċ
surface.py
(2k)
Mart Objartel,
May 8, 2011, 11:10 PM
Comments