![](/img/trans.png)
[英]AttributeError: 'numpy.ndarray' object has no attribute 'plot'
[英]Prob using axes for subplot an get AttributeError: 'numpy.ndarray' object has no attribute 'plot'
'''
matplotlib.use("Qt5Agg")
pas = [1,2,3,4,5,6,7,8,9,10]
# set up l'organisation de la figure
fig, axs = plt.subplots(nrows=3,ncols=len(pas))
manager = plt.get_current_fig_manager()
manager.window.showMaximized()
plt.show()
axs[1, 0+1].set(ylabel='fréquence (set test)')
for iii in range(0, len(pas)):
bins = np.linspace(round(y[:,iii].min()), round(y[:,iii].max()), 20)
axs[0, iii].hist(yhat_graph[:,iii], bins, color = 'steelblue', alpha = 0.5, label='simulation')
axs[0, iii].hist(y[:,iii], bins, color = 'orange', alpha=0.5, label='ref. apport hist.')
axs[0, iii].set(xlabel='apports m3/sec')
axs[0, iii].legend(loc='upper right')
axs[0, iii].set(title='prévision J+' + str(iii+1) + ' (set test)' )
axs[1, 0].set(ylabel='Variations journalières Jn - Jn-1 (set test) \n observation')
for iii in range(0, len(pas)-1):
axs[1, iii].plot()
graph_scatter(ecart_valid_y[iii],
ecart_yhat[iii], True,'simulation','','var. j' + str(iii+1) +' - j ' + str(iii) ,'steelblue')
axs[1, iii].set(xlabel='simulation')
if history == 'missing':
print('pas de fichier history')
axs[2,0:].plot()
else:
axs[2, 0].plot()
graph_loss(history)
axs[2,1:].plot()
graph_sim_multiStep(y[-windowGraph[0]:-windowGraph[1]], yhat_graph[-windowGraph[0]:-windowGraph[1]], nash, kge, titre)
'''
用這一行“axs[2,1:].plot()”
我有這個錯誤: AttributeError: 'numpy.ndarray' object has no attribute 'plot'
函數 'graph_loss' 和 'graph_scatter' 單獨工作正常
正如你所說,問題出在這一行:
axs[2,1:].plot()
在您的代碼中, axs
是AxesSubplot
對象的 3x10 numpy 數組。 我假設您要做的是一次在其中幾個對象上調用plot()
方法,但是 numpy 數組不支持這樣的方法調用。 您可以查看vectorize()
方法,但我認為僅使用 for 循環最清楚。 這里有一個小例子是調用plot()
與一對夫婦的次要情節的一些數據,然后調用plot()
與次要情節的其他任何參數。
import matplotlib.pyplot as plt
fig, axs = plt.subplots(nrows=2,ncols=3)
axs[0, 0].plot([1, 4, 2])
axs[0, 2].plot([4, 1, 2])
# Could probably remove the next three lines.
axs[0, 1].plot()
for iii in range(3):
axs[1, iii].plot()
plt.show()
我只是想知道你為什么要首先調用沒有參數的plot()
。 它似乎只是稍微改變了軸的比例。 嘗試完全刪除這些調用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.