Plot the curve of
f(x)=sin(x)
import numpy as np
import matplotlib.pyplot as plt
plt.figure(1, dpi=80)
x = np.linspace(-np.pi, np.pi, 100)
plt.plot(x, np.sin(x))
plt.grid()
plt.show()
Plot the curve of
f(x)=|x2−30|
plt.figure(1, dpi=80)
x = np.linspace(-10, 10, 100)
plt.plot(x, np.abs(x*x-30))
plt.grid()
plt.show()
N = 10
x = np.random.rand(N)
y = np.random.rand(N)
plt.scatter(x, y)
plt.grid()
plt.show()
x = range(1, 21)
y = [3, 4, 5, 5, 2, 4, 7, 8, 11, 8, 12,
11, 13, 13, 16, 17, 18, 17, 19, 21]
plt.scatter(x, y)
x1 = np.linspace(1, 20, 100)
plt.plot(x1, 0.516 + 0.970 * x1, color='red')
plt.grid()
plt.show()