Hotgym prediction example problem with --plot

I am new to HTM - just completed the full set of HTM-school videos - which are great!

I have a problem with the hotgym/prediction/one-gym example. I am using Ubuntu 18.10

I have installed nupic and nupic-mysql as docker containers and successfully run the swarm to get a good model. I can then do “python ./” to output predictions to file correctly. But I cannot get the --plot option to work. I have installed matplotlib using pip. At first this gave en error but I was able to fix this by changing “TKAgg” to “Agg” (in file, i.e.:


 import matplotlib


import matplotlib

But this then gives a new error:

  File "./", line 151, in <module>
    runModel(GYM_NAME, plot=plot)
  File "./", line 141, in runModel
    runIoThroughNupic(inputData, model, gymName, plot)
  File "./", line 127, in runIoThroughNupic
    output.write([timestamp], [consumption], [prediction])
  File "/usr/local/src/nupic/examples/opf/clients/hotgym/prediction/one_gym/", line 171, in write
  File "/usr/local/src/nupic/examples/opf/clients/hotgym/prediction/one_gym/", line 151, in initializeLines
    self.dates[index], self.actualValues[index]
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 1867, in inner
    return func(ax, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/", line 1528, in plot
    for line in self._get_lines(*args, **kwargs):
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/", line 406, in _grab_next_args
    for seg in self._plot_args(this, kwargs):
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/", line 383, in _plot_args
    x, y = self._xy_from_xy(x, y)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/", line 215, in _xy_from_xy
    bx = self.axes.xaxis.update_units(x)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 1474, in update_units
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 1492, in _update_axisinfo
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 1597, in set_major_locator
    self.stale = True
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 241, in stale
    self.stale_callback(self, val)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 68, in _stale_axes_callback
    self.axes.stale = val
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 241, in stale
    self.stale_callback(self, val)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 60, in _stale_figure_callback
    self.figure.stale = val
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 241, in stale
    self.stale_callback(self, val)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 577, in _auto_draw_if_interactive
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 2055, in draw_idle
    self.draw(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/", line 437, in draw
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 1493, in draw
    renderer, self, artists, self.suppressComposite)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 141, in _draw_list_compositing_images
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/", line 2635, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 141, in _draw_list_compositing_images
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 1190, in draw
    ticks_to_draw = self._update_ticks(renderer)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 1028, in _update_ticks
    tick_tups = list(self.iter_ticks())  # iter_ticks calls the locator
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 971, in iter_ticks
    majorLocs = self.major.locator()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 1249, in __call__
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 1269, in refresh
    dmin, dmax = self.viewlim_to_dt()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/", line 1026, in viewlim_to_dt
ValueError: view limit minimum 0.0 is less than 1 and is an invalid Matplotlib date value. This often happens if you pass a non-datetime value to an axis that has datetime units

I have examined the line in question in and what it seems to be complaining about is that there is a zero difference between the max and min values of the dates array. Which is not surprising since your code initially sets all 100 values to the same date:

def initializeLines(self, timestamps):
    for index in range(len(self.names)):
      print "initializing %s" % self.names[index]
      # graph = self.graphs[index]
      self.dates.append(deque([timestamps[index]] * WINDOW, maxlen=WINDOW))
        [date2num(date) for date in self.dates[index]], maxlen=WINDOW
      self.actualValues.append(deque([0.0] * WINDOW, maxlen=WINDOW))
      self.predictedValues.append(deque([0.0] * WINDOW, maxlen=WINDOW))
      actualPlot, = self.graphs[index].plot(
        self.dates[index], self.actualValues[index]   --- error here

I do not really understand what the above code is supposed to do (I am quite new to python also). Please can you help get this working for me (and others).


This is probably something to do with your local matplotlib setup. It varies on different operating systems. I had a hard time getting it to work for me years ago when I put this tutorial together. If you find out the code is wrong, please let me know.

I have fixed the problem. I have used docker containers a lot but never with a GUI. I did not know how to set this up - but now I do – and I think many others new to HTM will find the solution below helpful.

First when you run the docker container in the first place you need to do it like this:

sudo docker run --name nupic \
-e NTA_CONF_PROP_nupic_cluster_database_passwd=nupic \
-e NTA_CONF_PROP_nupic_cluster_database_host=mysql \
-v /tmp/.X11-unix:/tmp/.X11-unix \
--link nupic-mysql:mysql \
-ti numenta/nupic

On the host machine you need to enable access to the host’s X11 interface for the relevant docker container using its “Hostname”. Find this using:

$ sudo docker inspect nupic

The result includes:
"Config": {
            "Hostname": "fcf6bb178fdc",

Then do:

$ xhost +local:fcf6bb178fdc    (i.e the value of the Hostname found above)

From inside the container (for Ubuntu) install matplotlib as follows:

apt-get update
apt-get python-matplotlib

Now you can run the examples as per the original code (i.e. do not change “TkAgg” to “Agg” in

I think you should say something about running matplotlib from within a docker container somewhere in the nupic documentation – it is not obvious.


1 Like