# Hotgym prediction example problem with --plot

**URL:** https://discourse.numenta.org/t/hotgym-prediction-example-problem-with-plot/5459
**Category:** NuPIC
**Created:** [February 16, 2019, 2:56pm UTC](https://discourse.numenta.org/t/hotgym-prediction-example-problem-with-plot/5459 "2019-02-16T14:56:10Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![simon.1](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@simon.1](https://discourse.numenta.org/u/simon.1)
#### Post date: [February 16, 2019, 2:56pm UTC](https://discourse.numenta.org/t/hotgym-prediction-example-problem-with-plot/5459/1 "2019-02-16T14:56:10Z")

</div>

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 ./run.py” 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 nupic\_output.py), i.e.:

from

```auto
 import matplotlib
 matplotlib.use('TKAgg')  

```

to

```auto
import matplotlib
matplotlib.use('Agg')

```

But this then gives a new error:

```auto
  File "./run.py", line 151, in <module>
    runModel(GYM_NAME, plot=plot)
  File "./run.py", line 141, in runModel
    runIoThroughNupic(inputData, model, gymName, plot)
  File "./run.py", line 127, in runIoThroughNupic
    output.write([timestamp], [consumption], [prediction])
  File "/usr/local/src/nupic/examples/opf/clients/hotgym/prediction/one_gym/nupic_output.py", line 171, in write
    self.initializeLines(timestamps)
  File "/usr/local/src/nupic/examples/opf/clients/hotgym/prediction/one_gym/nupic_output.py", line 151, in initializeLines
    self.dates[index], self.actualValues[index]
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/ __init__.py", line 1867, in inner
    return func(ax, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_axes.py", line 1528, in plot
    for line in self._get_lines(*args, **kwargs):
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 406, in _grab_next_args
    for seg in self._plot_args(this, kwargs):
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 383, in _plot_args
    x, y = self._xy_from_xy(x, y)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 215, in _xy_from_xy
    bx = self.axes.xaxis.update_units(x)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1474, in update_units
    self._update_axisinfo()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1492, in _update_axisinfo
    self.set_major_locator(info.majloc)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1597, in set_major_locator
    self.stale = True
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 241, in stale
    self.stale_callback(self, val)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 68, in _stale_axes_callback
    self.axes.stale = val
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 241, in stale
    self.stale_callback(self, val)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 60, in _stale_figure_callback
    self.figure.stale = val
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 241, in stale
    self.stale_callback(self, val)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/pyplot.py", line 577, in _auto_draw_if_interactive
    fig.canvas.draw_idle()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backend_bases.py", line 2055, in draw_idle
    self.draw(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/backends/backend_agg.py", line 437, in draw
    self.figure.draw(self.renderer)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/figure.py", line 1493, in draw
    renderer, self, artists, self.suppressComposite)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
    a.draw(renderer)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axes/_base.py", line 2635, in draw
    mimage._draw_list_compositing_images(renderer, self, artists)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/image.py", line 141, in _draw_list_compositing_images
    a.draw(renderer)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/artist.py", line 55, in draw_wrapper
    return draw(artist, renderer, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", line 1190, in draw
    ticks_to_draw = self._update_ticks(renderer)
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/axis.py", 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/axis.py", line 971, in iter_ticks
    majorLocs = self.major.locator()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/dates.py", line 1249, in __call__
    self.refresh()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/dates.py", line 1269, in refresh
    dmin, dmax = self.viewlim_to_dt()
  File "/usr/local/lib/python2.7/dist-packages/matplotlib/dates.py", line 1026, in viewlim_to_dt
    .format(vmin))
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 matplotlib.dates.py 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:

```auto
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))
      self.convertedDates.append(deque(
        [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))
      print(self.dates[index])
      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).

Simon

---

<div class="post-metadata">

### Author: ![rhyolight](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.numenta.org/rhyolight/32/3922_2.png) [@rhyolight](https://discourse.numenta.org/u/rhyolight)
#### Post date: [February 17, 2019, 1:03am UTC](https://discourse.numenta.org/t/hotgym-prediction-example-problem-with-plot/5459/2 "2019-02-17T01:03:09Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![simon.1](https://avatars.discourse-cdn.com/v4/letter/s/9d8465/32.png) [@simon.1](https://discourse.numenta.org/u/simon.1)
#### Post date: [February 17, 2019, 7:33pm UTC](https://discourse.numenta.org/t/hotgym-prediction-example-problem-with-plot/5459/3 "2019-02-17T19:33:31Z")

</div>

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:

```auto
sudo docker run --name nupic \
-e NTA_CONF_PROP_nupic_cluster_database_passwd=nupic \
-e NTA_CONF_PROP_nupic_cluster_database_host=mysql \
-e DISPLAY=unix$DISPLAY \
-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:

```auto
$ sudo docker inspect nupic

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

```

Then do:

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

```

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

```auto
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 nupic\_output.py).

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

Simon.
