daleroberts / itermplot

An awesome iTerm2 backend for Matplotlib, so you can plot directly in your terminal.
1.49k stars 51 forks source link

Crash if ITERMPLOT_FRAMES is set but the script does not have animation #14

Closed garywu closed 7 years ago

garywu commented 7 years ago

When ITERMPLOT_FRAMES is not defined, script works as expected:

$ env | grep MPLBACKEND
MPLBACKEND=module://itermplot
$ env | grep ITERMPLOT_FRAMES
$ python docs/simple.py

test

However, if ITERMPLOT_FRAMES is defined, script without animation crashes:

$ ITERMPLOT_FRAMES=1 python docs/simple.py
Traceback (most recent call last):
  File "docs/simple.py", line 3, in <module>
    plt.show()
  File "/Users/admin/anaconda/envs/py3k/lib/python3.5/site-packages/matplotlib/pyplot.py", line 252, in show
    return _show(*args, **kw)
  File "/Users/admin/code/itermplot/itermplot/__init__.py", line 119, in show
    figmanager.show()
  File "/Users/admin/code/itermplot/itermplot/__init__.py", line 250, in show
    data = self.animate(loops, outfile)
  File "/Users/admin/code/itermplot/itermplot/__init__.py", line 228, in animate
    self.canvas.timer._on_timer()
AttributeError: 'FigureCanvasItermplot' object has no attribute 'timer'

The problem is when ITERMPLOT_FRAMES is defined itermplot expects the animation module to call new_timer to initialise the timer before calling show. For scripts that don't have animation, the timer was never initialized.

itermplot should work as no ITERMPLOT_FRAMES is set when the script does not call animation.