简体   繁体   English

如何使用 matplotlib 在同一图上绘制多个轨迹

[英]How to plot multiple trajectories on same plot using matplotlib

I have 2-D co-ordinates of each point in a trajectory for multiple trajectories.我有多个轨迹的轨迹中每个点的二维坐标。 I want to plot all these trajectories on a single plot using python preferably matplotlib.我想使用 python 最好是 matplotlib 在一个图上绘制所有这些轨迹。 I want the time-series plot of the trajectories as in the left figures in sample figures.我想要轨迹的时间序列图,如示例图中的左图所示。 The sample figure I found on Internet is我在网上找到的示例图是在此处输入图片说明

Use the pyplot.plot() method.使用pyplot.plot()方法。 You can plot an arbitrary number of trajectories on the same figure.您可以在同一图上绘制任意数量的轨迹。

from matplotlib import pyplot

x = range(12)
y1 = range(12)
y2 = [i**2 for i in x]
# y3,y4,...yn

pyplot.plot(x,y1)
pyplot.plot(x,y2)
pyplot.show()

For 3D plots:对于 3D 绘图:

from matplotlib import pyplot
from mpl_toolkits.mplot3d import Axes3D

x = range(12)
y1 = range(12)
y2 = [i**2 for i in x]
z1 = range(12)
z2 = [i/2 for i in z1]

f = pyplot.figure()
ax = f.add_subplot(111, projection='3d')
ax.set_xlabel('x (cm)')
ax.set_ylabel('y (cm)')
ax.set_zlabel('time(frame)')

ax.plot(x,y1,z1)
ax.plot(x,y2,z2)
pyplot.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM