One hot gym prediction or anomaly - plotting error

Getting the following error when running python --plot:

Traceback (most recent call last):
  File "", line 151, in <module>
    runModel(GYM_NAME, plot=plot)
  File "", line 141, in runModel
    runIoThroughNupic(inputData, model, gymName, plot)
  File "", line 98, in runIoThroughNupic
    output = nupic_output.NuPICPlotOutput([gymName])
  File "/home/neo/Projects/nupic/examples/opf/clients/hotgym/prediction/one_gym/", line 116, in __init__
NameError: global name 'plt' is not defined

This is because matplotlib is unreliable in many environments (yours!).

You need to figure how to get it installed on your OS in python properly.

1 Like

Ah, getting closer to the issue:

>>> import matplotlib.pyplot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/neo/.local/lib/python2.7/site-packages/matplotlib/", line 115, in <module>
    _backend_mod, new_figure_manager, draw_if_interactive, _show = pylab_setup()
  File "/home/neo/.local/lib/python2.7/site-packages/matplotlib/backends/", line 63, in pylab_setup
    [backend_name], 0)
  File "/home/neo/.local/lib/python2.7/site-packages/matplotlib/backends/", line 4, in <module>
    from . import tkagg  # Paint image to Tk photo blitter extension.
  File "/home/neo/.local/lib/python2.7/site-packages/matplotlib/backends/", line 5, in <module>
    from six.moves import tkinter as Tk
  File "/home/neo/.local/lib/python2.7/site-packages/", line 203, in load_module
    mod = mod._resolve()
  File "/home/neo/.local/lib/python2.7/site-packages/", line 115, in _resolve
    return _import_module(self.mod)
  File "/home/neo/.local/lib/python2.7/site-packages/", line 82, in _import_module
  File "/usr/lib/python2.7/lib-tk/", line 42, in <module>
    raise ImportError, str(msg) + ', please install the python-tk package'
ImportError: No module named _tkinter, please install the python-tk package


sudo apt-get install python-tk

And now it is working.
Thank you very much for the clue!

1 Like

Hey :blush:

I have an issue if the plot as well.
I could import everything in the files, so also this part

  import matplotlib
  import matplotlib.pyplot as plt
  import matplotlib.gridspec as gridspec
  from matplotlib.dates import date2num
except ImportError:

by using as second line the following:

matplotlib.use('TKAgg',warn=False, force=True)

I know this is not really a specific HTM Problem. But I searched on the Internet for a looooooong time, without finding a solution. So sorry to annoy here with that, but I hope that maybe someone had the same problem and can help me with that.

The thing is, that I got a figure in a new window, but it does not show anything. Just at the very end, I can see some results (just the very last days) .

I would really appreciate any help :hugs::slightly_smiling_face:
thanks to everyone in advance. :partying_face::partying_face::partying_face: