Plot list - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Plot list (/thread-18497.html) |
Plot list - arthurvercruysse - May-20-2019 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 Thanks for all!
RE: Plot list - scidam - May-20-2019 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 RE: Plot list - arthurvercruysse - May-20-2019 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 |