Python Forum

Full Version: Plot list
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I need your help
How can I plot a list of numbers? Because I don't want to plot point by point.
In my example I want to plot the x-values when k(x)=0

import sympy as sp
import numpy as np
import matplotlib.pyplot as plt
sp.var('x',real=True)
def k(x):
    return (x***4)-(3*x***3)+((7/4)*x**2)+((3/4)*x)-1
xx=np.linspace(-2,2,100)
plt.figure()
plt.plot(xx,k(xx))
plt.show()
a= sp.solve(k(x));a

plt.figure()
plt.plot(xx,k(xx))
plt.plot(a,k(a),'+')#doesn't work
plt.show()

plt.figure()
plt.plot(xx,k(xx))
plt.plot(a[0],k(a[0]),'+')#work but I want for all the terms also when there are 100 terms in a
plt.show()'`
The recived error message
Error:
TypeError: unsupported operand type(s) for ** or pow(): 'list' and 'int'
Thanks for all!
What does x***4 mean in your code? Probably x**4?

Try to pass np.array(a) to k, i.e.:

plt.plot(a, k(np.array(a)),'+') #doesn't work
Yes it's x**4,

Thanks for your respons, it's the what I want ;)
I try it before but it didn't, maybe I did an other mistake