I'm trying to plot a function which is an object of numpy.poly1d. In my case it is y = -x^2 + 7x -7
. So now I'm trying to plot it like a nice parabola, however when I plot it, it looks like this:
So I wondered if anybody could tell me how to make this line smooth.
This is my code:
t = np.poly1d([-1, 7, -7])
plt.plot(t)
plt.show()
poly1d(c_or_r, r=False, variable=None)[source] A one-dimensional polynomial class. Note. This forms part of the old polynomial API. Since version 1.4, the new polynomial API defined in numpy.
poly() function in the Sequence of roots of the polynomial returns the coefficient of the polynomial. Parameters : Seq : sequence of roots of the polynomial roots, or a matrix of roots. Return: 1D array having coefficients of the polynomial from the highest degree to the lowest one.
np.poly1d()
creates a polynomial. If you plot that, you only get its coefficient values, of which you have 3. So effectively you plot 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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With