Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different color for each set in scatter plot on matplotlib [duplicate]

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.

like image 876
Sergio de la Rica Avatar asked May 22 '26 20:05

Sergio de la Rica


1 Answers

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

like image 72
cel Avatar answered May 25 '26 09:05

cel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!