为子地块使用轴的问题get AttributeError:'numpy.ndarray'对象没有属性'plot'

2024-09-29 07:18:29 发布

您现在位置:Python中文网/ 问答频道 /正文

''”
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'对象没有属性'plot'

“图形丢失”和“图形分散”功能运行良好


Tags: testlenplotmanagerpltpashistgraph
1条回答
网友
1楼 · 发布于 2024-09-29 07:18:29

正如您所说,问题在于这一行:

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(),而不使用任何参数。它似乎只是稍微改变了轴的比例。尝试完全删除这些呼叫

相关问题 更多 >