我有两个来自多元正态分布的样本集: ¿我怎么能在matplotlib的散点图中为每一组设置不同的颜色?例如。从A1打印蓝色值,A2打印红色值。
N= 4
A1 = np.random.multivariate_normal(mean=[1,-4], cov=[[2,-1],[-1,2]],size = N)
A2 = np.random.multivariate_normal(mean=[1,-3], cov=[[1,1.5],[1.5,3]],size= N)
>>>print A1
[[ 0.16820131 -2.14909926]
[ 0.57792273 -2.43727122]
[-0.06946973 -3.72143292]
[ 2.59454949 -5.34776438]]
>>>print A2
[[ 0.98396671 -1.68934158]
[-0.33756576 -3.28187214]
[ 1.49767632 -3.46575623]
[ 1.47036718 -1.58453858]]
有人可以帮助我吗?提前谢谢。
答案 0 :(得分:5)
这应该适合你。
import numpy as np
import matplotlib.pyplot as plt
np.random.seed(42)
N = 1000
A1 = np.random.multivariate_normal(mean=[1,-4], cov=[[2,-1],[-1,2]],size = N)
A2 = np.random.multivariate_normal(mean=[1,-3], cov=[[1,1.5],[1.5,3]],size= N)
fig, ax = plt.subplots()
ax.scatter(A1[:,0], A1[:,1], color="blue", alpha=0.2)
ax.scatter(A2[:,0], A2[:,1], color="red", alpha=0.2)