clawpack / visclaw

Clawpack visualization tools
http://www.clawpack.org
BSD 3-Clause "New" or "Revised" License
29 stars 47 forks source link

matplotlib version 3 issue #244

Closed cheginit closed 4 years ago

cheginit commented 5 years ago

I have installed clawpack from git repo with matplotlib version 3 and python 3.7. When I try to run any example it fails at the animate step with the following error:

2019-06-25 08:29:06,839 INFO CLAW: Animation.save using <class 'clawpack.visclaw.plotpages.plotclaw_driver.<locals>.myHTMLWriter'>
Traceback (most recent call last):
  File "/home/taher/repositories/github/clawpack/visclaw/src/python/visclaw/plotclaw.py", line 166, in <module>
    plotclaw(sys.argv[1], sys.argv[2], sys.argv[3])
  File "/home/taher/repositories/github/clawpack/visclaw/src/python/visclaw/plotclaw.py", line 152, in plotclaw
    plotpages.plotclaw_driver(plotdata, verbose=False, format=format)
  File "/home/taher/repositories/github/clawpack/visclaw/src/python/visclaw/plotpages.py", line 2744, in wrapper
    return f(*args, **kwds)
  File "/home/taher/repositories/github/clawpack/visclaw/src/python/visclaw/plotpages.py", line 3079, in plotclaw_driver
    anim.save(fname, writer=myHTMLwriter)
  File "/home/taher/applications/anaconda/envs/claw/lib/python3.7/site-packages/matplotlib/animation.py", line 1156, in save
    writer.grab_frame(**savefig_kwargs)
  File "/home/taher/applications/anaconda/envs/claw/lib/python3.7/contextlib.py", line 119, in __exit__
    next(self.gen)
  File "/home/taher/applications/anaconda/envs/claw/lib/python3.7/site-packages/matplotlib/animation.py", line 232, in saving
    self.finish()
  File "/home/taher/applications/anaconda/envs/claw/lib/python3.7/site-packages/matplotlib/animation.py", line 528, in finish
    MovieWriter.finish(self)  # Will call clean-up
  File "/home/taher/applications/anaconda/envs/claw/lib/python3.7/site-packages/matplotlib/animation.py", line 367, in finish
    self.cleanup()
  File "/home/taher/applications/anaconda/envs/claw/lib/python3.7/site-packages/matplotlib/animation.py", line 531, in cleanup
    MovieWriter.cleanup(self)
  File "/home/taher/applications/anaconda/envs/claw/lib/python3.7/site-packages/matplotlib/animation.py", line 399, in cleanup
    out = TextIOWrapper(BytesIO(out)).read()
TypeError: a bytes-like object is required, not 'str'
/home/taher/repositories/github/clawpack/clawutil/src/Makefile.common:234: recipe for target 'plots' failed
make[2]: *** [plots] Error 1
make[2]: Leaving directory '/home/taher/repositories/Research/codes/coastal/src/mobile_bay'
/home/taher/repositories/github/clawpack/clawutil/src/Makefile.common:229: recipe for target '.plots' failed
make[1]: *** [.plots] Error 2
make[1]: Leaving directory '/home/taher/repositories/Research/codes/coastal/src/mobile_bay'
Makefile:66: recipe for target 'all' failed
make: *** [all] Error 2

When I downgrade matplotlib to version 2.2.3 it works without any issue. So something has changed in version 3 which is not compatible with version 2.

ketch commented 5 years ago

@taataam Thanks for reporting this; I did see that something changed in matplotlib recently that broke our usual way of using ianimate. You haven't included exactly what you did that threw this error. But if you want to use ianimate in a Jupyter notebook now you need to do something like

from IPython.display import HTML
anim = ianimate(claw)
HTML(anim.to_jshtml())

I will probably incorporate this inside the ianimate function when I have time.

cheginit commented 5 years ago

@ketch I just ran make all for a couple of example cases from a terminal. Thanks for the tip though, I'll give it a try.

ketch commented 5 years ago

Ah, looking at your traceback now I see that you weren't calling ianimate at all. Still, I think this is the same bug, caused by a change in matplotlib. Leave this issue open; we need to fix it.

rjleveque commented 5 years ago

Yes, it looks like we need to update the way JS animations are created in plotpages.py

File "/home/taher/repositories/github/clawpack/visclaw/src/python/visclaw/plotpages.py", line 3079, in plotclaw_driver
    anim.save(fname, writer=myHTMLwriter)
cheginit commented 5 years ago

Great, thanks.