import matplotlib.pyplot as plt
import random
# 建立一个空字典
ai = {}
num = []
person = 10
for i in range(person):
# 添加一个数字放到上面的空列表里
ai[i] = [i+100, "blue"]
num.append(i)
ax = plt.subplot(111)
# 分钱
coin = 10
# 每个人减少10块钱
for d in range(1000):
for i in range(person):
ai[i][0] -= coin
# 产生一个随机数字
q = random.randint(0,person-1)
# 给那个随机数字的位置的人1块钱
ai[q][0] += coin
if ai[i][0] < -50:
ai[i][1] = "green"
elif ai[i][0] < 0:
ai[i][1] = "red"
color = [] # 颜色列表
all = [] # 钱数列表
for k in sorted(ai,key=ai.__getitem__):
print(k)
color.append(ai[k][1]) # 颜色列表
all.append(ai[k][0]) # 钱数列表
# ai.sort()
ax.cla() # 清除画面
# ax.bar(num, ai, color=["#FF0000", "#FFA500", "#FFFF00", "#00FF00", "#00FFFF", "#0000FF", "#A020F0"], alpha=0.75)
ax.bar(range(person), all, color=color)
# r 0-255 g b
# 16进制
# 0 1 2 3 4 5 6 7 8 9 A B C D E F
plt.xlabel("序号")
plt.ylabel("身价")
plt.title("百人身价表%d" % d)
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.pause(0.01) # 设置暂停
plt.show()
deqin - 资金分配系统
猜你喜欢
转载自blog.csdn.net/houlaos/article/details/105141889
今日推荐
周排行