I have several arrays (more than this, about 20 x arrays and 20 y arrays) but this is an example
xa1=[0,...3000] ya1=[0,...3000] xa2=[0,...3000] ya2=[0,...3000] xa3=[0,...3000] ya3=[0,...3000]
I want to plot these arrays in a single plot using a for loop
I try first making an array of arrays
xarr = np.array([[xa1],[xa2],[xa3]]) yarr = np.array([[ya1],[ya2],[ya3]]) for i in range(3): plt.plot(xarr[i], yarr[i]) plt.show()
but my jupyter notebook crashes. I am new to coding, so could anyone help me improve this little code? or help me with an alternative? thank you so much in advance.
Based on your syntax xarr[i] is not an array but a list with one item in it and THAT item is an array. Matplotlib won’t like that.
Try initializing xarr as a list instead, i.e. [xa1,xa2,xa3], and the same for yarr: you don’t need them to be arrays, just a list OF arrays for the for-loop to iterate through.