简体   繁体   English

在 Python 中的 (x,y) 图形上创建随机点

[英]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.我需要在(X,Y)图形中创建随机点(最小 12-最大 18 个点)。

This points had to be between 0-9 x and y.这个点必须在 0-9 x 和 y 之间。 Like this像这样

import random
import matplotlib.pyplot as plt

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

y=[1,2,3,4,5,6,0,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()

try this:尝试这个:

import random

coords = []
amount_of_coords = 12+random.randint(0, 7)
print(amount_of_coords)

for x in range(amount_of_coords):
    coords.append([random.randint(0, 10),random.randint(0, 10)])

print(coords)

for point in coords:
    plt.scatter(point[0],point[1], color='k', s=100)

plt.show()

output: output:

12
[[1, 1], [3, 7], [3, 1], [4, 0], [0, 7], [2, 1], [1, 0], [2, 8], [3, 4], [4, 6], [3, 7], [1, 4]]

在此处输入图像描述

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM