RatInABox-Lab / RatInABox

A python package for simulating motion in continuous environments and spatial cell types (e.g. place cell).
MIT License
189 stars 31 forks source link

Error in ratinabox/Agent.py animate_trajectory #10

Closed marcoabrate closed 1 year ago

marcoabrate commented 1 year ago

Hi Tom,

Probably because of an update in matplotlib, the function animate_trajectory at ratinabox/Agent.py line 557 throws the error AttributeError: module 'matplotlib' has no attribute 'animation'.

You can replicate the error in matplotlib version 3.6.2:

>>> import matplotlib
>>> matplotlib.__version__
'3.6.2'
>>> matplotlib.animation
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/marco/miniconda3/envs/wp1/lib/python3.9/site-packages/matplotlib/_api/__init__.py", line 224, in __getattr__
    raise AttributeError(
AttributeError: module 'matplotlib' has no attribute 'animation'
>>> from matplotlib import animation
>>> animation
<module 'matplotlib.animation' from '/Users/marco/miniconda3/envs/wp1/lib/python3.9/site-packages/matplotlib/animation.py'>

The simple workaround is to import animation.

Full error message ``` --------------------------------------------------------------------------- AttributeError Traceback (most recent call last) Cell In [9], line 1 ----> 1 anim = agent.animate_trajectory(speed_up=10) File ~/phd/RatInABox/ratinabox/Agent.py:557, in Agent.animate_trajectory(self, t_start, t_end, speed_up) 554 return 556 fig, ax = self.plot_trajectory(0, 10 * self.dt) --> 557 anim = matplotlib.animation.FuncAnimation( 558 fig, 559 animate, 560 interval=40, 561 frames=int((t_end - t_start) / (40e-3 * speed_up)), 562 blit=False, 563 fargs=(fig, ax, t_start, t_end, speed_up), 564 ) 565 return anim File ~/miniconda3/envs/wp1/lib/python3.9/site-packages/matplotlib/_api/__init__.py:224, in caching_module_getattr..__getattr__(name) 222 if name in props: 223 return props[name].__get__(instance) --> 224 raise AttributeError( 225 f"module {cls.__module__!r} has no attribute {name!r}") AttributeError: module 'matplotlib' has no attribute 'animation' ```
TomGeorge1234 commented 1 year ago

Hi Marco, thanks for raising this, it's actually a known error and will be fixed in the next update (coming soon). In the meantime, from matplotlib import animation into your own script as a solution.

Cheers!!

TomGeorge1234 commented 1 year ago

Thanks again, the line from matplotlib import animation has been added to the relevant modules so this problem is now fixed. I will close this issue