def generate_chart(year): data = get_data(year) barchart = Bar(data, values=blend(*SCORED_EVENTS, labels_name='event'), label=cat(columns='Team', sort=False), stack=cat(columns='event', sort=False), color=color(columns='event', palette=Spectral9, sort=False), xgrid=False, ygrid=False, legend='top_right', plot_width=1000, plot_height=625, tools="pan,wheel_zoom,box_zoom,reset,resize") barchart.title = "Formula SAE Michigan " + str(year) + " Total Scores by Place" barchart._xaxis.axis_label = "Teams" barchart._xaxis.axis_line_color = None barchart._xaxis.major_tick_line_color = None barchart._xaxis.minor_tick_line_color = None barchart._xaxis.major_label_text_font_size = '0.6em' barchart._yaxis.axis_label = "Total Score" barchart._yaxis.axis_line_color = None barchart._yaxis.major_tick_line_color = None barchart._yaxis.minor_tick_line_color = None barchart.outline_line_color = None barchart.toolbar_location = 'right' barchart.logo = None return barchart
def fnCreate_Chart_Bar(df): pd.options.html.border=0 plot = Bar(df, 'Sub_Attbt', values='FY2013', title="Total DISPL by Attribute", bar_width=0.4) plot.logo=None script, div = components(plot,CDN) return script, div
def fnCreate_Chart_Bar1(df,strS): pd.options.html.border=1 label1=CatAttr(columns=['Airline'], sort=False) plot = Bar(df, label=label1, values='Ticket Price',group='Airline', title="Average of Ticket Price- Airline wise" + strS, legend=False, bar_width=100, xlabel='Airlines',ylabel='Average Ticket Price') plot.logo=None script, div = components(plot,CDN) return script, div
def fnCreate_Chart_Bar(df): pd.options.html.border=1 # pd.options.display.html.border=1 label1=CatAttr(columns=['Routes'], sort=False) plot = Bar(df, label=label1, values='Ticket Price',group='Routes', title="Average of Ticket Price- Routes wise", legend=False, bar_width=50, xlabel='Routes',ylabel='Average Ticket Price') plot.logo=None script, div = components(plot,CDN) return script, div
def fnCreate_Chart_Bar_Full(df): pd.options.html.border=0 plot = Bar(df, label='Attbt', values='FY2013', agg='sum', group='Attbt', title="Total Sum, grouped by Attribute", legend='top_left') # plot = Bar(df, 'Sub_Attbt', values='FY2013', title="Total DISPL by Attribute", bar_width=0.4) plot.logo=None script, div = components(plot,CDN) return script, div
def fnCreate_Chart_Bar2(df): output_file("line_bar.html") pd.options.html.border=0 plot = Bar(df, label='Attbt', values='FY2013', agg='sum', group='Attbt', title="Total Sum, grouped by Attribute", legend='top_left') # plot = Bar(df, 'Sub_Attbt', values='FY2013', title="Total DISPL by Attribute", bar_width=0.4) plot.logo=None show(plot) return True
def plot(df): print("-" * 10) print(df) print("-" * 10) from bokeh.charts import Bar, show p = Bar(df, label=["model", "dim reduction"], \ values="accuracy", agg="mean", color="model",\ legend=None, bar_width=0.3, plot_width=600, plot_height=600) p.logo = None # will open a browser to show the plot. show(p)
def fnCreate_Stacked_Bar(df): # label1=CatAttr(columns=['Aspects'], sort=True) tmp=df plot = Bar(tmp, stack=tmp.columns[0], label=tmp.columns[1], values=tmp.columns[2], legend=True,title="Sentiment segmentation based on top 7 Aspects", xlabel='Polarity',ylabel='Count') plot.logo=None plot.legend.label_text_font_size = "7pt" plot.legend.orientation = "horizontal" script, div = components(plot,CDN) return script, div
def fnCreate_Chart_Bar(df): plot = Bar(df, label='Aspects', values='Count',group='Polarity', title="Average Sentiment for various Aspects", legend='top_left', bar_width=0.9,color=["green","red"], xlabel='Aspects',ylabel='Count') plot.logo=None plot.legend.label_text_font_size = "7pt" plot.legend.orientation = "horizontal" # plot.legend.click_policy="hide" script, div = components(plot,CDN) return script, div
def generate_chart(event): data = get_data(TIMED_EVENTS[event]) # Bokeh doesn't let me control the order of the grouping! This is # frustrating since it will be different on every server launch barchart = Bar(data, values='percentage_dnf', label='year', color="FireBrick", xgrid=False, ygrid=False, plot_width=800, plot_height=500, tools="pan,wheel_zoom,box_zoom,reset,resize") barchart.title = "Formula SAE Michigan DNFs - " + event barchart._xaxis.axis_label = "Year" barchart._xaxis.axis_line_color = None barchart._xaxis.major_tick_line_color = None barchart._xaxis.minor_tick_line_color = None barchart._yaxis.axis_label = "Percentage DNF" barchart._yaxis.axis_line_color = None barchart._yaxis.major_tick_line_color = None barchart._yaxis.minor_tick_line_color = None barchart._yaxis.formatter = NumeralTickFormatter(format="0%") barchart.y_range = Range1d(0, 1) barchart.outline_line_color = None barchart.toolbar_location = 'right' barchart.logo = None for renderer in barchart.select(GlyphRenderer): if renderer.data_source.data['height'] != [0]: year = renderer.data_source.data['year'] num_dnf = data['dnfs'].loc[data['year'] == year] num_entries = data['entries'].loc[data['year'] == year] percent_dnf = data['percentage_dnf'].loc[data['year'] == year] hover = HoverTool(renderers=[renderer], tooltips=[ ("# DNFs", '%d' % num_dnf.values[0]), ("# Entries", '%d' % num_entries.values[0]), ("% DNF", '%.2f%%' % (100 * percent_dnf.values[0])) ]) barchart.add_tools(hover) return barchart
def fnCreate_Chart_Bar_wf(df,stS= "all type reviews"): label1=CatAttr(columns=['word'], sort=False) plot = Bar(df, label=label1, values='freq',group='word', title="Top 10 Frequent Words for " + stS, legend=None, bar_width=0.9,xlabel='word',ylabel='freq') #,plot_width=450, plot_height=450 plot.logo=None plot.legend.label_text_font_size = "7pt" plot.legend.orientation = "horizontal" script, div = components(plot,CDN) return script, div
def generate_chart(team): data = generate_data(team) selectable_years = list(map(str, data.index.unique())) # Generate the chart UNFORTUNATELY using the high level plots. Streaming # a bunch of quads resulted in lots of graphics corruption when switching # teams. I would rather have the plots work all the time but really slow # then have the plot show the wrong information. barchart = Bar(data, values=blend(*SCORED_EVENTS, labels_name='event'), label=cat(columns='Year', sort=False), stack=cat(columns='event', sort=False), color=color(columns='event', palette=Spectral9, sort=False), xgrid=False, ygrid=False, plot_width=1000, plot_height=625, tools="pan,wheel_zoom,box_zoom,reset,resize") barchart.title = "Formula SAE Michigan - " + team barchart._xaxis.axis_label = "Teams" barchart._xaxis.axis_line_color = None barchart._xaxis.major_tick_line_color = None barchart._xaxis.minor_tick_line_color = None barchart._yaxis.axis_label = "Total Score" barchart._yaxis.axis_line_color = None barchart._yaxis.major_tick_line_color = None barchart._yaxis.minor_tick_line_color = None barchart.outline_line_color = None barchart.toolbar_location = 'right' barchart.logo = None # Hacky tooltips for renderer in barchart.select(GlyphRenderer): if renderer.data_source.data['height'] != [0]: year = renderer.data_source.data['Year'] place = data['Place'].loc[data['Year'] == year] score = data['Total Score'].loc[data['Year'] == year] hover = HoverTool(renderers=[renderer], tooltips=[("Year", '@Year'), ("Selection", '@event'), ("Event Score", '@height'), ("Total Score", '%.2f' % score.values[0]), ("Overall Place", '%d' % place.values[0])]) barchart.add_tools(hover) return barchart
def output_chart(issues_df, output_mode='static'): import datetime import bokeh from bokeh.models import HoverTool # Add timestamp to title issues_chart = Bar(issues_df, label='value_delivered', values='status', agg='count', stack='status', title=ISSUES_TITLE + " (Updated " + datetime.datetime.now().strftime('%m/%d/%Y') + ")", xlabel="Value Delivered", ylabel="Number of Use Cases", legend='top_right', tools='hover', color=brewer["GnBu"][3]) issues_chart.plot_width = DESTINATION_FRAME_WIDTH - (HTML_BODY_MARGIN * 2) issues_chart.plot_height = DESTINATION_FRAME_HEIGHT - (HTML_BODY_MARGIN * 2) issues_chart.logo = None issues_chart.toolbar_location = None hover = issues_chart.select(dict(type=HoverTool)) hover.tooltips = [("Value Delivered", "$x")] #--- Configure output --- reset_output() if output_mode == 'static': # Static file. CDN is most space efficient output_file(ISSUES_FILE, title=ISSUES_TITLE, autosave=False, mode='cdn', root_dir=None) # Generate file save(issues_chart, filename=ISSUES_FILE) elif output_mode == 'notebook': output_notebook() # Show inline show(issues_chart) else: # Server (using internal server IP, rather than localhost or external) session = bokeh.session.Session(root_url=BOKEH_SERVER_IP, load_from_config=False) output_server("ddod_chart", session=session) show(issues_chart)
def fnCreate_Chart_Bar(df): pd.options.html.border = 1 plot = Bar(df, label='ID', values='Tweet Count', group='ID', title="Top 5 contributors", legend=False, bar_width=1.8, xlabel='Users', ylabel='Tweets Count') plot.logo = None script, div = components(plot, CDN) return script, div
def generate_chart(event): data = get_data(TIMED_EVENTS[event]) # Bokeh doesn't let me control the order of the grouping! This is # frustrating since it will be different on every server launch barchart = Bar(data, values='percentage_dnf', label='year', color="FireBrick", xgrid=False, ygrid=False, plot_width=800, plot_height=500, tools="pan,wheel_zoom,box_zoom,reset,resize") barchart.title = "Formula SAE Michigan DNFs - " + event barchart._xaxis.axis_label = "Year" barchart._xaxis.axis_line_color = None barchart._xaxis.major_tick_line_color = None barchart._xaxis.minor_tick_line_color = None barchart._yaxis.axis_label = "Percentage DNF" barchart._yaxis.axis_line_color = None barchart._yaxis.major_tick_line_color = None barchart._yaxis.minor_tick_line_color = None barchart._yaxis.formatter = NumeralTickFormatter(format="0%") barchart.y_range = Range1d(0, 1) barchart.outline_line_color = None barchart.toolbar_location = 'right' barchart.logo = None for renderer in barchart.select(GlyphRenderer): if renderer.data_source.data['height'] != [0]: year = renderer.data_source.data['year'] num_dnf = data['dnfs'].loc[data['year'] == year] num_entries = data['entries'].loc[data['year'] == year] percent_dnf = data['percentage_dnf'].loc[data['year'] == year] hover = HoverTool(renderers=[renderer], tooltips=[("# DNFs", '%d' % num_dnf.values[0]), ("# Entries", '%d' % num_entries.values[0]), ("% DNF", '%.2f%%' % (100 * percent_dnf.values[0]))]) barchart.add_tools(hover) return barchart
def output_chart(issues_df,output_mode='static'): import datetime import bokeh from bokeh.models import HoverTool # Add timestamp to title issues_chart = Bar(issues_df, label='value_delivered', values='status', agg='count', stack='status', title=ISSUES_TITLE+" (Updated "+datetime.datetime.now().strftime('%m/%d/%Y')+")", xlabel="Value Delivered",ylabel="Number of Use Cases", legend='top_right', tools='hover', color=brewer["GnBu"][3] ) issues_chart.plot_width = DESTINATION_FRAME_WIDTH - (HTML_BODY_MARGIN * 2) issues_chart.plot_height = DESTINATION_FRAME_HEIGHT - (HTML_BODY_MARGIN * 2) issues_chart.logo = None issues_chart.toolbar_location = None hover = issues_chart.select(dict(type=HoverTool)) hover.tooltips = [ ("Value Delivered", "$x")] #--- Configure output --- reset_output() if output_mode == 'static': # Static file. CDN is most space efficient output_file(ISSUES_FILE, title=ISSUES_TITLE, autosave=False, mode='cdn', root_dir=None ) # Generate file save(issues_chart,filename=ISSUES_FILE) elif output_mode == 'notebook': output_notebook() # Show inline show(issues_chart) else: # Server (using internal server IP, rather than localhost or external) session = bokeh.session.Session(root_url = BOKEH_SERVER_IP, load_from_config=False) output_server("ddod_chart", session=session) show(issues_chart)
def generate_chart(year): data = get_data(year) plot_data = { 'country': data.index.tolist(), 'count': [float(i) for i in data.values.tolist()] } barchart = Bar(plot_data, label='country', values='count', color="red", xgrid=False, ygrid=False, plot_width=800, plot_height=500, tools="pan,wheel_zoom,box_zoom,reset,resize") barchart.title = "Formula SAE Michigan " + year + " Countries" barchart.x_range = FactorRange(factors=data.index.tolist()) barchart._xaxis.axis_label = "Country" barchart._xaxis.axis_line_color = None barchart._xaxis.major_tick_line_color = None barchart._xaxis.minor_tick_line_color = None barchart._yaxis.axis_label = "Number of Teams" barchart._yaxis.axis_line_color = None barchart._yaxis.major_tick_line_color = None barchart._yaxis.minor_tick_line_color = None barchart.outline_line_color = None barchart.toolbar_location = 'right' barchart.logo = None hover = HoverTool(tooltips=[("Country", '@x'), ("# Teams", '@height')]) barchart.add_tools(hover) return barchart
def generate_chart(): data = get_data() # Bokeh doesn't let me control the order of the grouping! This is # frustrating since it will be different on every server launch barchart = Bar(data, label='year', values='count', group=cat(columns='size', ascending=True, sort=True), color=color(columns='size', palette=Spectral4), legend='top_left', xgrid=False, ygrid=False, plot_width=800, plot_height=500, tools="pan,wheel_zoom,box_zoom,reset,resize") barchart.title = "Formula SAE Michigan Engine Cylinders" barchart._xaxis.axis_label = "Year" barchart._xaxis.axis_line_color = None barchart._xaxis.major_tick_line_color = None barchart._xaxis.minor_tick_line_color = None barchart._yaxis.axis_label = "Frequency" barchart._yaxis.axis_line_color = None barchart._yaxis.major_tick_line_color = None barchart._yaxis.minor_tick_line_color = None barchart.outline_line_color = None barchart.toolbar_location = 'right' barchart.logo = None hover = HoverTool(tooltips=[("Engine", '@size'), ("# Teams", '@height')]) barchart.add_tools(hover) return barchart
def generate_chart(year): data = get_data(year) plot_data = {'country': data.index.tolist(), 'count': [float(i) for i in data.values.tolist()]} barchart = Bar(plot_data, label='country', values='count', color="red", xgrid=False, ygrid=False, plot_width=800, plot_height=500, tools="pan,wheel_zoom,box_zoom,reset,resize") barchart.title = "Formula SAE Michigan " + year + " Countries" barchart.x_range = FactorRange(factors=data.index.tolist()) barchart._xaxis.axis_label = "Country" barchart._xaxis.axis_line_color = None barchart._xaxis.major_tick_line_color = None barchart._xaxis.minor_tick_line_color = None barchart._yaxis.axis_label = "Number of Teams" barchart._yaxis.axis_line_color = None barchart._yaxis.major_tick_line_color = None barchart._yaxis.minor_tick_line_color = None barchart.outline_line_color = None barchart.toolbar_location = 'right' barchart.logo = None hover = HoverTool(tooltips=[("Country", '@x'), ("# Teams", '@height')]) barchart.add_tools(hover) return barchart
def generate_chart(year): data = get_data(year) barchart = Bar(data, values=blend(*SCORED_EVENTS, labels_name='event'), label=cat(columns='Team', sort=False), stack=cat(columns='event', sort=False), color=color(columns='event', palette=Spectral9, sort=False), xgrid=False, ygrid=False, legend='top_right', plot_width=1000, plot_height=625, tools="pan,wheel_zoom,box_zoom,reset,resize") barchart.title = "Formula SAE Michigan " + str( year) + " Total Scores by Place" barchart._xaxis.axis_label = "Teams" barchart._xaxis.axis_line_color = None barchart._xaxis.major_tick_line_color = None barchart._xaxis.minor_tick_line_color = None barchart._xaxis.major_label_text_font_size = '0.6em' barchart._yaxis.axis_label = "Total Score" barchart._yaxis.axis_line_color = None barchart._yaxis.major_tick_line_color = None barchart._yaxis.minor_tick_line_color = None barchart.outline_line_color = None barchart.toolbar_location = 'right' barchart.logo = None return barchart
portions_df = pd.DataFrame.from_records(portions, columns=["Name", "Portion","HasFeature","SaleStatus", "Feature"] ) # Make the chart TOOLS = '' plt2 = Bar(portions_df, label="Name", values="Portion", stack = "SaleStatus", legend="bottom_right", color=['Green','Red'], xlabel="Listing feature", ylabel="Portion sold or unsold", title="Impact of listing features on likelihood of sale", tools=TOOLS) plt2.logo = None plt2.toolbar_location = None plt2.y_range = Range1d(start=0,end=1) # Save the plot output_file("./templates/plot3_new.html") # show(plt2) ####################################################### # Look at dependence of sale outcome on seller feedback score ####################################################### # hist = Histogram(data_sold, values='feedbackScore', color='listingType', # title="Distribution of feedback scores for sold items", legend='top_left')
def summarize_plans(state, age, npi): todaysdate = str(datetime.now()) age = str(age) if age > '65': age = '65' elif age < '20': age = '20' # filter based on what plans are current (not expired) and age filteredplans = pd.read_hdf('webapp/data/plan-rates.h5', state, where=['(Age==age) & (RateExpirationDate > todaysdate) & (RateEffectiveDate < todaysdate)'], columns = ['IndividualRate', 'MetalLevel', 'Age','URLForSummaryofBenefitsCoverage','PlanMarketingName']) stateave = filteredplans.IndividualRate.mean() myave = stateave # plot it #filteredplans.groupby('MetalLevel').IndividualRate.mean().plot(kind='bar') #statebardf = filteredplans.groupby('MetalLevel').IndividualRate.mean() statebardf = filteredplans.groupby('MetalLevel', as_index=False).mean() #p = mpl.to_bokeh() if npi == '': p = Bar(filteredplans.groupby('MetalLevel').IndividualRate.mean(), values='IndividualRate', xlabel="", ylabel="Montly Premium ($)") else: print 'input npi is ' + npi # read hdf5 of provider-plan pairings provnplanpd = pd.read_hdf('webapp/data/plan_providers.h5', state) # make a list of planids for the input npi planlst = provnplanpd[provnplanpd.npi == npi].plan_id.values print planlst # read in hdf5 of plan info planinfo = pd.read_hdf('webapp/data/plan-rates.h5', state, where=['(Age==age) & (RateExpirationDate > todaysdate) & (RateEffectiveDate < todaysdate)']) # for each planid, get the first entry and concatenate them together. filteredplans = planinfo[planinfo.PlanId==planlst[0]].groupby('PlanId', as_index=False).first() filteredplans.head() #pd.concat([filteredplans, filteredplans]) for ii in range(1, len(planlst)): filteredplans = pd.concat([filteredplans, planinfo[planinfo.PlanId==planlst[ii]].groupby('PlanId', as_index=False).first()]) provbardf = filteredplans.groupby('MetalLevel', as_index=False).mean() provbardf['average'] = ['provider rates']*len(provbardf.MetalLevel.values) statebardf['average'] = ['state average']*len(provbardf.MetalLevel.values) myave = statebardf.IndividualRate.mean() #provbardf['average'] = [1, 1] #statebardf['average'] = [2, 2] #plotdf = pd.merge(statebardf, provbardf, on='MetalLevel') plotdf = pd.concat([provbardf, statebardf]) #plotdf['state average'] = statebardf['IndividualRate'] #plotdf['provider rates'] = provbardf['IndividualRate'] print plotdf p = Bar(plotdf, label='MetalLevel', values='IndividualRate', group='average', legend='top_right', xlabel="", ylabel="Montly Premium ($)") p.logo = None p.plot_height=400 p.toolbar_location = None script,div = components(p) print filteredplans.to_dict(orient='records') return {'num_plans':len(filteredplans), 'script': script, 'plot_div': div, 'national_comp': format_price_comp(float(age2nationalAverage(age))-myave), 'state_comp': format_price_comp(float(stateave)-myave), 'plans': render_template('plans.html', plans=filteredplans.sort_values(by='IndividualRate').to_dict(orient='records'))}
def summarize_plans(state, age, npi): todaysdate = str(datetime.now()) age = str(age) if age > '65': age = '65' elif age < '20': age = '20' # filter based on what plans are current (not expired) and age filteredplans = pd.read_hdf( 'webapp/data/plan-rates.h5', state, where=[ '(Age==age) & (RateExpirationDate > todaysdate) & (RateEffectiveDate < todaysdate)' ], columns=[ 'IndividualRate', 'MetalLevel', 'Age', 'URLForSummaryofBenefitsCoverage', 'PlanMarketingName' ]) stateave = filteredplans.IndividualRate.mean() myave = stateave # plot it #filteredplans.groupby('MetalLevel').IndividualRate.mean().plot(kind='bar') #statebardf = filteredplans.groupby('MetalLevel').IndividualRate.mean() statebardf = filteredplans.groupby('MetalLevel', as_index=False).mean() #p = mpl.to_bokeh() if npi == '': p = Bar(filteredplans.groupby('MetalLevel').IndividualRate.mean(), values='IndividualRate', xlabel="", ylabel="Montly Premium ($)") else: print 'input npi is ' + npi # read hdf5 of provider-plan pairings provnplanpd = pd.read_hdf('webapp/data/plan_providers.h5', state) # make a list of planids for the input npi planlst = provnplanpd[provnplanpd.npi == npi].plan_id.values print planlst # read in hdf5 of plan info planinfo = pd.read_hdf( 'webapp/data/plan-rates.h5', state, where=[ '(Age==age) & (RateExpirationDate > todaysdate) & (RateEffectiveDate < todaysdate)' ]) # for each planid, get the first entry and concatenate them together. filteredplans = planinfo[planinfo.PlanId == planlst[0]].groupby( 'PlanId', as_index=False).first() filteredplans.head() #pd.concat([filteredplans, filteredplans]) for ii in range(1, len(planlst)): filteredplans = pd.concat([ filteredplans, planinfo[planinfo.PlanId == planlst[ii]].groupby( 'PlanId', as_index=False).first() ]) provbardf = filteredplans.groupby('MetalLevel', as_index=False).mean() provbardf['average'] = ['provider rates'] * len( provbardf.MetalLevel.values) statebardf['average'] = ['state average'] * len( provbardf.MetalLevel.values) myave = statebardf.IndividualRate.mean() #provbardf['average'] = [1, 1] #statebardf['average'] = [2, 2] #plotdf = pd.merge(statebardf, provbardf, on='MetalLevel') plotdf = pd.concat([provbardf, statebardf]) #plotdf['state average'] = statebardf['IndividualRate'] #plotdf['provider rates'] = provbardf['IndividualRate'] print plotdf p = Bar(plotdf, label='MetalLevel', values='IndividualRate', group='average', legend='top_right', xlabel="", ylabel="Montly Premium ($)") p.logo = None p.plot_height = 400 p.toolbar_location = None script, div = components(p) print filteredplans.to_dict(orient='records') return { 'num_plans': len(filteredplans), 'script': script, 'plot_div': div, 'national_comp': format_price_comp(float(age2nationalAverage(age)) - myave), 'state_comp': format_price_comp(float(stateave) - myave), 'plans': render_template('plans.html', plans=filteredplans.sort_values( by='IndividualRate').to_dict(orient='records')) }
portions, columns=["Name", "Portion", "HasFeature", "SaleStatus", "Feature"]) # Make the chart TOOLS = '' plt2 = Bar(portions_df, label="Name", values="Portion", stack="SaleStatus", legend="bottom_right", color=['Green', 'Red'], xlabel="Listing feature", ylabel="Portion sold or unsold", title="Impact of listing features on likelihood of sale", tools=TOOLS) plt2.logo = None plt2.toolbar_location = None plt2.y_range = Range1d(start=0, end=1) # Save the plot output_file("./templates/plot3_new.html") # show(plt2) ####################################################### # Look at dependence of sale outcome on seller feedback score ####################################################### # hist = Histogram(data_sold, values='feedbackScore', color='listingType', # title="Distribution of feedback scores for sold items", legend='top_left') # # # Save the plot