DatalogiForAlle / AgentsPy

Agent-based simulation for education in Python
GNU General Public License v3.0
5 stars 0 forks source link

Jumping histogram #118

Closed dybber closed 3 years ago

dybber commented 3 years ago

Issue reported by a high school teacher. The histogram max value jumps to whatever max value, this makes the plot very hard to read as the scale is changing all the time.

Example where the issue was reported below. We can probably do something similar to what the plotter in Mu-editor, where the max value jumps between a few predefined values, so it will jump more rarely e.g. everytime the value doubled: https://github.com/mu-editor/mu/blob/master/mu/interface/panes.py#L1348-L1350

from agents import *
from random import randint
model = Model("random walk", 60, 60)

class Person(Agent):
    def setup(self,model):
        self.jump_to(60*4,60*4)
    def step(self, model):
        self.direction += randint(-180,180)
        self.forward(4)
        self.distanceToCenter = self.distance_to(0,60*8)-340

def model_setup(model):
    model.reset()
    for agent in range(1000):
          model.add_agent(Person())

def model_step(model):
    for person in model.agents:
        person.step(model)
    model.update_plots()

model.add_button("Setup", model_setup)
model.add_toggle_button("Go", model_step)
model.histogram("distanceToCenter", -60, 60, 20, (200,0,0))
run(model)