1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Python数据分析10——使用Matplotlib绘制3D图

Python数据分析10——使用Matplotlib绘制3D图

时间:2023-08-22 18:12:47

相关推荐

Python数据分析10——使用Matplotlib绘制3D图

目录

3D立体图形

3D绘图

3D散点图

3D曲线图

3D平面图

3D立体图形

绘制三维图像主要通过 mplot3d 模块实现。

from matplotlib import pyplot as pltfrom mpl_toolkits.mplot3d import Axes3D%matplotlib notebook

3D绘图

3D绘图与2D绘图使用的方法基本一致,不同的是,操作的对象变为了 Axes3D() 对象。

3D散点图

from matplotlib import pyplot as pltimport numpy as npfrom mpl_toolkits.mplot3d import Axes3Dx = np.random.rand(100)y = np.random.rand(100)z = np.random.rand(100)fig = plt.figure()ax = Axes3D(fig)ax.scatter(x,y,z,s=10,color="r",marker='o')plt.show()

3D曲线图

from matplotlib import pyplot as pltimport numpy as npfrom mpl_toolkits.mplot3d import Axes3Dzline = np.linspace(0,15,1000)xline = np.sin(zline)yline = np.cos(zline)fig = plt.figure()ax = Axes3D(fig)ax.plot(xline,yline,zline)plt.show()

3D平面图

x = [1,2,3,4]y = [1,2,3,4]X, Y = np.meshgrid(x, y)# 创建画布fig = plt.figure()# 创建3D坐标系ax = Axes3D(fig)ax.plot_surface(X,Y,Z=X+Y)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。