我有 5 个数组,每个数组包含 30 个值。我想在一个散点图中将每个数组绘制在其自己的列上。 因此,我希望最终得到一个包含 5 列的散点图,每列中绘制 30 个数据点。我不希望数组重叠,这是我现在的代码遇到的问题。
plt.scatter(y,Coh1mean40,label='1', c='r')
plt.scatter(y, Coh75mean40,label='75', c='b')
plt.scatter(y,Coh05mean40,label='50', c='y')
plt.scatter(y,Coh25mean40,label='25', c='g')
plt.scatter(y,Coh00mean40,label='0')
plt.legend()
plt.show()
此代码为我提供了一个包含所有数据点的散点图,但它们全部重叠,没有不同的列。
y 只是一个包含 30 个数字的列表,因为 plt.scatter 函数需要两个参数。 Coh1mean40、Coh75mean40 等。都是包含 [0.435, 0.56, 0.645...] 30 个值的数组
最佳答案
您需要为每个数组的每次调用指定一个唯一的y
,每个数组将落在不同的“列”中。最好将其称为 x
,因为您使用第一个参数定义每个点的 x 值。
x = np.ones(30)
plt.scatter(0 * x,Coh1mean40,label='1', c='r')
plt.scatter(1 * x, Coh75mean40,label='75', c='b')
plt.scatter(2 * x,Coh05mean40,label='50', c='y')
plt.scatter(3 * x,Coh25mean40,label='25', c='g')
plt.scatter(4 * x,Coh00mean40,label='0')
plt.legend()
plt.show()
但是,您可能想查看 Seaborn,特别是 stripplot
关于python - 如何在一个散点图上将多个数据集绘制在各自的列上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55423097/