[英]Matplotlib is plotting multiple labels
I have matrix A
of size 50x4
and another matrix B
of size 4*2
我有大小为50x4
矩阵A
和另一个大小为4*2
矩阵B
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? 如何让matplotlib只显示一次标签名称?
Because you have 2 columns of data. 因为您有2列数据。
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现在有形状(50,2),D有形状(50,)
>>> C.shape
(50, 2)
>>> np.shape(D)
(50,)
The Documentation on plt.plot
says: plt.plot
上的文档说:
If x and/or y is 2-dimensional, then the corresponding columns will be plotted. 如果x和/或y是2维的,则将绘制相应的列。
I would recommend you to fix this by reducing the data to one column using C.flatten()
and changing the dimension of D
accordingly. 我建议你通过使用C.flatten()
将数据减少到一列并相应地改变D
的维度来解决这个问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.