I have code that is used to create 100 randomly drawn points based on a normal distribution centered at the point (1, -2) with a standard deviation of 0.3. These points are shown below.
points = np.random.randn(100,2)*0.3 +[1,-2]
plt.scatter(points[:,0],points[:,1],c='r')
plt.show()
I want to create three groups of 200 points randomly drawn using a normal distribution of 0.05 and centered on the following centers:
- 0.8; 0.3
- 0.3 ; 0.2
- 0.5; 0.9
How to show these three groups in the same figure with three different colors?
The points generated to the previous question will be saved in a single variable x
. This variable will correspond to the points of my learning set of the K-means algorithm that I want to configure.
You can set the generation parameters of the points in a list, and iterate through it to generate each set. If you don't care about colors, as long as they are different, you can generate a palette for as many groups as you have, otherwise just define the color inside the list as one more parameter:
I suggest you use the
alpha
(transparency) parameter as it makes the concentration and overlapping of the points more visible.You say that you want to generate a list
x
with all 300 points, but that you want to represent them with separate colors.I think the simplest way is to generate them separately, in three arrays, and use these for the graphical representation. Then concatenate those arrays to get your variable
x
.That is, for the figure:
And for the
x
end:x.shape
it is(300,2)