-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdie_visual.py
More file actions
24 lines (21 loc) · 767 Bytes
/
Copy pathdie_visual.py
File metadata and controls
24 lines (21 loc) · 767 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from plotly.graph_objs import Bar,Layout
from plotly import offline
from die import Die
die_1 = Die()
die_2 = Die(10)
results = []
for roll_num in range(50_000):
result = die_1.roll() + die_2.roll()
results.append(result)
frequencies = []
maxresult = die_1.num_sides + die_2.num_sides
for value in range(2,maxresult+1):
frequency = results.count(value)
frequencies.append(frequency)
x_values = list(range(2,maxresult+1))
data = [Bar(x=x_values,y=frequencies)]
x_axis_config = {'title':'结果','dtick':1}
y_axis_config = {'title':'结果的频率'}
my_layout = Layout(title='掷一个D6和一个D10 50000次的结果',
xaxis=x_axis_config,yaxis=y_axis_config)
offline.plot({'data':data,'layout':my_layout},filename='d6_d10.html')