Poly1d with Matplotlib

I am trying to build a function that is a numpy.poly1d object. In my case it is y = -x^2 + 7x -7. So now I'm trying to draw it like a beautiful parabola, however, when I draw it, it looks like this:

1

So I wondered if anyone could tell me how to make this line smooth.

This is my code:

t = np.poly1d([-1, 7, -7])

plt.plot(t)
plt.show()
+5
source share
1 answer

np.poly1d()creates a polynomial. If you built this value, you will only get its coefficient values, of which you have 3. Thus, you effectively create the values ​​-1, 7 and -7.

You want to pass some x values ​​to your polynomial to get the corresponding y values.

p = np.poly1d([-1, 7, -7])
x = np.arange(20)
y = p(x)
plt.plot(x, y)
plt.show()
+8
source

Source: https://habr.com/ru/post/1623659/


All Articles