Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/276.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/visual-studio-2012/2.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 matplotlib()缺少1个必需的位置参数:';i';_Python_Matplotlib_Tkinter - Fatal编程技术网

Python matplotlib()缺少1个必需的位置参数:';i';

Python matplotlib()缺少1个必需的位置参数:';i';,python,matplotlib,tkinter,Python,Matplotlib,Tkinter,当我尝试使用按钮运行函数时,问题就出现了。无需使用按钮即可正常工作。我得到了错误 matplotlib()缺少1个必需的位置参数:“i” 我试着通过简单地删除这个,我,然后我得到了错误 matplotlib()接受0个位置参数,但给出了1个 我还试着在我的按钮中的command=matplotlib(I)之后加上(I),我的图形变成空白,然后我得到了这个错误 matplotlib()接受0个位置参数,但给出了1个 我只是想找出如何制作一个活动的图形,我,甚至是什么意思,我不知道为什么只有当我在T

当我尝试使用按钮运行函数时,问题就出现了。无需使用按钮即可正常工作。我得到了错误

matplotlib()缺少1个必需的位置参数:“i”

我试着通过简单地删除这个,我,然后我得到了错误

matplotlib()接受0个位置参数,但给出了1个

我还试着在我的按钮中的command=matplotlib(I)之后加上(I),我的图形变成空白,然后我得到了这个错误

matplotlib()接受0个位置参数,但给出了1个


我只是想找出如何制作一个活动的图形,我,甚至是什么意思,我不知道为什么只有当我在Tkinter中用一个按钮运行它时,它才起作用。

基于您现在拥有的matplotlib(I)-我真的没有在您的函数中使用,所以我会删除它,所以请更改matplotlib(I)中的定义到matplotlib()

根据评论对其进行编辑。

def matplotlib(i):

    graph_data = open('sampleData.txt', 'r').read()
    lines = graph_data.split('\n')
    xs = []
    ys = []
    for line in lines:
        if len(line) >1:
            x, y = line.split(',')
            xs.append(x)
            ys.append(y)

    fig.clear()

    'Limits'
    ax = plt.gca()
    ax.set_xlim([80, -80])
    ax.set_ylim([42, -42])
    plt.axis('equal')

    'Labels'
    plt.xticks([-16, -32, -48, -64, -80, 0, 16, 32, 48, 64, 80])
    plt.yticks([-42, -28, -14, 0, 14, 28, 42])

    plt.show()

    plt.scatter(xs, ys)

'Toolbar Buttons'

insertButt = Button(toolbar, text="Matplotlib TST", fg='Dark Red', bg="Dim Grey", activebackground='Dim Grey',
                    activeforeground='Dark Red', command=matplotlib).pack(side=LEFT, padx=2, pady=2)

ani = animation.FuncAnimation(fig, matplotlib, interval=1000)
执行函数
matplotlib()
,不带参数

但是这个

command=matplotlib
使用一个参数执行相同的函数

因此,如果使用
def matplotlib(i):
def matplotlib():

您没有在
matplotlib()中使用
i
,因此可以指定默认值
None

FuncAnimation( matplotlib ) 
无论有无争论,它都会起作用



FuncAnimation
将“当前帧号”发送为
i
,您可以使用从列表中获取不同的值(显示它)或生成不同的绘图(即
sin(i)
)。

您的上一句话,或者至少是误导性的。将函数与按钮关联时,不包括括号。
def matplotlib(i=None):