Reputation: 4792
array1=[1,2,3,4]
array2=[5,6,7,8]
plt.plot(4, array1, 'g', label='Label 1')
plt.plot(4, array2, 'b', label='Label 2')
plt.title('Sample Graph')
plt.xlabel('X Axis')
plt.ylabel('Y Axis')
plt.legend()
plt.show()
But when I run this it says
ValueError: x and y must have same first dimension, but have shapes (1,) and (4,)
Upvotes: 1
Views: 1980
Reputation: 2189
4 is just an int. What you need is a list of 1-4
plt.plot(range(1,5), array1, 'g', label='Label 1')
plt.plot(range(1,5), array2, 'b', label='Label 2')
Output:
Upvotes: 1