Reputation: 2856
I have matrix A
of size 50x4
and another matrix B
of size 4*2
import numpy as np
import matplotlib.pyplot as plt
plt.plot(np.dot(A, B), [0]*A.shape[0], "bo", label="Tennis")
plt.legend()
plt.show()
How to make matplotlib display the label name only once?
Upvotes: 0
Views: 582
Reputation: 3239
Because you have 2 columns of data.
import numpy as np
import matplotlib.pyplot as plt
A=np.random.rand(50, 4)
B=np.random.rand(4, 2)
C=np.dot(A, B)
D=[0]*A.shape[0]
plt.plot(C, D, "bo", label="Tennis")
plt.legend()
plt.show()
C has now shape (50, 2) and D has shape (50,)
>>> C.shape
(50, 2)
>>> np.shape(D)
(50,)
The Documentation on plt.plot
says:
If x and/or y is 2-dimensional, then the corresponding columns will be plotted.
I would recommend you to fix this by reducing the data to one column using C.flatten()
and changing the dimension of D
accordingly.
Upvotes: 2