I've tried to rewrite code for a plot from R into Python, but have gotten a resulting diagram that doesn't look right. The dots of the Python scatter plot seem to fall on one line. Am wondering if I've used the wrong function in np.random.normal in replacing rnorm?
Here's the original R code:
g <- 9.8 ##meters per second
n <- 25
tt <- seq(0,3.4,len=n) ##time in secs, t is a base function
f <- 56.67 - 0.5*g*tt^2
y <- f + rnorm(n,sd=1)
plot(tt,y,ylab="Distance in meters",xlab="Time in seconds")
lines(tt,f,col=2)
Here's the attempted rewrite in Python:
import numpy as np
import matplotlib.pyplot as plt
g = 9.8 # meters per second
n = 25
tt = np.linspace(0, 3.4, num = n)
f = 56.67 - 0.5 * g * tt**2
y = f + np.random.normal(n, scale=1.0)
plt.scatter(tt, y, edgecolor="black", facecolors="white")
plt.plot(tt, f, color="orange")
plt.xlabel("Time in seconds")
plt.ylabel("Distance in meters")
plt.show()

