我想在这个程序中尝试多次运行函数graph
,但目前它甚至没有运行一次。任何人都可以解释原因,并给我一些修复它的代码吗?
from matplotlib import pyplot as plt
import numpy as np
import matplotlib
import random
from multiprocessing import Process
max_x_val = int(input("What is the maximum x value? "))
max_y_val = int(input("What is the maximum y value? "))
counter = 0
points = int(input("How many points to be plotted? "))
plotted = []
notifications = (input("Do you want to see which point is being ploted?(Y/N) ")).lower()
def graph(max_x_val, max_y_val, points, plotted, notifications):
for i in range (1,points):
x = random.randint(0,max_x_val)
y = random.randint(0,max_y_val)
xstr = str(x)
ystr = str(y)
point = (str("(" + xstr + "," + ystr +")"))
plotted.append(point)
if (plotted.count(point)) == 1 : c="tab:blue"
elif (plotted.count(point)) == 2 : c="tab:cyan"
elif (plotted.count(point)) == 3 : c="tab:green"
elif (plotted.count(point)) == 4 : c="y"
elif (plotted.count(point)) == 5 : c="tab:orange"
elif (plotted.count(point)) >= 6 : c="tab:red"
plt.scatter(x=x,y=y, c=c)
if notifications == "y" : print(len(plotted))
plt.show()
print (plotted)
if __name__=="__main__":
p1 = Process (target=graph)
p1.start()
p2 = Process (target=graph)
p2.start()