Advertisement
Guest User

Untitled

a guest
Oct 10th, 2017
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. from bokeh.plotting import figure
  2. from bokeh.io import curdoc
  3. from bokeh.layouts import row
  4. from bokeh.models.widgets import Slider
  5. from bokeh.models import ColumnDataSource
  6. import pandas
  7.  
  8.  
  9. class Person(object):
  10.     """ Person class represents a person in the population """
  11.  
  12.     def __init__(self,
  13.                  infected=False,
  14.                  vaccinated=False,
  15.                  x=0,
  16.                  y=0,
  17.                  infectedByx=0,
  18.                  infectedByy=0,
  19.                  stepInfected=0):
  20.         self.infected = False
  21.         self.vaccinated = False
  22.         self.x = 0
  23.         self.y = 0
  24.         self.infectedByx = 0
  25.         self.infectedByy = 0
  26.         self.stepInfected = 0
  27.  
  28.  
  29. def initialisePlot():
  30.     plot = figure(plot_height=400, plot_width=400)
  31.     plot.xgrid.grid_line_color = None
  32.     plot.ygrid.grid_line_color = None
  33.     plot.axis.visible = False
  34.     plot.toolbar.logo = None
  35.     plot.toolbar_location = None
  36.  
  37.     return plot
  38.  
  39.  
  40. def dataChange(step):
  41.     for i in range(100):
  42.         current = dataFrame.iloc[i]
  43.         if current.stepInfected < step:
  44.             plot.circle(current.x, current.y, size=2, color='red')
  45.             plot.line([current.x, current.infectedByx],
  46.                       [current.y, current.infectedByy],
  47.                       color='red')
  48.  
  49.  
  50. def update_data(attrname, old, new):
  51.     # get the current value
  52.     step = round(stepSlider.value)
  53.     dataChange(step)
  54.  
  55.  
  56. # Set up data
  57. dataFrame = pandas.read_csv('DIRECTORY TO THE CSV FILE HERE')
  58. source = ColumnDataSource(dataFrame)
  59. steps = 9
  60. circleSize = 9
  61.  
  62. # Set up plot
  63. plot = initialisePlot()
  64. plot.circle('x', 'y', source=source, size=circleSize, color='blue')
  65.  
  66. stepSlider = Slider(title="Step", value=0, start=0, end=10, step=1)
  67. stepSlider.on_change('value', update_data)
  68.  
  69. curdoc().add_root(row(plot, stepSlider, width=400))
  70. curdoc().title = "Sliders"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement