Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/284.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 为什么我不能在循环中保存图像?_Python_Numpy_Matplotlib - Fatal编程技术网

Python 为什么我不能在循环中保存图像?

Python 为什么我不能在循环中保存图像?,python,numpy,matplotlib,Python,Numpy,Matplotlib,我试图用不同的名称在循环中保存图像。我的代码正在执行,但没有保存文件。这似乎是在发出警告 y1 = linspace(0.51,0.61,0.01,endpoint=True) y2 = linspace(0.52,0.62,0.01,endpoint=True) name = linspace(1,11,1,endpoint=True) for i,j,k in zip(y1,y2,name): fig,ax = plt.subplots() A = (a**2)*

我试图用不同的名称在循环中保存图像。我的代码正在执行,但没有保存文件。这似乎是在发出警告

y1   = linspace(0.51,0.61,0.01,endpoint=True)
y2   = linspace(0.52,0.62,0.01,endpoint=True)
name = linspace(1,11,1,endpoint=True)

for i,j,k in zip(y1,y2,name):

    fig,ax = plt.subplots()
    A = (a**2)*sin(p)*sqrt(1-sin(p)*sin(p))
    B = (a*b*d)/(sin(p)**2)
    C = a*b*d
    D = a*c*sqrt(1-sin(p)*sin(p))
    E = a*c*sin(p)*sqrt(1-sin(p)*sin(p))
    F = (b*c*d)/(sin(p)**3)
    G = (b*c*d)/sin(p)

    H = a*d* (   (a/(sin(p)*sin(p))) - a + (c/(sin(p)**3)) - (c/(sin(p))) )

    t = abs((A+B-C+D+E+F-G) / (H))

    ax.scatter(angle_degrees,t)
    ax.xlim(0,-90)
    ax.ylim(i,j)
    ax.set_xlabel('Angle', fontsize=16)
    ax.set_ylabel('Time', fontsize=16)
    ax.set_title('Formula 1', fontsize=16)
    plt.savefig('A{}.png'.format(k))
我不明白是什么问题。虽然有一个警告

DeprecationWarning: object of type <class 'float'> cannot be
safely interpreted as an integer.
app.launch_new_instance()
DeprecationWarning:类型的对象不能为
安全地解释为整数。
app.launch_new_instance()

这次我拿到了。linspace中的参数是错误的。我把它当作是阿兰奇。我的错。以下是正确的代码:

y1   = linspace(0.51,0.61,10,endpoint=True)
y2   = linspace(0.52,0.62,10,endpoint=True)
name = linspace(1,11,10,endpoint=True)

for i,j,k in zip(y1,y2,name):

    fig,ax = plt.subplots()
    A = (a**2)*sin(p)*sqrt(1-sin(p)*sin(p))
    B = (a*b*d)/(sin(p)**2)
    C = a*b*d
    D = a*c*sqrt(1-sin(p)*sin(p))
    E = a*c*sin(p)*sqrt(1-sin(p)*sin(p))
    F = (b*c*d)/(sin(p)**3)
    G = (b*c*d)/sin(p)

    H = a*d* (   (a/(sin(p)*sin(p))) - a + (c/(sin(p)**3)) - (c/(sin(p))) )

    t = abs((A+B-C+D+E+F-G) / (H))

    ax.scatter(angle_degrees,t)
    ax.xlim(0,-90)
    ax.ylim(i,j)
    ax.set_xlabel('Angle', fontsize=16)
    ax.set_ylabel('Time', fontsize=16)
    ax.set_title('Formula 1', fontsize=16)
    plt.savefig('A{}.png'.format(k))

谢谢你的评论,guyz。

你是在哪里创建这个数字的?你应该在每次循环时创建一个新的图形。有趣的是,也许可以添加一些调试消息以查看失败的地方。我尝试过,但也没有成功。更新代码@BenTYour使用linspace时出现错误。检查那些阵列。在使用文件之前先打印文件名。