0

'''
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)

'''

with this line "axs[2,1:].plot()"

I've got this error: AttributeError: 'numpy.ndarray' object has no attribute 'plot'

the function 'graph_loss' and 'graph_scatter' work fine lonely

asked Nov 6, 2020 at 21:37

1 Answer 1

1

As you say, the problem is with this line:

axs[2,1:].plot()

In your code, axs is a 3x10 numpy array of AxesSubplot objects. I assume what you're trying to do is to call the plot() method on several of those objects at once, but numpy arrays don't support method calls like that. You could look at the vectorize() method, but I think it's clearest to just use a for loop. Here's a small example that calls plot() with some data on a couple of subplots, then calls plot() with no parameters on the rest of the subplots.

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()

I only wonder why you want to call plot() with no parameters in the first place. It just seems to change the axis scale a bit. Try removing those calls completely.

answered Nov 6, 2020 at 22:32
1
  • I create a script to create complexe custum graph, I wish t generate the subplots and fill it by the graph of my script Commented Nov 7, 2020 at 1:39

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.