3

I have two samples sets from a multivariate normal distribution: ¿How could I set a different color for each set in scatter plot on matplotlib? Eg. printing values from A1 in blue and values from A2 in red.

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]]

Could someone help me? Thanks in advance.

1

1 Answer 1

4

This should work for you.

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)

enter image description here

1
  • Thank you very much! , That was exactly what I wanted to do. May 30, 2015 at 17:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.