Reputation: 7
So I am trying to get a plot to show and I am able to produce the box for said graph with the x and y axis labeled as necessary, however the line/function in itself is not showing. Is there some sort of issue in my code that I am not noticing?
import numpy as np
import math
import matplotlib.pyplot as plt
def main():
X = []
Y = []
x = np.arange(-1.5,1.6, 0.101)
X.append(x)
for x in X:
y = x**3 - x
Y.append(y)
X = list(X)
Y = list(Y)
print(X)
print(Y)
plt.xlabel("x")
plt.ylabel("y")
plt.plot(X,Y)
plt.show()
main()
Upvotes: 0
Views: 41
Reputation: 506
The problem is that X
and Y
are lists containing arrays of points, where plot
takes arrays of points. If you really need X
and Y
to be lists containing arrays, then you need to call plot
like plt.plot(X[0], Y[0])
. Typically, though, you would just have X
and Y
equal to arrays directly.
Upvotes: 1