The following code is the minimum example of a error that I'm not sure how to solve it.
import matplotlib.pyplot as plt
import numpy as np
x = [1, 2, 3, 4, 5]
y = [5, 4, 3, 2, 1]
a, b, c = np.polyfit(x, y, 2)
fig, ax = plt.subplots()
ax.plot(x, a*x)
What am I doing wrong?
CodePudding user response:
You were trying to multiply a list with a non-integer. Instead, use numpy arrays
import matplotlib.pyplot as plt
import numpy as np
x = np.array([1, 2, 3, 4, 5])
y = np.array([5, 4, 3, 2, 1])
a, b, c = np.polyfit(x, y, 2)
fig, ax = plt.subplots()
ax.plot(x, a*x)
plt.show()