0

I am using matplotlib to plot a 2D array but in the plot I am not getting curves, it only shows the axis. Following is my code:

posx = []
posy = []
for i in range(1,37):     
    posx.append(data[i,0])
    posy.append(data[i,1])
    for j in range(2,507):
        plt.plot(data[0,j],data[i,j]) 
print(posx,posy)
plt.show()

I have tried plt.plot(data[0,j],data[i,j],'.') which shows me a scatter plot which I don't want.

1
  • Share your data so that I can reproduce it Commented Aug 20, 2018 at 18:49

1 Answer 1

1

In your call to plot - plt.plot(data[0,j],data[i,j]), data[0,j] and data[i,j] are single numbers. plt.plot() tries to plot a line, however you are only passing a single x and a single y value. In order plot a line, you need at least 2 values for the x and y.

Your code can be simplified using slice notation which will remove the inner for loop:

for i in range(1,37):     
    plt.plot(data[0, 2:507], data[i, 2:507]) 

plt.show()
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.