scientific-programming-exer.../exam/ex13/main.py

29 lines
687 B
Python
Raw Permalink Normal View History

2019-02-23 19:38:37 +00:00
import matplotlib.pyplot as plt
import numpy as np
from model import prepare_model
from backend import total_living_cells
from executor import execute_tick
def cells_alive_at_ticks(model, ticks):
for i in range(ticks):
cell_count = total_living_cells(model)
2019-02-23 20:01:16 +00:00
yield [i, cell_count]
execute_tick(model)
2019-02-23 19:38:37 +00:00
plot_data = {
0.3 : ("r", "p=0.3")
, 0.5: ("g", "p=0.5")
, 0.7: ("b", "p=0.7")
}
2019-02-23 20:01:16 +00:00
handles = []
2019-02-23 19:38:37 +00:00
for p, (color, label) in plot_data.items():
model = prepare_model(100, p)
2019-02-23 20:01:16 +00:00
living_cells = np.array(list(cells_alive_at_ticks(model, 10)))
plot, = plt.plot(living_cells[:, 0], living_cells[:, 1], color, label=label)
handles.append(plot)
2019-02-23 19:38:37 +00:00
2019-02-23 20:01:16 +00:00
plt.legend(handles=handles)
2019-02-23 19:38:37 +00:00
plt.show()