Created
October 9, 2024 00:07
-
-
Save Yonah1504/fe724866269d44c5326dc970498032be to your computer and use it in GitHub Desktop.
scatter plot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import math | |
# Buat data titik (x, y) | |
x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | |
y = [0, 1, 2, 1, 0, 1, 3, 5, 3, 1, 0] | |
# Buat scatter plot | |
plt.scatter(x, y) | |
# Tambahkan grid | |
plt.grid() | |
# Beri label pada sumbu x dan y | |
plt.xlabel('t') | |
plt.ylabel('x') | |
# Tampilkan plot | |
plt.show() | |
import matplotlib.pyplot as plt | |
# Tentukan jumlah data | |
N = 20 | |
# Buat list nilai x dari 0 hingga N | |
x = [*range(0, N+1)] | |
# Hitung nilai y berdasarkan rumus tertentu | |
y = [(i-4)*(i-10)*(i-16) for i in x] | |
# Buat scatter plot | |
plt.scatter(x, y) | |
# Tambahkan grid | |
plt.grid() | |
# Beri label pada sumbu x dan y | |
plt.xlabel('x') | |
plt.ylabel('y') | |
# Tampilkan plot | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment