Benutzer-Werkzeuge

Webseiten-Werkzeuge


Seitenleiste

ws2021:code8
import plotly.graph_objects as go
import numpy as np
import random
 
steps = 100
agents = 300
temp = 0.1
 
 
 
x0 = [random.uniform(0.1,4.9) for i in range(agents)]
y0 = [random.uniform(0.1,4.9) for i in range(agents)]
 
x = x0
y = y0
 
color_susceptible = 'MediumSeaGreen'
susceptible = [color_susceptible for i in range(agents)]
 
number_infected = 0
 
fig = go.Figure()
 
fig.add_trace(go.Scatter(x=x0, y=y0, mode="markers", marker=dict(size = 10, color = 'MediumSeaGreen')))
 
# Set axes properties
fig.update_xaxes(range=[0, 5], showgrid=False)
fig.update_yaxes(range=[0, 5], showgrid=False)
 
# Add shapes
fig.add_shape(type="rect",
    x0=0, y0=0, x1=5, y1=5,
    line=dict(color="RoyalBlue")
)
 
 
#x_random = [temp*random.uniform(-1,1) for i in range(agents)]
#y_random = [temp*random.uniform(-1,1) for i in range(agents)]
 
frames = []
 
for step in range(steps):
 
 
    #x = [x1 + x_random[x2] for x1 in x]
    #y = [y1 + y_random[y2] for y1 in y]
 
    x = [x1 + random.randint(-5,5) for x1 in x]
    y = [y1 + random.randint(-5,5) for y1 in y]
 
    if x > 5 or x < 0:
 
 
    if y > 5 or y < 5:
    #for dot in range(len(susceptible)):
 
    frames.append(go.Frame(data=[go.Scatter(x=x, y=y, \
        mode = "markers", \
        marker=dict(size = 10, color=susceptible, 
        ))
        ] ))
 
fig.frames = frames
button = dict(label='Play',
             method='animate',
             args=[None, dict(frame=dict(duration=50, redraw=False),
                              transition=dict(duration=0),
                              fromcurrent=True,
                              mode='immediate')])
fig.update_layout(updatemenus=[dict(type='buttons',
                              showactive=False,
                              y=0,
                              x=1.05,
                              xanchor='left',
                              yanchor='bottom',
                              buttons=[button] )],
                  width=800, height=500)
 
fig.update_layout(plot_bgcolor='white')
 
fig.show()
ws2021/code8.txt · Zuletzt geändert: 2021/02/04 17:01 von livia.mai