您的位置:首页 > 编程语言 > Python开发

3D画图 Python matplotlib & Axes3D

2017-09-30 13:37 741 查看
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')

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: