Search code examples
pythonalgorithmmatplotlibrandom

Creating random points on (x,y) graphic in Python


I need to create random points (Min 12- Max 18 points between) in (X,Y) graphic.

This points had to be between 0-9 x and y, like this: figure 1

import random
import matplotlib.pyplot as plt

x=[0,1,2,3,4,5,6,7,8,9]

y=[0,1,2,3,4,5,6,7,8,9]
print(x+y)

random.shuffle(x)

random.shuffle(y)

a=plt.scatter(x,y, color='k', s=100)

random.shuffle(x)

random.shuffle(y)

b=plt.scatter(x,y, color='k', s=100)

plt.show()

Solution

  • Is this what you're looking for:

    import matplotlib.pyplot as plt
    from random import randint
    
    amt = randint(12,19)
    
    x = [randint(1,9) for _ in range(amt)]
    y = [randint(1,9) for _ in range(amt)]
    
    plt.scatter(x,y)
    plt.show()
    

    plt