У меня есть экземпляр EC2 со всем необходимым, установленным и обновленным.
Я получаю предупреждение и ошибку при попытке создать график.
Предупреждение:
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.
Ошибка, которая возникает сразу после:
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
Мой код:
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()
Я искал и пробовал много вещей, но безуспешно. Есть предложения?
EDIT:
Изменение моего кода, чтобы очистить любые цифры и графики (хотя их не должно быть):
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()
Я получаю сообщение вроде:
No handles with labels found to put in legend.
и другая ошибка:
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: <matplotlib.axes._subplots.AxesSubplot object at 0x7f165b4e10b8>