title: "Unknown element o" when calling plot in EC2 instance
body: <p>I have an EC2 instance with everything needed installed and upgraded.</p>
  
  <p>I keep getting a warning and an error when I try to create a plot.</p>
  
  <p>The warning is:</p>
  
  <pre><code>MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.
  </code></pre>
  
  <p>The error that comes immediately afterwards:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/threading.py", line 916, in _bootstrap_inner
      self.run()
    File "/home/ec2-user/mnn/nn_tp_thread.py", line 241, in run
      plt.plot(mean_prediction_last_10)
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/matplotlib/pyplot.py", line 3347, in plot
      ax = gca()
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/matplotlib/pyplot.py", line 984, in gca
      return gcf().gca(**kwargs)
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/matplotlib/figure.py", line 1817, in gca
      return self.add_subplot(1, 1, 1, **kwargs)
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/matplotlib/figure.py", line 1240, in add_subplot
      self._axstack.add(key, a)
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/matplotlib/figure.py", line 142, in add
      Stack.remove(self, (key, a_existing))
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/matplotlib/cbook/__init__.py", line 1254, in remove
      raise ValueError('Unknown element o')
  ValueError: Unknown element o
  </code></pre>
  
  <p>My code is:</p>
  
  <pre><code>            thread_locker.acquire()
  
              mean_prediction_last_10 = mean_prediction[9:]
              mean_prediction_last_10
              plt.plot(mean_prediction_last_10)
              plt.title('Price Prediction - ' + str(datetime.datetime.now().time()))
              plt.xlabel('Time')
              plt.ylabel('Mean Price')
              plt.legend()
              # plt.show()
              fig = plt.figure()
              fig.savefig("/static/images/Last_prediction_"+ timeframe +".png")
              thread_locker.release()
  </code></pre>
  
  <p>I have searched and tried many things but with no success. Any suggestions?</p>
  
  <p><strong>EDIT:</strong>
  Changing my code to clear any figures and plots (although there shouldn't exist any):</p>
  
  <pre><code>            thread_locker.acquire()
              plt.clf()
              plt.close()
              mean_prediction_last_10 = mean_prediction[9:]
              plt.plot(mean_prediction_last_10)
              fig = plt.figure()
              plt.title('Price Prediction - ' + str(datetime.datetime.now().time()))
              plt.xlabel('Time')
              plt.ylabel('Mean Price')
              plt.legend()
              # plt.show()
  
              fig.savefig("/static/images/Last_prediction_"+ timeframe +".png")
              thread_locker.release()
  </code></pre>
  
  <p>I get a message like:</p>
  
  <pre><code>No handles with labels found to put in legend.
  </code></pre>
  
  <p>and a different error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/threading.py", line 916, in _bootstrap_inner
      self.run()
    File "/home/ec2-user/mnn/nn_tp_thread.py", line 237, in run
      plt.clf()
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/matplotlib/pyplot.py", line 686, in clf
      gcf().clf()
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/matplotlib/figure.py", line 1413, in clf
      self.delaxes(ax)         # removes ax from self._axstack
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/matplotlib/figure.py", line 1007, in delaxes
      self._axstack.remove(ax)
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/matplotlib/figure.py", line 113, in remove
      Stack.remove(self, self._entry_from_axes(a))
    File "/home/ec2-user/anaconda3/envs/tensorflow_p36/lib/python3.6/site-packages/matplotlib/figure.py", line 108, in _entry_from_axes
      ind, k = {a: (ind, k) for k, (ind, a) in self._elements}[e]
  KeyError: &lt;matplotlib.axes._subplots.AxesSubplot object at 0x7f165b4e10b8&gt;
  </code></pre>