3D Line or Scatter plot using Matplotlib (Python) [3D Chart]

If you ever want to plot some trajectory of particles then a 3D plot can be particularly useful.

The following is a very simple example of code illustrating the procedure to plot a 3D line/scatter chart using Matplotlib and Python


from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
# ax = fig.add_subplot(111, projection='3d')
ax = Axes3D(fig)

t = np.arange(0,20,0.2)
x = np.cos(t)-1
y = 1/2*(np.cos(2*t)-1)

# For scatter plot
# ax.scatter(x, y, t, c='r', marker='o')
ax.plot(x, y, t, c='r', marker='o')
# For line plot
ax.plot(x, y, t, c='g')

ax.set_title('Trajectory of electron for E vector along [120]')



PhD researcher at Friedrich-Schiller University Jena, Germany. I'm a physicist specializing in theoretical, computational and experimental condensed matter physics. I like to develop Physics related apps and softwares from time to time. Can code in most of the popular languages. Like to share my knowledge in Physics and applications using this Blog and a YouTube channel.
[wpedon id="7041" align="center"]

Leave a Reply

Your email address will not be published. Required fields are marked *