S.Hemanth
S.Hemanth

Reputation: 63

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. 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 enter image description here

Upvotes: 1

Views: 3880

Answers (1)

nick
nick

Reputation: 1207

Use the pyplot.plot() method. 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:

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()

Upvotes: 1

Related Questions