python绘制三维曲线图_python matplotlib绘制三维图的示例

起步

新建一个matplotlib.figure.Figure对象,然后向其添加一个Axes3D类型的axes对象。

其中Axes3D对象的创建,类似其他axes对象,只不过使用projection='3d'关键词。

1

2

3

4

import matplotlib.pyplot as plt

from mpl_toolkits.mplot3dimport Axes3D

fig= plt.figure()

ax= fig.add_subplot(111, projection='3d')

3D曲线图

1-200924133043.png

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

import matplotlib as mpl

from mpl_toolkits.mplot3dimport Axes3D

import numpy as np

import matplotlib.pyplot as plt

mpl.rcParams['legend.fontsize']= 10

fig= plt.figure()

ax= fig.gca(projection='3d')

theta= np.linspace(-4 * np.pi,4 * np.pi,100)

z= np.linspace(-2,2,100)

r= z**2 + 1

x= r* np.sin(theta)

y= r* np.cos(theta)

ax.plot(x, y, z, label='parametric curve')

ax.legend()

ax.set_xlabel('X Label')

ax.set_ylabel('Y Label')

ax.set_zlabel('Z Label')

plt.show()

简化用法:

1-200924133044.png

1

2

3

4

5

6

7

8

from pylabimport *

from mpl_toolkits.mplot3dimport Axes3D

plt.gca(projection='3d')

plt.plot([1,2,3],[3,4,1],[8,4,1],'--')

plt.xlabel('X')

plt.ylabel('Y')

#plt.zlabel('Z') #无法使用

3D散点图

1-200924133044-50.png

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

import numpy as np

from mpl_toolkits.mplot3dimport Axes3D

import matplotlib.pyplot as plt

def randrange(n, vmin, vmax):

return (vmax-vmin)*np.random.rand(n)+ vmin

fig= plt.figure()

ax= fig.add_subplot(111, projection='3d')

n= 100

for c, m, zl, zhin [('r','o',-50,-25), ('b','^',-30,-5)]:

xs= randrange(n,23,32)

ys= randrange(n,0,100)

zs= randrange(n, zl, zh)

ax.scatter(xs, ys, zs, c=c, marker=m)

ax.set_xlabel('X Label')

ax.set_ylabel('Y Label')

ax.set_zlabel('Z Label')

plt.show()

以上就是matplotlib绘制三维图的示例的详细内容,更多关于matplotlib绘制三维图的资料请关注服务器之家其它相关文章!

原文链接:https://www.cnblogs.com/catmelo/p/4162101.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值