def createHistogram(key): data = json.load(open('FinishedCourseData/pausePlayBins.json'))[key] x = sorted([float(num) for num in data.keys()]) strX = [str(i) for i in x] y = np.array([data[i] for i in strX], dtype=np.float) output_file('pausePlay.html') p2 = figure(title="PausePlay for " + key, tools="", x_range=strX, y_range=[0, int(max(y))], background_fill='#59636C', plot_width=1600, plot_height=800) xSize = [c + ":0.5" for c in strX] p2.rect(x=xSize, y=y / 2, width=0.2, height=y, color="gold", alpha=0.8) p2.xgrid.grid_line_color = None p2.axis.major_label_text_font_size = "8pt" p2.axis.major_label_standoff = 0 p2.xaxis.major_label_orientation = np.pi / 3 p2.xaxis.major_label_standoff = 5 p2.xaxis.major_tick_out = 0 # show the plots arrayed in a VBox show(VBox(p2))
def createHistogram(key): data =json.load(open('FinishedCourseData/pausePlayBins.json'))[key] x=sorted([float(num) for num in data.keys()]) strX=[str(i) for i in x] y = np.array([data[i] for i in strX], dtype=np.float) output_file('pausePlay.html') p2 = figure(title="PausePlay for "+key, tools="", x_range=strX, y_range=[0, int(max(y))], background_fill='#59636C', plot_width=1600, plot_height=800) xSize = [c+":0.5" for c in strX] p2.rect(x=xSize, y=y/2, width=0.2, height=y, color="gold", alpha=0.8) p2.xgrid.grid_line_color = None p2.axis.major_label_text_font_size = "8pt" p2.axis.major_label_standoff = 0 p2.xaxis.major_label_orientation = np.pi/3 p2.xaxis.major_label_standoff = 5 p2.xaxis.major_tick_out = 0 # show the plots arrayed in a VBox show(VBox(p2))
import json import numpy as np from bokeh.plotting import * from bokeh.sampledata.olympics2014 import data from bokeh.objects import ColumnDataSource, Range1d data = { d['abbr']: d['medals'] for d in data['data'] if d['medals']['total'] > 0} # pull out just the data we care about countries = sorted( data.keys(), key=lambda x: data[x]['total'], reverse=True ) gold = np.array([data[abbr]['gold'] for abbr in countries], dtype=np.float) silver = np.array([data[abbr]['silver'] for abbr in countries], dtype=np.float) bronze = np.array([data[abbr]['bronze'] for abbr in countries], dtype=np.float) # EXERCISE: output static HTML file output_file('olympics.html') # EXERCISE: turn on plot hold hold() # use the `rect` renderer to display stacked bars of the medal results. Note # that we set y_range explicitly on the first renderer with a `Range1d` object rect(x=countries, y=bronze/2, width=0.8, height=bronze, x_range=countries, color="#CD7F32", alpha=0.6, background_fill='#59636C', title="Olympic Medals by Country (stacked)", tools="", y_range=Range1d(start=0, end=max(gold+silver+bronze)), plot_width=800) rect(x=countries, y=bronze+silver/2, width=0.8, height=silver, x_range=countries, color="silver", alpha=0.6) # EXERCISE: add a `rect` renderer to stack the gold medal results
import json import numpy as np from bokeh.plotting import * from bokeh.sampledata.olympics2014 import data from bokeh.models import ColumnDataSource data = { d['abbr']: d['medals'] for d in data['data'] if d['medals']['total'] > 0} # pull out just the data we care about countries = sorted( data.keys(), key=lambda x: data[x]['total'], reverse=True ) gold = np.array([data[abbr]['gold'] for abbr in countries], dtype=np.float) silver = np.array([data[abbr]['silver'] for abbr in countries], dtype=np.float) bronze = np.array([data[abbr]['bronze'] for abbr in countries], dtype=np.float) # EXERCISE: output static HTML file output_file('olympics.html') # EXERCISE: turn on plot hold hold() # use the `rect` renderer to display stacked bars of the medal results. Note # that we set y_range explicitly on the first renderer rect(x=countries, y=bronze/2, width=0.8, height=bronze, x_range=countries, color="#CD7F32", alpha=0.6, background_fill='#59636C', title="Olympic Medals by Country (stacked)", tools="", y_range=[0, max(gold+silver+bronze)], plot_width=800) rect(x=countries, y=bronze+silver/2, width=0.8, height=silver, x_range=countries, color="silver", alpha=0.6) # EXERCISE: add a `rect` renderer to stack the gold medal results
import json import numpy as np from bokeh.plotting import * from bokeh.sampledata.olympics2014 import data from bokeh.objects import ColumnDataSource data = { d['abbr']: d['medals'] for d in data['data'] if d['medals']['total'] > 0 } # pull out just the data we care about countries = sorted(data.keys(), key=lambda x: data[x]['total'], reverse=True) gold = np.array([data[abbr]['gold'] for abbr in countries], dtype=np.float) silver = np.array([data[abbr]['silver'] for abbr in countries], dtype=np.float) bronze = np.array([data[abbr]['bronze'] for abbr in countries], dtype=np.float) # EXERCISE: output static HTML file output_file('olympics.html') # EXERCISE: turn on plot hold hold() # use the `rect` renderer to display stacked bars of the medal results. Note # that we set y_range explicitly on the first renderer rect(x=countries, y=bronze / 2, width=0.8, height=bronze, x_range=countries, color="#CD7F32",