码迷,mamicode.com
首页 > 其他好文 > 详细

matplotlib表面三维图

时间:2018-01-26 17:07:16      阅读:264      评论:0      收藏:0      [点我收藏+]

标签:false   mat   alias   二维数组   图库   ticker   body   grid   lib   

1.basic

2.code

In [88]: from mpl_toolkits.mplot3d import Axes3D

In [89]: from matplotlib import cm

In [108]: from matplotlib.ticker import LinearLocator,FormatStrFormatter

In [91]: import matplotlib.pyplot as plt

In [92]: import numpy as np

In [93]: fig=plt.figure(figsize=(12,9))

In [94]: points=np.arange(-4,4,0.25)

In [95]: xx,yy=np.meshgrid(points,points)

In [96]: r=np.sqrt(xx**2+yy**2)

In [97]: z=np.sin(r)
In [103]: surf=ax.plot_surface(xx,yy,z,rstride=1,cstride=1,cmap=cm.coolwarm,linewidth=0,antialiased=False)

In [104]: ax.set_zlim(-1.01,1.01)
Out[104]: (-1.01, 1.01)

In [105]: ax.zaxis.set_major_locator(LinearLocator(10))

In [109]: ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))

In [110]: fig.colorbar(surf,shrink=0.6,aspect=6)
Out[110]: <matplotlib.colorbar.Colorbar at 0xaae3710>

In [111]: plt.show()

3.result

技术分享图片

matplotlib表面三维图

标签:false   mat   alias   二维数组   图库   ticker   body   grid   lib   

原文地址:https://www.cnblogs.com/yangjing000/p/8360096.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!