[Python] Parameter not found although present in function call (don't understand the syntax)...

Discussão em 'Python' iniciado por Stack, Abril 23, 2025.

  1. Stack

    Stack Membro Participativo

    This code doesnt compile it gives an error message. TypeError: update() missing 1 required positional argument: 'posY'

    Why is it missing "posY" although i have given this parameter to the function? I gave it "posX", too and it does not complain about not finding it.

    fig, ax = plt.subplots()
    posX = 0
    posY = 0
    scat = ax.scatter(pos, 0, c="b", s=5, label=f'der sich bewegende punkt')
    ax.set(xlim=[-5, 5], ylim=[-1, 1], xlabel='Ort', ylabel='garnix is 1D')
    ax.legend()


    def update(frame, posX, posY):
    # for each frame, update the data stored on each artist.
    x = posX + random.gauss()
    y = posY + random.gauss()
    posX = posX + random.gauss()
    posY = posY + random.gauss()
    # update the scatter plot:
    scat.set_offsets([x,y])
    return (x,y)

    ani = animation.FuncAnimation(fig=fig, func=update(posX, posY), frames=240, interval=50)
    ani.save('test.mp4')


    I expected it to run well. Just as the code below

    fig, ax = plt.subplots()
    pos = 0
    scat = ax.scatter(pos, 0, c="b", s=5, label=f'der sich bewegende punkt')
    ax.set(xlim=[-5, 5], ylim=[-1, 1], xlabel='Ort', ylabel='garnix is 1D')
    ax.legend()


    def update(frame):
    # for each frame, update the data stored on each artist.
    x = pos + random.gauss()`
    # update the scatter plot:
    scat.set_offsets([x,0])
    return (x)


    ani = animation.FuncAnimation(fig=fig, func=update, frames=40, interval=30)
    ani.save('test.mp4')

    Continue reading...

Compartilhe esta Página