Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
490 changes: 490 additions & 0 deletions .ipynb_checkpoints/learning_bokeh_in_jupyter-checkpoint.ipynb

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# InteractiveProgramming
This is the base repo for the interactive programming project for Software Design, Spring 2016 at Olin College.
This is the repo for an interactive map of queer resources in Massachusetts.
To run:
Have view_pandas.py, model_pandas.py, and test.csv in the same directory.
Run view_pandas.py.
Binary file added images/basic_plot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/cat_basic_with_overtext.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/cat_zoomed_in.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
55 changes: 55 additions & 0 deletions model_pandas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
This part of the code comprises the model portion of model-view-controller.
It takes in a filename, which is a csv file with information about resources for queer youth in MA.
It outputs a pandas DataFrame.

@author: Louise Nielsen and Apurva Raman
nielsenlouise@github.com, apurvaraman@github.com
"""

from pandas import *
from bokeh.plotting import ColumnDataSource as plotColumnDataSource


class Model(object):
"""A Model() object contains a pandas.DataFrame of resources.
"""

def __init__(self, source=None, filename='test.csv', frame=None):
self.source = source
self.filename = filename
if frame is None:
self.frame = DataFrame(read_csv(self.filename))
else:
self.frame = frame

def set_color(self):
"""Sets colors for each glyph based on category. Defines attributes for each glyph.
"""
colormap = {'health': 'red',
'support': 'green',
'housing': 'blue',
'advocacy': 'purple',
'legal': 'cyan'
}
self.frame['color'] = self.frame['Category'].map(lambda x: colormap[x])
self.source = plotColumnDataSource(dict(
name=self.frame['Name'],
lat=self.frame['Lat'],
lon=self.frame['Lon'],
address=self.frame['Address'],
category=self.frame['Category'],
color=self.frame['color']))

def update_model(self):
"""This is going to update the model, probably has to filter things.

We did not have time before the due date to implement buttons and
filtering, which was the intent of this.
"""
pass # TODO: Implement this.

if __name__ == '__main__':
thing = Model()
thing.set_color
print thing.frame
Binary file added model_pandas.pyc
Binary file not shown.
3 changes: 3 additions & 0 deletions playing_with_packages/csv_read_for_pandas.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import pandas as pd

print pd.read_csv('test_bokeh_data.csv')
51 changes: 51 additions & 0 deletions playing_with_packages/google_maps_stuff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from bokeh.models import HoverTool
from bokeh.plotting import figure
from bokeh.plotting import ColumnDataSource as plotColumnDataSource
from bokeh.io import output_file, show
from bokeh.models import (
GMapPlot, GMapOptions, ColumnDataSource, Circle, DataRange1d, PanTool, WheelZoomTool, BoxSelectTool
)

map_options = GMapOptions(lat=42.3601, lng=-71.0589, map_type="roadmap", zoom=9)

plot = GMapPlot(
x_range=DataRange1d(), y_range=DataRange1d(), map_options=map_options, title="Massachusetts"
)

# source = ColumnDataSource(
# data=dict(
# lat=[42.3601, 42.2926],
# lon=[-71.0589, -71.2644],
# )
# )

data=dict(
x=[-71.0589, -71.2644],
y=[42.3601, 42.2926],
name=['Boston', 'Olin'],
address=['Boston Rite Aid', 'Olin The Awesomest']
)
source = plotColumnDataSource(data)

colormap = {'Boston': 'blue', 'Olin': 'green'}
colors = {colormap[x] for x in data['name']}
circle = Circle(x="x", y="y", size=15, fill_color=colors, fill_alpha=0.8)
plot.add_glyph(source, circle)

# TOOLS="pan,wheel_zoom,box_zoom,reset,hover,save"

# p = figure(title="Our Map", tools=TOOLS)

plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool(), HoverTool())

hover = plot.select_one(HoverTool)
hover.point_policy = "follow_mouse"
hover.tooltips = [
('Name', '@name'),
('Title', '@address')
# ("(Long, Lat)", "($x, $y)"),
]

# plot.add_tools(PanTool(), WheelZoomTool(), BoxSelectTool(), hover())
output_file("gmap_plot.html")
show(plot)
Loading