0
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.animation as animation

def rectangle_random_walk3(n, w, l):
  bounces = 0
  x = 0
  y = 0 
  path = [(x, y)]  
  for i in range(n):
    
      if np.random.rand() < 0.5:
          x = x + 1  
      else:
          x = x - 1
      if np.random.rand() < 0.5:
          y = y + 1  
      else:
          y = y - 1  

      if abs(x) > w/2:
        x = x - 1
        bounces = bounces + 1
      if abs(y) > l/2:
        y = y - 1
        bounces = bounces + 1
    
      path.append((x, y))

  xar = []
  yar = []
  for x, y in path:
    xar.append(x)
    yar.append(y)

  fig, ax = plt.subplots()
  ax.set_xlim(-w, w)
  ax.set_ylim(-l, l)
  graph, = plt.plot([], [], '-')

  def init():
    return graph,

  def animate(i):
    graph.set_data(xar[:i],yar[:i])
    return graph,

  ani = animation(fig, animate, frames=range(len(xar)), interval=50, save_count=len(xar), init_func=init, blit=True)
  ani.plot('random_walk.gif')

The code for the animation came from this thread

I am getting 'module' object is not callable on this line: ani = animation(fig, animate, frames=range(len(xar)), interval=50, save_count=len(xar), init_func=init, blit=True

I've tried to research what the error code is, and what a module is but my problem is that I don't know which the of parameters is the problem or what is even making something into a module

  • 2
    `matplot.animation` is a module. I suspect you wanted `animation.FuncAnimation` there. – Tim Roberts Mar 14 '23 at 05:40
  • Please trim your code to make it easier to find your problem. Follow these guidelines to create a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). – Blue Robin Mar 15 '23 at 00:04

0 Answers0