import random
import matplotlib.pyplot as plt
def all_list(arr):
result = {}
for i in set(arr):
result[i] = arr.count(i)
return result
def SumT(n):
a =[]
for i in range(1,n+1):
a.append(random.randint(1,64))
dist = all_list(a)
d1 = {k: v for k, v in dist.items() if v > 1}
num1 = len(d1)
num2 = n - num1
if 0.5< (num1):
Add_f = 2
else:
Add_f = 4
T = num2 + Add_f*num1
return T
b = []
for i in range(1,51):
b.append(SumT(i))
print(b)
x =list(range(1,51))
print(x)
from pylab import *
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
'''
from pylab import *
from matplotlib.ticker import MultipleLocator, FormatStrFormatter
xmajorLocator = MultipleLocator(20) #将x主刻度标签设置为20的倍数
xmajorFormatter = FormatStrFormatter('%1.1f') #设置x轴标签文本的格式
xminorLocator = MultipleLocator(5) #将x轴次刻度标签设置为5的倍数
ymajorLocator = MultipleLocator(0.5) #将y轴主刻度标签设置为0.5的倍数
ymajorFormatter = FormatStrFormatter('%1.1f') #设置y轴标签文本的格式
yminorLocator = MultipleLocator(0.1) #将此y轴次刻度标签设置为0.1的倍数
t = arange(0.0, 100.0, 1)
s = sin(0.1*pi*t)*exp(-t*0.01)
ax = subplot(111) #注意:一般都在ax中设置,不再plot中设置
plot(t,s,'--b*')
#设置主刻度标签的位置,标签文本的格式
ax.xaxis.set_major_locator(xmajorLocator)
ax.xaxis.set_major_formatter(xmajorFormatter)
ax.yaxis.set_major_locator(ymajorLocator)
ax.yaxis.set_major_formatter(ymajorFormatter)
#显示次刻度标签的位置,没有标签文本
ax.xaxis.set_minor_locator(xminorLocator)
ax.yaxis.set_minor_locator(yminorLocator)
ax.xaxis.grid(True, which='major') #x坐标轴的网格使用主刻度
ax.yaxis.grid(True, which='minor') #y坐标轴的网格使用次刻度
show()
'''
#figsize = 11,9
#figure, ax = plt.plot(figsize=figsize
plt.plot(x, b, 'ro-')
#设置坐标间隔
ax.xaxis.set_major_locator(MultipleLocator(10))
plt.show()