0

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()
2
  • Don't have a function named as main Commented Apr 19, 2018 at 3:21
  • 1
    fix your indentation Commented Apr 19, 2018 at 3:22

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.