Python基于matplotlib实现绘制三维图形功能示例
本文实例讲述了Python基于matplotlib实现绘制三维图形功能。分享给大家供大家参考,具体如下:
代码一:
# coding=utf-8 import numpy as np import matplotlib.pyplot as plt import mpl_toolkits.mplot3d x,y = np.mgrid[-2:2:20j,-2:2:20j] #测试数据 z=x*np.exp(-x**2-y**2) #三维图形 ax = plt.subplot(111, projection='3d') ax.set_title('www.jb51.net - matplotlib Demo'); ax.plot_surface(x,y,z,rstride=2, cstride=1, cmap=plt.cm.Blues_r) #设置坐标轴标签 ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') plt.show()
运行结果:
代码二:
# coding=utf-8 import pylab as pl import numpy as np import mpl_toolkits.mplot3d rho, theta = np.mgrid[0:1:40j,0:2*np.pi:40j] z = rho**2 x = rho*np.cos(theta) y = rho*np.sin(theta) ax = pl.subplot(111, projection='3d') ax.set_title('www.jb51.net - matplotlib Demo'); #ax.plot_surface(x,y,z) ax.plot_surface(x,y,z,rstride=2, cstride=1) #设置坐标轴标签 ax.set_xlabel('X') ax.set_ylabel('Y') ax.set_zlabel('Z') pl.show()
运行结果:
更多关于Python相关内容可查看本站专题:《Python数学运算技巧总结》、《Python正则表达式用法总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》及《Python入门与进阶经典教程》
希望本文所述对大家Python程序设计有所帮助。
相关推荐
meylovezn 2020-09-15
wordmhg 2020-07-28
syThinkCool 2020-07-16
adamlovejw 2020-06-20
woxmh 2020-06-03
maybeyoucan 2020-05-17
jiahaohappy 2020-05-11
laohyx 2020-05-07
Tonybo 2020-04-27
liusarazhang 2020-04-10
tengyunjiawucom 2020-03-27
wangdaren 2020-03-27
Leonwey 2020-03-03
xinhao 2020-02-18
Jonderwu 2020-02-10
数据齿轮 2020-01-31
FrederickBala 2020-01-29
Laozizuiku 2020-01-13