我是靠谱客的博主 冷静飞机,最近开发中收集的这篇文章主要介绍matplotlib绘制三维轨迹图,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

1. 绘制基本三维曲线

# import necessary module
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np

# load data from file
# you can replace this using with open
data1 = np.loadtxt("./pos.txt")
# print (data1)
num=data1.size


datax = data1[:, 0]
datay = data1[:, 1]
dataz = data1[:, 2]

print (datax)
print (datay)
print (dataz)

numx=datax.size
print(numx)
numy=datay.size
print(numy)
numz=dataz.size
print(numz)

# new a figure and set it into 3d
fig = plt.figure()
ax = fig.gca(projection='3d')

# set figure information
ax.set_title("3D_Curve")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")

# draw the figure, the color is r = read
figure = ax.plot(datax, datay, dataz, c='r')

plt.show()

在这里插入图片描述

2. 同一张图中绘制多个三维曲线

# import necessary module
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
from pylab import *

# load data from file
# you can replace this using with open
data1 = np.loadtxt("./pos.txt")
datax = data1[:, 0]
datay = data1[:, 1]
dataz = data1[:, 2]

data2 = np.loadtxt("./pos.txt")
data2x = data2[:, 0]
data2y = data2[:, 1]
data2z = data2[:, 2]

# new a figure and set it into 3d
fig = plt.figure()
ax = fig.gca(projection='3d')


# set figure information
ax.set_title("3D_Curve")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")

# draw the figure, the color is r = read
figure1 = ax.plot(datax, datay, dataz, c='r',marker='*',linestyle='--')
figure2 = ax.plot(data2x, data2y, data2z+0.01, c='b',marker='^',linestyle='-')
plt.show()

在这里插入图片描述

3. 将区域划分后绘制三维图像

# import necessary module
from mpl_toolkits.mplot3d import axes3d
import matplotlib.pyplot as plt
import numpy as np
from pylab import *

# load data from file
# you can replace this using with open
data1 = np.loadtxt("./pos.txt")
datax = data1[:, 0]
datay = data1[:, 1]
dataz = data1[:, 2]

data2 = np.loadtxt("./pos_ros.txt")
data2x = data2[:, 0]
data2y = data2[:, 1]
data2z = data2[:, 2]


# new a figure and set it into 3d
fig = plt.figure()
# ############ first subplot ############
ax = fig.add_subplot(3, 3, 1, projection='3d')
# ax = fig.gca(projection='3d')


# set figure information
ax.set_title("3D_Curve")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")

# draw the figure, the color is r = read
figure1 = ax.plot(datax, datay, dataz, c='r',marker='*',linestyle='-')
# figure2 = ax.plot(data2x, data2y, data2z, c='b',marker='^',linestyle='-')


# plt.figure(1)

# ############ second subplot ############
ax = fig.add_subplot(3, 3, 2, projection='3d')

# set figure information
ax.set_title("3D_Curve2")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")

# draw the figure, the color is r = read
# figure1 = ax.plot(datax, datay, dataz, c='r',marker='*',linestyle='-')
figure2 = ax.plot(data2x, data2y, data2z, c='b',marker='^',linestyle='-')

# ############ third subplot ############
ax = fig.add_subplot(3, 3, 3, projection='3d')

# set figure information
ax.set_title("3D_Curve3")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_zlabel("z")

# draw the figure, the color is r = read
figure1 = ax.plot(datax, datay, dataz, c='r',marker='*',linestyle='-')
figure2 = ax.plot(data2x, data2y, data2z+0.01, c='b',marker='^',linestyle='-')

plt.show()

在这里插入图片描述

4. plot

5.reference

https://blog.csdn.net/qq_34859482/article/details/80617391

最后

以上就是冷静飞机为你收集整理的matplotlib绘制三维轨迹图的全部内容,希望文章能够帮你解决matplotlib绘制三维轨迹图所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部