Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Plot list
#1
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!
Reply
#2
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
Reply
#3
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to plot intraday data of several days in one plot mistermister 3 2,854 Dec-15-2020, 07:43 PM
Last Post: deanhystad
  Plot data from list. Makada 0 1,755 Jan-22-2020, 10:58 AM
Last Post: Makada
  How to plot vertically stacked plot with same x-axis and SriMekala 0 1,885 Jun-12-2019, 03:31 PM
Last Post: SriMekala
  How to plot two list on the same graph with different colors? Alberto 2 28,695 Jul-18-2017, 09:20 AM
Last Post: Alberto

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020