1

I am trying to draw a plot, like following (call it img_1) , programmatically.

enter image description here

this post gives a piece of code though, the key is iris dataset

enter image description here

is there a way to generate 2 group of data randomly with NumPy or some other packages to draw a scatter plot like img_1?

1 Answers1

3

Use np.random to generate the point clouds and matplotlib to plot them.

import numpy as np
import matplotlib.pyplot as plt

# generate random normally distributed point clouds (customize as needed)
x1 = np.random.normal(loc=3.0, size=15)
y1 = np.random.normal(loc=2.0, size=15)
x2 = np.random.normal(loc=9.0, size=35)
y2 = np.random.normal(loc=7.0, size=35)

# now do the plotting with matplotlib
plt.scatter(x1,y1,color='red', marker='+',s=35)
plt.scatter(x2,y2,color='blue', marker= '^',s=35)
plt.xlim(-5,15)
plt.ylim(-5,15)
plt.xlabel('$x_1$',fontsize=25)
plt.ylabel('$x_2$',fontsize=25)
plt.savefig('example.png', bbox_inches='tight')
plt.show()

This generates

enter image description here

kevinkayaks
  • 2,636
  • 1
  • 14
  • 30