Fundamentals 5 min read

Plotting a Parabolic Trajectory in Python: Step‑by‑Step Guide

This article explains how to simulate and draw the parabolic path of a horizontally launched projectile using Python, covering the physics formulas, point‑generation logic, and Matplotlib visualization with a complete, runnable code example.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
Plotting a Parabolic Trajectory in Python: Step‑by‑Step Guide

Introduction

Based on a follower's request, this tutorial shows how to use Python to plot the solid line of a projectile's parabolic trajectory (horizontal launch with initial speed v).

1. Idea

The solution hinges on two points: calculating x and y coordinates from acceleration formulas, and then plotting these points. The physics formula for projectile motion is illustrated below.

2. Analysis

Previously we stored coordinates in a list; here we improve the approach by using a list comprehension to generate all points at once. The total height can be set arbitrarily, and horizontal and vertical positions are computed from the formulas before calling the plotting function.

3. Implementation

# coding: utf-8
import matplotlib.pyplot as plt
import numpy as np
import math

def pwx(v0, h):
    g = 9.8
    H = 5 * h
    t = math.sqrt(H/g)
    x = [v0 * t for t in np.arange(0, t, 0.1)]
    y = [H - 0.5 * g * t * t for t in np.arange(0, t, 0.1)]
    plt.title("Parabolic trajectory curve")
    plt.xlabel("x")
    plt.ylabel("y")
    plt.plot(x, y)  # plotting x and y
    plt.show()

if __name__ == "__main__":
    v = int(input("请输入初速度v:  "))
    h = int(input("请输入绘制行数h:  "))
    pwx(v, h)

Running the script in PyCharm and entering an initial speed of 5 and a plot height of 10 produces the following execution screenshot:

The Matplotlib library then displays a perfect parabolic curve:

Conclusion

This guide demonstrates one practical method to generate and plot the parabolic trajectory of a projectile using Python, fulfilling the follower's request and providing a foundation for further enhancements.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

Data visualizationphysics simulationMatplotlibParabolic Motion
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.