3D画图 Python matplotlib & Axes3D

from http://www.scipy-lectures.org/intro/scipy.html#file-input-output-scipy-io

#3D 表面染色图的绘制 利用matplotlib

import numpy as np

from scipy import optimize
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D


def sixhump(x):
    return (4 - 2.1*x[0]**2 + x[0]**4 / 3.) * x[0]**2 + x[0] * x[1] + (-4 + \
        4*x[1]**2) * x[1] **2

x = np.linspace(-2, 2)
y = np.linspace(-1, 1)
xg, yg = np.meshgrid(x, y)

#plt.figure()  # simple visualization for use in tutorial
#plt.imshow(sixhump([xg, yg]))  #2 显示图像的灰度,只能将3位信息降低到二维
#plt.colorbar()






fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
surf = ax.plot_surface(xg, yg, sixhump([xg, yg]), rstride=1, cstride=1,
                       cmap=plt.cm.jet, linewidth=0, antialiased=False)

ax.set_xlabel('x')
ax.set_ylabel('y')
ax.set_zlabel('f(x, y)')

ax.set_title('Six-hump Camelback function')



你可能感兴趣的:(3D画图 Python matplotlib & Axes3D)