Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在plt.show()上使用numpy和matplotlib打印,不显示_Python_Matplotlib - Fatal编程技术网

Python 在plt.show()上使用numpy和matplotlib打印,不显示

Python 在plt.show()上使用numpy和matplotlib打印,不显示,python,matplotlib,Python,Matplotlib,因此,我试图得到一个图来显示,我能够为所述图形生成框,其中x轴和y轴标记为必要的,但是线/函数本身没有显示。我的代码中是否存在某种我没有注意到的问题 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:

因此,我试图得到一个图来显示,我能够为所述图形生成框,其中x轴和y轴标记为必要的,但是线/函数本身没有显示。我的代码中是否存在某种我没有注意到的问题

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()

问题在于,X和Y是包含点数组的列表,而plot采用点数组。如果确实需要X和Y是包含数组的列表,那么需要调用plt.plotX[0],Y[0]这样的plot。不过,通常情况下,X和Y直接等于数组。

没有名为main的函数来修复缩进