### Matplotlib exercise

Posted:

**Tue Jun 16, 2020 11:27 am**I have made the Matplotlib exercise, but not sure if I found the correct solution.

the solution can be summarized in the next steps:

-Creating 2 dimensional random array with .randn under 0.5 maximum margin each

-Divide the distribution points into 4 groups, and move each distribution center to corresponding quadrant

-Create the array colour variable in function of each point position

-Scatter representation

So, in my opinion, this solution is a work around, because if I see the solution, the distribution looks like more homogeneous, not like Gauss distribution as my solution shows. I think that the correct solution would be a crazy mathematical function that calculate points position and assign colours and epic things like that.

Other solutions?

the solution can be summarized in the next steps:

-Creating 2 dimensional random array with .randn under 0.5 maximum margin each

-Divide the distribution points into 4 groups, and move each distribution center to corresponding quadrant

-Create the array colour variable in function of each point position

-Scatter representation

Code: Select all

```
import matplotlib.pyplot as plt
import numpy as np
quantity = 100
def XOR(x1,x2):
xorResult = False
if x1 > 0 and x2 >= 0:
xorResult = False
elif x1 > 0 and x2 < 0:
xorResult = True
elif x1 <= 0 and x2 <= 0:
xorResult = False
elif x1 <=0 and x2 > 0:
xorResult = True
return xorResult
def colorDecider(x,quantity):
colourSequence = np.zeros(quantity)
for i in range(0,quantity):
colourSequence[i] = int(XOR(x[i][0],x[i][1]))
return colourSequence
quantity = 700
x =(np.random.randn(quantity,2))*0.125
x[:int(quantity/4)] += 0.5
x[int(quantity/4):int(quantity/2)] -= 0.5
x[int(quantity/2):int(3*quantity/4)] += [0.5, -0.5]
x[int(3*quantity/4):quantity] += [-0.5, 0.5]
y = colorDecider(x,quantity)
plt.scatter(x[:,0], x[:,1], c=y)
plt.show()
```

So, in my opinion, this solution is a work around, because if I see the solution, the distribution looks like more homogeneous, not like Gauss distribution as my solution shows. I think that the correct solution would be a crazy mathematical function that calculate points position and assign colours and epic things like that.

Other solutions?