I have a 4x4 data array like
data = np.array([[0,1,1,1], [1,0,0,1], [1,1,1,0], [0,0,0,1]])
现在我想在二维图上散点表示这个数组。
如果等于1,那么点(x,y)=(i,j)应该有一个有颜色的斑点。 我已经尝试使用matplotlib中的scatter plot,但是不知道为什么无法使其工作。
I have a 4x4 data array like
data = np.array([[0,1,1,1], [1,0,0,1], [1,1,1,0], [0,0,0,1]])
您可以使用以下方法来完成:
import numpy as np
import matplotlib.pyplot as plt
data = np.array([[0,1,1,1], [1,0,0,1], [1,1,1,0], [0,0,0,1]])
# get the indices where data is 1
x,y = np.argwhere(data == 1).T
plt.scatter(x,y)
plt.show()
然而,当你只想可视化4x4数组时,可以使用matshow
plt.matshow(data)
plt.show()