Responsive Navbar with Google Search
☰ Menu
Home
Python
LaTeX
GNUPlot
Arduino
Feedback
Contact Us
Plotting in Python: 3D Plot
Plotting in Python
Basic Plot and formatting
Subplot, Multiplot
Colormaps in Plots
Bar Plot
Pie Chart
Histogram
Quiver plot to show Vector Fields
Stream plot to Visualize Flow Data
Polar, Parametric Plot
Contour Plot
3D Plot
Density Plot
Animated Plot
Miscellaneous
3D Plot: Program 1
Trajectory of a projectile in 3D
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # Parameters for the projectile v0 = 50 # initial velocity theta = np.pi / 4 # launch angle g = 9.81 # gravity # Time of flight t = np.linspace(0, 2 * v0 * np.sin(theta) / g, 100) # Define the trajectory x = v0 * np.cos(theta) * t y = v0 * np.sin(theta) * t - 0.5 * g * t**2 z = np.zeros_like(t) # Plotting the trajectory fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.plot(x, y, z, label='Projectile Trajectory') ax.set_title("3D Projectile Trajectory") plt.savefig('plot.png')
Run Code
Output 1
3D Plot: Program 2
3D Magnetic Field Lines Around a Current-Carrying Wire
import numpy as np import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D # Define the magnetic field def magnetic_field(x, y, z): return -y / (x**2 + y**2), x / (x**2 + y**2), np.zeros_like(x) x, y, z = np.meshgrid(np.linspace(-5, 5, 10), np.linspace(-5, 5, 10), np.linspace(-5, 5, 10)) # Plotting the magnetic field lines fig = plt.figure() ax = fig.add_subplot(111, projection='3d') ax.quiver(x, y, z, *magnetic_field(x, y, z)) ax.set_title("Magnetic Field Around a Current-Carrying Wire") plt.savefig('plot.png')
Run Code
Output 2