gpt4 book ai didi

python - 在 EC2 实例中调用 plot 时为 "Unknown element o"

转载 作者:太空宇宙 更新时间:2023-11-04 00:18:15 25 4
gpt4 key购买 nike

我有一个 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()

我搜索并尝试了很多东西,但都没有成功。有什么建议吗?

编辑:更改我的代码以清除任何图形和绘图(尽管不应该存在任何图形和绘图):

            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>

最佳答案

当我尝试使用 matplotlib 获取频谱图数据时,我也遇到了错误“Unknown element o”:

pxx, freqs, bins, im = plt.specgram(sample,  NFFT=256, Fs=10000, noverlap=120)

我在训练模型时使用了这条线,所以我不需要绘图,我通过关闭窗口和移除轴来解决它:

pxx, freqs, bins, im = plt.specgram(sample,  NFFT=256, Fs=10000, noverlap=120)
plt.axis('off')
plt.close()

我希望有人觉得这有帮助。

关于python - 在 EC2 实例中调用 plot 时为 "Unknown element o",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50119460/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com