def school_types_bar_chart():
    schools_2016 = get_schools('urn/2016.urns.list', 2016)
    schools_2015 = get_schools('urn/2015.urns.list', 2015)

    y_data = { 'SR2015': [], 'SR2016': [] }
    x_categories = []
    est_types = {}

    def _update_types(schools_dict):
        for s in schools_dict:
            est_type = s.data['typeOfEstablishment']['label']
            year = s.data['comp']
            try:
                est_types[est_type][year] += 1
            except KeyError:
                est_types[est_type] = { 2015: 0, 2016: 0 }
                est_types[est_type][year] += 1

    _update_types(schools_2015)
    _update_types(schools_2016)

    for est_type, yc in est_types.iteritems():
        y_data['SR2015'].append(yc[2015])
        y_data['SR2016'].append(yc[2016])
        x_categories.append(est_type)

    output_file('visuals/establisment_types.html')
    bar = Bar(y_data, cat=x_categories, title='Establishment Types and count', xlabel='Type of Establishment', ylabel='Count', width=1000, height=600, legend=True)

    show(bar)
Example #2
0
def donutchart(*args, **kwargs):
    #get info from submitted data
    data = kwargs.get('data', 'None')
    ids = kwargs.get('ids', 'None')
    vals = kwargs.get('vals', 'None')
    val_name = kwargs.get('val_name', 'None')
    v_name = kwargs.get('v_name', 'None')
    out_file = kwargs.get('out_file', 'None')

    if vals or data or ids or val_name == 'None':
        return "Data must be submitted"

    df = df_from_json(data)
    df = df.sort("total", ascending=False)
    df = pd.melt(df, id_vars=[ids],
                value_vars=[vals],
                value_name=val_name,
                var_name=v_name)
    d = Donut(df, label=[ids, v_name],
            values=v_name,
            text_font_size='8pt',
            hover_text='vals')

    output_file(out_file)
    save(d)
Example #3
0
 def __init__(self, data, valuekey, labelkey, title='test', legend='test'):
     self.__data = data
     self.__title = title
     self.__legend = legend
     self.__vkey = valuekey
     self.__lkey = labelkey 
     output_file("stacked_bar.html")
Example #4
0
	def exibir(self):
		for i in self.dados.keys():
			if len(self.dados[i]) > 0: continue
			else: return
		defaults.width, defaults.height = 400, 300
		# prepare some data
		# input options
		hist_pontuacao = Histogram(self.dados["pontos"],
						title="Grades por pontuação",
						xlabel="Pontuação",
						ylabel="Número de grades",
						responsive=True,
						bins=30)

		hist_tamanho = Histogram(self.dados["tamanhos"],
						title="Grades por quantidade de disciplinas",
						xlabel="Número de disciplinas",
						ylabel="Número de grades",
						responsive=True,
						bins=8)
		
		hist_pop = Histogram(self.dados["popularidade"],
						title="Ocorrências da disciplina x",
						xlabel="Disciplina",
						ylabel="Ocorrências nas grades",
						responsive=True,
						bins=46)
		
		output_file("html/histograms.html")

		show(hplot(	hist_pontuacao,
					hist_tamanho,
					hist_pop
		))		
def graph_feature_importance(olddf, model):
    """
    Output: Plot of Feature Importance
    """
    lab_feats = sorted(zip(olddf.columns, model.feature_importances_), key=lambda x : x[1])[::-1]
    total,cnt = 0,0
    for n,v in lab_feats:
        total+=v
        if total<=.98:
            cnt+=1
            print cnt,n,v
    graph_feats = lab_feats[:cnt]
    col_names = []
    feat_vals = []
    for name, val in graph_feats:
        col_names.append(name)
        feat_vals.append(val)

    df = pd.concat([pd.DataFrame(col_names, columns=['columns']), pd.DataFrame(feat_vals, columns=['featimpt'])], axis=1).sort_values(by='featimpt', ascending=False)

    print df

    p = Bar(df, 'columns', values='featimpt', title="Feature Importance From Model")

    output_file("templates/feat_impt.html", title="Feature Importance From Model")

    save(p)
Example #6
0
def single_bokeh_graph(args, marked_fn, unmarked_corpus,
                       token='compare', bin_count=400):

    print(marked_fn)
    unmarked_fn = os.path.basename(marked_fn)
    unmarked_text = clean_and_read_text(args.unmarked_corpus_folder +
                                        '/' + unmarked_fn)
    text = clean_and_read_text(marked_fn)
    if token == 'compare':
        # assumes that you've passed a True, so you're
        # trying to graph comparatively.
        locations, quote_n, bins = find_bin_counts(
            find_quote_characters(unmarked_text), bin_count)
        _, caret_n, _ = find_bin_counts(find_carets(text), bin_count)
        n = quote_n - caret_n
    elif token == 'caret':
        locations, n, bins = find_bin_counts(find_carets(text), bin_count)
    else:
        locations, n, bins = find_bin_counts(
            find_quoted_quotes(unmarked_text), bin_count)
    d_frame = pd.DataFrame(n, columns=['count'])
    output_file('bokeh_graphs/' + re.sub(r'\.txt', '',
                os.path.basename(marked_fn)) + '.html')
    p = Bar(d_frame, legend=False, plot_width=1200)
    p.xaxis.visible = False
    p.xgrid.visible = False
    save(p)
Example #7
0
	def analyze(self):
		plots = False
		h5_filename = self.output_filename + '.h5'
		with tb.open_file(h5_filename, 'r+') as in_file_h5:
			raw_data = in_file_h5.root.raw_data[:]
			meta_data = in_file_h5.root.meta_data[:]
			hit_data = self.dut.interpret_raw_data(raw_data, meta_data)
			in_file_h5.createTable(in_file_h5.root, 'hit_data', hit_data, filters=self.filter_tables)
			hits = hit_data['col'].astype(np.uint16)
			hits = hits * 64
			hits = hits + hit_data['row']
			value = np.bincount(hits)
			value = np.pad(value, (0, 64*64 - value.shape[0]), 'constant')
			full_occupation = np.full(4096, 100, dtype=int)
			difference = full_occupation - value
			tot_diff = abs(np.sum(difference))
			if tot_diff<10000: plots=True;
			self.not_fired.append(tot_diff)
			logging.info('Shmoo plot entry: %s', str(tot_diff))

		if plots == True:
			occ_plot, H = plotting.plot_occupancy(h5_filename)
			tot_plot, _ = plotting.plot_tot_dist(h5_filename)
			lv1id_plot, _ = plotting.plot_lv1id_dist(h5_filename)
			output_file(self.output_filename + '.html', title=self.run_name)
			save(vplot(occ_plot, tot_plot, lv1id_plot))
			return H
Example #8
0
def plot_histogram(same, diff):
    df = {"PAINS vs. PAINS": same, "PAINS vs. ChEMBL": diff}
    output_file("histogram_pains_self_diff.html")
    hist = Histogram(df, bins=20, density=True, legend=True)
    hist.x_range = Range1d(0, 1)
    #hist.legend.orientation = "top_right"
    show(hist)
def graphstocks(ssymbol):
    """ Very simple embedding of a polynomial chart"""
    # Grab the inputs arguments from the URL
    # This is automated by the button
    args = ["ADAM"] 
    args = request.args

    # Get all the form arguments in the url with defaults
    color = colors[getitem(args, 'color', 'Black')]
    _from = int(getitem(args, '_from', 0))
    to = int(getitem(args, 'to', 10))

    # Create a polynomial line graph
    #x = list(range(_from, to + 1))
    #fig = figure(title="Polynomial")
    #fig.line(x, [i ** 2 for i in x], color=color, line_width=2)
    AAPL= pd.read_csv("https://ichart.yahoo.com/table.csv?s="+ssymbol+"&a=0&b=1&c=2000&d=0&e=1&f=2010",parse_dates=['Date'])   
    data = dict(AAPL=AAPL['Adj Close'], Date=AAPL['Date'])
    tsline = TimeSeries(data,x='Date', y='AAPL', ylabel='Stock Prices', legend=True)
    #tsline=TimeSeries(data,x='Date', y=['AAPL'], color=['AAPL'], dash=['AAPL'],
   #                   title="Timeseries", ylabel = 'Stock Prices', legend=True)
#    tspoint=TimeSeries(data,x='Date',y=[ssymbol], dash=[ssymbol],title="Timeseries",ylabel='Stock Prices', legend=True)
    output_file("timeseries.html")
    fig=vplot(tsline)
    
    # Configure resources to include BokehJS inline in the document.
    # For more details see:
    #   http://bokeh.pydata.org/en/latest/docs/reference/resources_embedding.html#bokeh-embed
    js_resources = JS_RESOURCES.render(
        js_raw=INLINE.js_raw,
        js_files=INLINE.js_files
    )

    css_resources = CSS_RESOURCES.render(
        css_raw=INLINE.css_raw,
        css_files=INLINE.css_files
    )
#from: http://bokeh.pydata.org/en/0.11.1/docs/releases/0.11.0.html  
# Before:

#html = file_html(layout, None, title=title, template=template, js_resources=js_resources, css_resources=css_resources)
#v0.11:
#
#html = file_html(layout, resources=(js_resources, css_resources), title=title, template=template)
 
   # For more details see:
    #   http://bokeh.pydata.org/en/latest/docs/user_guide/embedding.html#components
    script, div = components(fig, INLINE)
    html = render_template(
        'embed.html',
        plot_script=script,
        plot_div=div,
        js_resources=js_resources,
        css_resources=css_resources,
        color=color,
        _from=_from,
        to=to
    )
    return encode_utf8(html)
def dotplot(pname, filename, data, title, ylabel):
    titlex=pname+" : "+title
    filename=filename+"_"+title
    output_file(filename+".html")
    values = [value for name, value in data.items()]
    names = [name for name, value in data.items()]
    dots = Dot(values, cat=names, title=titlex, ylabel=ylabel, legend=False)
    show(dots)
def ts_vis_auto(steps,path):
    try:
        index_name,my_trend = parse_csv(path)
        if my_trend.count(0) <= 30:
            index_name,index_name_future,my_trend,future = holt_pred(steps,path) 
        else:
            index_name,index_name_future,my_trend,future = sarima(steps,path) 
        slope = np.polyfit(range(len(my_trend[-156:])),my_trend[-156:],1)[0]
        if slope >= 0:
            print 'This is a upward trending with slope: ', slope
            html_path = '/Users/royyang/Desktop/trending_project/html/'+path.split('/')[-1][:-4]+'.html'
    #            html_path = 'example.html'            
            output_file(html_path, title="bohek example")
            source1 = ColumnDataSource(
                    data=dict(
                        x1=index_name,
                        y1=my_trend,
                        Time1=[str(var).split()[0] for var in index_name],
                        Intensity1=my_trend 
                    )
                )
                
            source2 = ColumnDataSource(
                    data=dict(
                        x2=index_name_future,
                        y2=future,
                        Time1=[str(var).split()[0] for var in index_name_future],
                        Intensity1=[np.round(var,0) for var in future]
                    )
                )
            
            TOOLS = "pan,wheel_zoom,box_zoom,reset,save,hover"
            
            p = figure(x_axis_type="datetime",plot_width=1000, plot_height=600, tools=TOOLS)
            
            p.line('x1','y1', color='red',legend='Past',source=source1)
            p.circle('x1','y1',size = 5,color = 'red',source=source1)
            p.line('x2','y2', color='blue', legend='Future',source=source2)
            p.circle('x2','y2',size = 8,color = 'blue',source=source2)
            p.xaxis.axis_label="Time"
            p.yaxis.axis_label="Search Intensity"
            p.title = "Search Prediction of "+path.split('/')[-1].split('.')[0]
            p.background_fill= "#cccccc"
            p.grid.grid_line_color="white"
            p.legend.label_standoff = 20
            p.legend.glyph_width = 50
            p.legend.legend_spacing = 15
            p.legend.legend_padding = 1
            p.legend.orientation = "top_left"
            hover = p.select(dict(type=HoverTool))
            hover.tooltips = OrderedDict([
                ('Time', '@Time1'),
                ('Intensity', '@Intensity1'),
            ])
    #            save(p)
            show(p)
    except Exception as err:
        print 'There is no content in file: '+path
Example #12
0
 def plot(self, identifier, chart, data, width):
     chart_title = chart + " - " + identifier;
     y_label = "Social Cost (2007 US $)";
     if(chart == "emissions"):
         y_label = "Total emissions (1E12 g)";
     output_file("plots/tables/" + chart + "/plots/" + identifier + "_" + chart + "_visualization.html", title = chart_title);
     
     p = Bar(data, width=width, height=700, title=chart_title, xlabel="Source", ylabel=y_label, legend="top_left", stacked=True, palette=self.colors, tools=self.TOOLS);
     save(p);
def create_barChart(countDict):
    hover = HoverTool(
        tooltips=[
                  ("Count", "@height"),
                  ("Label","@label")]  )
    p=Bar(countDict, values='taxaCount',label='label', tools=[hover], title="Number of annotated taxa", xlabel="taxa", ylabel="count")
    output_file("bokeh_bar.html") # save file to html
    #show(p)
    return p
def histogram_exptime():
    """
    Create a histogram showing the distribution of exposure times for
    the composite lightcurves
    """

    logging.info('Creating exposure time historgram')

    data_dir = get_settings()['composite_dir']

    exptime_data = {}
    for dataset in glob.glob(os.path.join(data_dir, '*.fits')):
        with fits.open(dataset) as hdu:
            targname = os.path.split(dataset)[-1].split('_')[4]
            exptime = hdu[0].header['EXPTIME']

            if targname in exptime_data:
                exptime_data[targname] += exptime
            else:
                exptime_data[targname] = exptime

    charts.output_file(os.path.join(get_settings()['plot_dir'], 'exptime_histogram.html'))

    times = np.array(exptime_data.values())
    names = np.array(exptime_data.keys())
    indx = np.argsort(times)

    times = list(times[indx])[::-1][:30]
    names = list(names[indx])[::-1][:30]

    bar = charts.Bar(times,
                     label=names,
                     xlabel='Target',
                     ylabel='Exptime (s)',
                     width=700,
                     height=400,
                     title='Cumulative Exptime per Target')

    bar.background_fill = '#cccccc'
    bar.outline_line_color = 'black'

    # change just some things about the x-grid
    #bar.xgrid.grid_line_color = None

    # change just some things about the y-grid
    #bar.ygrid.band_fill_alpha = 0.1
    #bar.ygrid.band_fill_color = "navy"

    #bar.toolbar_location = None

    #charts.show(bar)

    script, div = components(bar)

    plot_file = os.path.join(get_settings()['plot_dir'], 'exptime_histogram.html')
    charts.save(obj=bar, filename=plot_file)
    set_permissions(plot_file)
Example #15
0
def getDistrib():
        if request.method == 'GET':
                return render_template('distrib.html')
        else:
                bronx=[[2009,'https://data.cityofnewyork.us/resource/en2c-j6tw.json'],[2010,'https://data.cityofnewyork.us/resource/n2s5-fumm.json'],[2011,'https://data.cityofnewyork.us/resource/bawj-6bgn.json'],[2012,'https://data.cityofnewyork.us/resource/3qfc-4tta.json']]
                brooklyn=[[2009,'https://data.cityofnewyork.us/resource/rmv8-86p4.json'],[2010,'https://data.cityofnewyork.us/resource/w6yt-hctp.json'],[2011,'https://data.cityofnewyork.us/resource/5mw2-hzqx.json'],[2012,'https://data.cityofnewyork.us/resource/bss9-579f.json']]
                manhattan=[[2009,'https://data.cityofnewyork.us/resource/956m-xy24.json'],[2010,'https://data.cityofnewyork.us/resource/ad4c-mphb.json'],[2011,'https://data.cityofnewyork.us/resource/ikqj-pyhc.json'],[2012,'https://data.cityofnewyork.us/resource/dvzp-h4k9.json']]
                queens=[[2009,'https://data.cityofnewyork.us/resource/m59i-mqex.json'],[2010,'https://data.cityofnewyork.us/resource/crbs-vur7.json'],[2011,'https://data.cityofnewyork.us/resource/s3zn-tf7c.json'],[2012,'https://data.cityofnewyork.us/resource/jcih-dj9q.json']]
                statenIsland=[[2009,'https://data.cityofnewyork.us/resource/cyfw-hfqk.json'],[2010,'https://data.cityofnewyork.us/resource/wv4q-e75v.json'],[2011,'https://data.cityofnewyork.us/resource/a5qt-5jpu.json'],[2012,'https://data.cityofnewyork.us/resource/tkdy-59zg.json']]
                featureNames=[['comparable_rental_2_market_value_per_sqft',  'Market value per square foot'],['comparable_rental_2_full_market_value',      'Full market value'],['comparable_rental_2_year_built',             'Year Built'],['comparable_rental_2_gross_income_per_sqft', 'Gross income per square foot']]
                #request was a POST (get the var from the form)
		#... All Boroughs are selected by default
                app_xplor.vars['feat'] = request.form['feat']
                app_xplor.vars['year'] = request.form['year']

                #Translating name of the feature into the name in the original database
                dbFeatureName = convertField(app_xplor.vars['feat'],featureNames)

		#Building the queries
		queryA = buildQuery(int(app_xplor.vars['year']),bronx,dbFeatureName)
		queryB = buildQuery(int(app_xplor.vars['year']),brooklyn,dbFeatureName)
		queryC = buildQuery(int(app_xplor.vars['year']),manhattan,dbFeatureName)
		queryD = buildQuery(int(app_xplor.vars['year']),queens,dbFeatureName)
		queryE = buildQuery(int(app_xplor.vars['year']),statenIsland,dbFeatureName)
                #executing the queries on the tables
                rawA = pd.read_json(queryA)
                rawB = pd.read_json(queryB)
                rawC = pd.read_json(queryC)
                rawD = pd.read_json(queryD)
		rawE = pd.read_json(queryE)
		
                #Managind the data to be input for a boxplot 
                rawA['Borough']='Bronx'
                rawB['Borough']='Brooklyn'
                rawC['Borough']='Manhattan'
                rawD['Borough']='Queens'
		rawE['Borough']='Staten Island'
		
                allData = pd.concat([rawA, rawB, rawC, rawD, rawE])
                cleanData= allData.dropna()
                cleanData.columns=[app_xplor.vars['feat'],'Borough']
		
                #plot
                defaults.width = 450
                defaults.height = 350   
                box_plot = BoxPlot(cleanData, label='Borough',title=str(app_xplor.vars['year']))
		#box_plot = BoxPlot(cleanData, label='Borough',title='Year')
                output_file("templates/results.html")
                show(
                    vplot(
                        hplot(box_plot)
                    )
                )
                return redirect('/goDistrib')
Example #16
0
    def plot(self, pct=False,
            output_file_path='temp_plot.html', title="", legend=True):
        """
        Allows the user to plot the timeseries data in self.content 
        using Bokeh. 

        Parameters
        ----------
        pct: bool
            Transformes the data to be percent change.
        output_file_path: str
            Path, including the name, for the output file.
        title: str
            The title of the graph and the html page.
        legend: bool
             Whether to include the legend or not.
        """
        # Output to static HTML file
        output_file(output_file_path, title=title)

        no_cols_needed = len(self.content.columns)
        if no_cols_needed == 3: Spectral = bokeh.palettes.Spectral3
        if no_cols_needed == 4: Spectral = bokeh.palettes.Spectral4
        if no_cols_needed == 5: Spectral = bokeh.palettes.Spectral5
        if no_cols_needed == 6: Spectral = bokeh.palettes.Spectral6
        if no_cols_needed == 7: Spectral = bokeh.palettes.Spectral7
        if no_cols_needed == 8: Spectral = bokeh.palettes.Spectral8
        if no_cols_needed == 9: Spectral = bokeh.palettes.Spectral9
        if no_cols_needed == 10: Spectral = bokeh.palettes.Spectral10
        if no_cols_needed >= 11: Spectral = bokeh.palettes.Spectral11


        data = self.content
        # Bokeh stumbles if the series starts with a nan.  
        # Hopefully will be fixed in Bokeh 0.9.4
        data = data.dropna(thresh=len(data.columns), axis=1)
        data.iloc[0] = data.iloc[0].fillna(0)

        p = TimeSeries(data, legend=legend, title=title, 
                width=800, height=350)
                # width=800, height=350, palette=Spectral)

        if pct:
            data2 = self.content.pct_change()
            data2 = data2.dropna(thresh=len(data2.columns), axis=1)
            data2.iloc[0] = data2.iloc[0].fillna(0)
            p2 = TimeSeries(data2, legend=legend, title="Percent Change", 
                width=800, height=350)
                # width=800, height=350, palette=Spectral)
            # show(vplot(p,p2))
            show(p2)
        else:
            show(p)
    def export():
        nonlocal data

        import bokeh.charts as bch
        from bokeh.layouts import column
        # from bokeh.models import HoverTool, GlyphRenderer
        bch.output_file("Chart.html")

        data = data.iloc[1:, :]

        # TOOLS = "pan, wheel_zoom, box_zoom, crosshair, resize, reset "# , hover"

        title = "History (total result: {0:.2f} €)".format(result)
        if bonus > 0:
            title = title[:-1] + ", excluding Bonus: {0:.2f} €)".format(bonus)

        cols = ["Paid-in", "Balance", "Normalised", "Total Result"]
        if bonus > 0:
            cols = ["Paid-in", "Balance", "Normalised",
                    "Total Result incl Bonus", "Total Result"]

        tsline = bch.TimeSeries(data,
                                x="Time",
                                y=cols,
                                title=title,  # tools=TOOLS,
                                ylabel='Euro', legend=True,
                                width=1250, height=550)
        """
        from bokeh.models import HoverTool
        hover = HoverTool(
            tooltips=[
                ("index", "$index"),
                ("(x,y)", "($x, $y)"),
                ("desc", "$balance"),
                # ("test", data.iloc["$index", 4])
            ]
        )

        tsline.add_tools(hover)
        """

        if open_browser:
            bch.show(column(tsline))
        else:
            bch.save(column(tsline))

        import matplotlib.pyplot as plt
        import matplotlib
        matplotlib.style.use('ggplot')

        data.plot(x="Time", y=cols)
        plt.savefig("Chart.pdf")
Example #18
0
File: bok.py Project: vlall/pyrista
	def __init__(self, local_ip='n/a', public_ip='n/a', arp = []):

		# Set palette of colors for n vlans 
		palette = [
		"#004529", "#006837", "#238443", "#41ab5d", "#78c679", "#addd8e", 
		"#d9f0a3", "#f7fcb9", "#ffffe5","#084081", "#0868ac", "#2b8cbe", "#4eb3d3", "#7bccc4", 
		"#a8ddb5", "#ccebc5", "#e0f3db", "#f7fcf0","#4d004b", "#810f7c", "#88419d", "#8c6bb1",
		"#EFEFEF","#CFCFCF","#5F5F5F","#000000", "#8c96c6", "#9ebcda", "#bfd3e6", "#e0ecf4", 
		"#f7fcfd","#fff7fb", "#ece2f0", "#d0d1e6", "#a6bddb", "#67a9cf", "#3690c0", "#02818a", 
		"#016c59", "#014636","#67001f", "#980043", "#ce1256","#e7298a", "#df65b0", "#c994c7", 
		"#d4b9da", "#e7e1ef", "#f7f4f9", "#fff7ec", "#fee8c8", "#fdd49e", "#fdbb84", "#fc8d59", 
		"#ef6548", "#d7301f", "#b30000", "#7f0000"
		]
		try:
		    import pandas as pd
		except ImportError as e:
		    raise RuntimeError("Data requires pandas (http://pandas.pydata.org) to be installed")

		data = pd.read_csv(join(dirname(__file__), "vlan.csv"))
		# pandas magic
		df = data[data.columns[:-1]]
		df2 = df.set_index(df[df.columns[0]].astype(str))
		df2.drop(df.columns[0], axis=1, inplace=True)
		df3 = df2.transpose()
		output_file("output/switch.html", title = 'vlan map')
		# text_input = TextInput(value="VLAN NAME", title="Make Vlan:", callback= )

		# Make Heapmap
		hm = HeatMap(df3, title="VLANs", width=950, palette=palette)

		# Make Ip/Arp Table		
		x = [ 'Local', 'Public']
		y = [ local_ip,public_ip]
		for i in arp:
			valueX = i[1].strip().strip("()")
			valueY = i[0].strip().strip("()")			
			x.append(valueX)
			y.append(valueY)
		data = dict(
		    sourceCol=x,
		    ipCol=y,
		)
		source = ColumnDataSource(data)
		columns = [
		    TableColumn(field="sourceCol", title="Source"),
		    TableColumn(field="ipCol", title="IP Address"),
		]

		data_table = DataTable(source=source, columns=columns, width=650, height=450)
		p = vform(hm,data_table)
		show(p)
def plot_accuracies_bokeh(accuracies, proteins, title, directory='C:\\uday\\gmu\\ngrams\\july_2016_results\\', ext='html'):
    if not os.path.exists(directory):
        os.makedirs(directory)
    filename = "%s.%s" % (title, ext)
    path_plus_filename = os.path.join(directory, filename)
    output_file(path_plus_filename)
    methods = ['RF', 'SVM', 'KNN', 'GNB']
    accuracies_dict = {}
    proteins_and_accuracies = zip(proteins, accuracies)
    TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
    for protein, accuracy in proteins_and_accuracies:
        accuracies_dict[protein] = accuracy
    bar = Bar(SortedDict(accuracies_dict), methods, title=title, stacked=False, legend='top_right', ylabel="accuracy", tools=TOOLS)
    show(bar)
Example #20
0
def aggregate(transaction_history):
    net = dict()
    buy = dict()
    sell = dict()
    interest = dict()
    dividend = dict()
    historical = dict()
    
    for t in transaction_history:
        quarter = "%s-Q%i" % (t.date.year, (t.date.month-1)//3+1)
        net[quarter] = float(handleNull(net.get(quarter))) + float(t.cashflow)
        if t.kind == Transaction.BUY:
            buy[quarter] = float(handleNull(buy.get(quarter))) + float(t.cashflow)
        elif t.kind == Transaction.SELL:
            sell[quarter] = float(handleNull(sell.get(quarter))) + float(t.cashflow)
        elif t.kind == Transaction.INTEREST:
            interest[quarter] = float(handleNull(interest.get(quarter))) + float(t.cashflow)
        elif t.kind == Transaction.DIVIDEND:
            dividend[quarter] = float(handleNull(dividend.get(quarter))) + float(t.cashflow)
        elif t.kind == Transaction.HISTORICAL or t.kind == Transaction.CURRENT:
            historical[quarter] = float(handleNull(historical.get(quarter))) + float(t.cashflow)

    net = addMissingQuarters(net)
    buy = addMissingQuarters(buy)
    sell = addMissingQuarters(sell)
    interest = addMissingQuarters(interest)
    dividend = addMissingQuarters(dividend)
    historical = addMissingQuarters(historical)

    d = {'net': pd.Series(net),
         'buy': pd.Series(buy), 
         'sell': pd.Series(sell),
         'interest':pd.Series(interest),
         'dividend':pd.Series(dividend),
         'historical':pd.Series(historical)}

    df = pd.DataFrame(d)
    df['label']=df.index
    p1 = Bar(df, 
            values = blend('buy','sell','interest','dividend','historical',name='cashflow', labels_name='cf'),
            label=cat(columns='label',sort=False),
            stack=cat(columns='cf',sort=False))

    p2 = Bar(df,
             values = blend('net'),
             label='label')

    output_file("test.html")
    
    show(vplot(p1, p2))
Example #21
0
def static_bar_plot(plug):
    han2 = prepare_han2(plug)
    start_time = str(han2.head(1).READING_DATETIME.values[0])[:10]
    end_time = str(han2.tail(1).READING_DATETIME.values[0])[:10]
    # customer = han2.CUSTOMER_ID.unique()[0]
    customer = '10082576'  # FIXME
    plug = han2.PLUG_NAME.unique()[0]
    output_file("templates/plot.html")
    p = Bar(han2, 'HOUR',
            values='READING_DELTA',
            title="Total Energy Used from %s to %s" % (start_time, end_time),
            ylabel="kWh Consumed, %s at site %s" % (plug, customer),
            xlabel='Hour in Day (5 means 5:00am to 5:59am)')
    save(p)
Example #22
0
def show_histogram(values, title, filename):
    output_file('../results/{0}'.format(filename), title=title)
    distributions = OrderedDict(stars=values)
    df = pandas.DataFrame(distributions)
    distributions = df.to_dict()

    for k, v in distributions.items():
        distributions[k] = v.values()

    hist = Histogram(df, bins=5, legend=True,
                     title=title,
                     ylabel="Frequency",
                     xlabel="Ratings",
                     width=800, height=800)
    show(hist)
Example #23
0
def piechart(percents, **kwargs):
    plot = None
    chart_title = kwargs.get('title', 'Default Chart')

    # create a figure and add a wedge glyph to it
    plot = figure(title=chart_title,
                toolbar_location=None,
                x_range=(-1, 1.1),
                y_range=(-1, 1.1),
                min_border=10,
                min_border_left=50,
                title_text_font_size='12pt',
                width=450,
                height=450)
    plot.outline_line_width = 0
    plot.outline_line_color = "white"
    plot.xaxis.visible = None
    plot.xgrid.grid_line_color = None
    plot.yaxis.visible = None
    plot.ygrid.grid_line_color = None
    total = percents.pop('space')[0]
    colors = ["#726F78", "#5350C5"]
    wedges = []
    wedge_sum = 0

    if not total == 0:
        for i, (key, val) in enumerate(percents.iteritems()):
            wedge = {}
            wedge['start'] = 2*pi*wedge_sum
            wedge_sum = (val) + wedge_sum
            wedge['end'] = 2*pi*wedge_sum
            wedge['name'] = '{:.40} ({:.2f} %)'.format(key, val*100)
            wedge['color'] = colors[i%len(colors)]
            wedges.append(wedge)

    plot._renderers = []
    for i, wedge in enumerate(wedges):
        plot.wedge(x=0, y=0, radius=0.75,
                   legend=wedge['name'],
                   start_angle=wedge['start'],
                   end_angle=wedge['end'],
                   color=wedge['color'],
                   line_color='white',
                   radius_units='data')
    plot.legend.glyph_width = 10
    file_name = chart_title.replace(' ', '') + ".html"
    output_file(file_name)
    save(plot)
Example #24
0
def plot_size_count(dir,title):
    data = read_csv()
    data_size = map(lambda x: x/1024, data.SIZE.tolist())
    data_dir = data.D.tolist()
    length = len(data_size)
    data_to_show = []
    for i in range(0,length):
        if(data_dir[i] == dir):
            data_to_show.append(data_size[i])

    print "Total data:", sum(data_to_show) , "MB"
    
    
    p = charts.Histogram(data_to_show,bins=100,color='#FB9A99',title=title)
    charts.output_file("/tmp/"+title+".html",title=title)
    charts.show(p)
Example #25
0
def make_plot(which_cuisine):
    reviewDf = pd.read_pickle("review2.pkl")
    businessDf = pd.read_pickle("business2.pkl")
    # best indian restaurant
    p4 = Bar(
        businessDf[businessDf.category_id == which_cuisine],
        values="avg_star",
        label="name",
        agg="max",
        color="wheat",
        title="Best " + which_cuisine + " by star rating alone",
        xlabel="Restaurant name",
        ylabel="Star rating",
    )
    output_file("templates/plots.html")
    # p = vplot(p4)
    show(p4)
def bar_opt_elem():
    """
    Create a bar chart showing the number of composite lightcurves
    for each COS & STIS optical element
    """

    logging.info('Creating optical element bar chart')

    # Query for data
    query = session.query(Metadata.instrume, Metadata.opt_elem).all()
    instrumes = [result[0] for result in query]
    opt_elems = [result[1] for result in query]
    opt_elems_set = sorted(list(set(opt_elems)))

    # Initialize dictionaries that store all optical elements
    cos_dict, stis_dict = {}, {}
    for opt_elem in opt_elems_set:
        cos_dict[opt_elem] = 0
        stis_dict[opt_elem] = 0

    # Count number of opt_elems
    for instrument, opt_elem in zip(instrumes, opt_elems):
        if instrument == 'COS':
            cos_dict[opt_elem] += 1
        elif instrument == 'STIS':
            stis_dict[opt_elem] += 1

    # Determine plotting values
    cat = list(opt_elems_set)
    xyvalues = OrderedDict()
    xyvalues['COS'] = [cos_dict[opt_elem] for opt_elem in opt_elems_set]
    xyvalues['STIS'] = [stis_dict[opt_elem] for opt_elem in opt_elems_set]

    # Make plots
    bar = charts.Bar(xyvalues,
                     label=cat,
                     xlabel='Optical Element',
                     ylabel='# of Lightcurves',
                     stacked=True,
                     legend = 'top_right')
    bar.background_fill = '#cccccc'
    bar.outline_line_color = 'black'
    charts.output_file(os.path.join(get_settings()['plot_dir'], 'opt_elem.html'))
    plot_file = os.path.join(get_settings()['plot_dir'], 'opt_elem.html')
    charts.save(obj=bar, filename=plot_file)
    set_permissions(plot_file)
Example #27
0
def plot_shuffle_size_count(csv_file,dir,title):
    data = read_csv(csv_file)
    data_size = map(lambda x: x/1024, data.SIZE.tolist())
    data_dir = data.D.tolist()
    data_path = data.PATHNAME.tolist()
    length = len(data_size)
    data_to_show = []
    for i in range(0,length):
        if(data_dir[i] == dir and 'shuffle' in data_path[i]):
            data_to_show.append(data_size[i])

    print "Total shuffle data:", sum(data_to_show) , "MB"


    p = charts.Histogram(data_to_show,bins=100,color='#1F78B4',title=title)
    charts.output_file("/tmp/"+title+".html",title=title)
    charts.show(p)
Example #28
0
    def analyze(self):
        h5_filename = self.output_filename +'.h5'
        
        with tb.open_file(h5_filename, 'r+') as in_file_h5:
            raw_data = in_file_h5.root.raw_data[:]
            meta_data = in_file_h5.root.meta_data[:]
            
            hit_data = self.dut.interpret_raw_data(raw_data, meta_data)
            in_file_h5.createTable(in_file_h5.root, 'hit_data', hit_data, filters=self.filter_tables)
            
        occ_plot, H = plotting.plot_occupancy(h5_filename)
        tot_plot,_ = plotting.plot_tot_dist(h5_filename)
        lv1id_plot, _ = plotting.plot_lv1id_dist(h5_filename)

        output_file(self.output_filename + '.html', title=self.run_name)
        save(vplot(occ_plot, tot_plot, lv1id_plot))
            
        return H
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)
Example #30
0
    def analyze(self):
        h5_filename = self.output_filename +'.h5'
        with tb.open_file(h5_filename, 'r+') as in_file_h5:
            raw_data = in_file_h5.root.raw_data[:]
            meta_data = in_file_h5.root.meta_data[:]

            hit_data = self.dut.interpret_raw_data(raw_data, meta_data)
            in_file_h5.createTable(in_file_h5.root, 'hit_data', hit_data, filters=self.filter_tables)

        analysis.analyze_threshold_scan(h5_filename)
        status_plot = plotting.plot_status(h5_filename)
        occ_plot, H = plotting.plot_occupancy(h5_filename)
        tot_plot,_ = plotting.plot_tot_dist(h5_filename)
        lv1id_plot, _ = plotting.plot_lv1id_dist(h5_filename)
        scan_pix_hist, _ = plotting.scan_pix_hist(h5_filename)
        t_dac = plotting.t_dac_plot(h5_filename)

        output_file(self.output_filename + '.html', title=self.run_name)
        save(vplot(hplot(occ_plot, tot_plot, lv1id_plot), scan_pix_hist, t_dac, status_plot))
Example #31
0
        n = n + 1

    if p > n:
        pcount = pcount + 1
        df1 = pd.DataFrame([{'sentiment': 'Positive'}])
        df = df.append(df1)
    else:
        ncount = ncount + 1
        df1 = pd.DataFrame([{'sentiment': 'Negative'}])
        df = df.append(df1)

p1 = Donut(data2,
           label=['Did the volunteers manage the event properly ?'],
           title="Did the volunteers manage the event properly ?",
           text_font_size='12pt')
p2 = Donut(data2,
           label=['How was the speaker ?'],
           title="How was the speaker ?",
           text_font_size='12pt')
p3 = Donut(data2,
           label=['Was the event lengthy ?'],
           title="Was the event lengthy ?",
           text_font_size='12pt')
p4 = Donut(df,
           label=['sentiment'],
           title="How was the event overall ?",
           text_font_size='12pt')

output_file("chart.html")

show(column(p1, p2, p3, p4))
Example #32
0
              values='cyl',
              palette=RdYlGn6)

hm7 = HeatMap(autompg,
              x=bins('mpg'),
              y=bins('displ'),
              stat='mean',
              values='cyl',
              palette=RdYlGn9)

hm8 = HeatMap(autompg,
              x=bins('mpg'),
              y=bins('displ'),
              values='cyl',
              stat='mean',
              legend='top_right')

hm9 = HeatMap(fruits, y='year', x='fruit', values='fruit_count', stat=None)

hm10 = HeatMap(unempl,
               x='Year',
               y='Month',
               values='Unemployment',
               stat=None,
               sort_dim={'x': False},
               width=1000)

output_file("heatmap.html", title="heatmap.py example")

show(vplot(hm1, hm2, hm3, hm4, hm5, hm6, hm7, hm8, hm9, hm10))
Example #33
0
""" This example uses the Iris data to demonstrate the specification of
combined variables using chart operations.

This specific instance uses a blend, which stacks columns, and renames
the combined column. This can be used where the column itself is a type
of categorical variable. Here, length and width are derived from the
petal and sepal measurements.
"""

from bokeh.charts import Scatter, output_file, show
from bokeh.charts.operations import blend
from bokeh.sampledata.iris import flowers as data

scatter = Scatter(
    data,
    x=blend('petal_length', 'sepal_length', name='length'),
    y=blend('petal_width', 'sepal_width', name='width'),
    color='species',
    title=
    'x=petal_length+sepal_length, y=petal_width+sepal_width, color=species',
    legend='top_right')

output_file("iris_blend.html", title="iris_blend.py example")

show(scatter)
Example #34
0
def SalesData(request):
    if request.method == 'POST':
        isbn = request.POST.get('isbn')
        if isbn == "":
            return render(request, 'blog/predict.html')
        else:
            username = isbn
            # HTML text is assigned to the html_str variable. Ideally this will be writen to the file ISBN2.html
            html_str = """{% extends 'blog/base.html' %}{% block content %}{% load staticfiles %}<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"><script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script><script type="text/javascript" src="http://jqueryrotate.googlecode.com/svn/trunk/jQueryRotate.js"></script><script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script><div class="container"><div class="panel-group"><div class="panel panel-default"><div class="panel-heading"><h4 class="panel-title"><a data-toggle="collapse" href="#collapse1">Current Edition</a></h4></div><div id="collapse1" class="panel-collapse collapse"><div class="panel-body"><br/><div class="bs-example" data-example-id="table table-bordered" id ="table table-bordered"><table class= "table table-bordered"> <thead> """
            #   ISBN2.HTML file is opened in the below with condition
            with open(
                    'U:\\django_test\\mysitetest\\blog\\templates\\blog\ISBN2.html',
                    'w') as myfile:
                # with the file open,
                myfile.write(html_str)
                myfile.write(
                    "<th class="
                    "col-md-1"
                    ">" + "  " + "</th><th class="
                    "col-md-1"
                    ">Jan</th> <th>Feb</th> <th>Mar</th> <th>Apr</th> <th>May</th> <th>Jun</th> <th>Jul</th> <th>Aug</th> <th>Sep</th> <th>Oct</th> <th>Nov</th> <th>Dec</th></tr> </thead> <tbody> <tr> "
                )
                with open(
                        'C:\\Users\\prasadv\\Desktop\\Stock Opt\\Clustering output file\ISBN_Data_SOMCluster_Period_nrm.csv',
                        'rt') as f:
                    reader = pd.read_csv(f, delimiter=',')
                    df1 = pd.DataFrame(
                        reader,
                        columns=[
                            '', 'ISBN', 'PMG', 'PMC', 'Medium',
                            'Extended Medium', 'Edition Type',
                            'First Sale Time', 'First Sale Month',
                            'Sale Period(in Months)', 'Quarter',
                            'First Year Sales', 'Second Year Sales',
                            'Third Year Sales', 'Fourth Year Sales',
                            'Fifth Year Sales', 'Supply Site : L',
                            'Supply Site : R', 'Range Sales Cluster',
                            'Previous ISBN', 'Previous Edition Cluster',
                            'SOM Cluster', 'Cluster : 2-12', 'Cluster : 1-12',
                            'Cluster : 13-24', 'Cluster : 25-36',
                            'Cluster : 37-48', 'Cluster : 49-60',
                            'Cluster : 1-24', 'Cluster : 1-36',
                            'Cluster : 1-48', 'Cluster : 1-60', 'Period : 1',
                            'Period : 2', 'Period : 3', 'Period : 4',
                            'Period : 5', 'Period : 6', 'Period : 7',
                            'Period : 8', 'Period : 9', 'Period : 10',
                            'Period : 11', 'Period : 12', 'Period : 13',
                            'Period : 14', 'Period : 15', 'Period : 16',
                            'Period : 17', 'Period : 18', 'Period : 19',
                            'Period : 20', 'Period : 21', 'Period : 22',
                            'Period : 23', 'Period : 24', 'Period : 25',
                            'Period : 26', 'Period : 27', 'Period : 28',
                            'Period : 29', 'Period : 30', 'Period : 31',
                            'Period : 32', 'Period : 33', 'Period : 34',
                            'Period : 35', 'Period : 36', 'Period : 37',
                            'Period : 38', 'Period : 39', 'Period : 40',
                            'Period : 41', 'Period : 42', 'Period : 43',
                            'Period : 44', 'Period : 45', 'Period : 46',
                            'Period : 47', 'Period : 48', 'Period : 49',
                            'Period : 50', 'Period : 51', 'Period : 52',
                            'Period : 53', 'Period : 54', 'Period : 55',
                            'Period : 56', 'Period : 57', 'Period : 58',
                            'Period : 59', 'Period : 60', 'Period : 61',
                            'Period : 62', 'Period : 63', 'Period : 64',
                            'Period : 65', 'Period : 66', 'Period : 67',
                            'Period : 68', 'Period : 69', 'Period : 70',
                            'Period : 71', 'Period : 72', 'Period : 73',
                            'Period : 74', 'Period : 75', 'Period : 76',
                            'Period : 77', 'Period : 78', 'Period : 79',
                            'Period : 80', 'Period : 81', 'Period : 82',
                            'Period : 83', 'Period : 84', 'Period : 85',
                            'Period : 86', 'Period : 87', 'Period : 88',
                            'Period : 89', 'Period : 90', 'Period : 91',
                            'Period : 92', 'Period : 93', 'Period : 94',
                            'Period : 95', 'Period : 96', 'Period : 97',
                            'Period : 98', 'Period : 99', 'Period : 100',
                            'Period : 101', 'Period : 102', 'Period : 103',
                            'Period : 104', 'Period : 105', 'Period : 106',
                            'Period : 107', 'Period : 108', 'Period : 109',
                            'Period : 110', 'Period : 111', 'Period : 112',
                            'Period : 113', 'Period : 114', 'Total Sales'
                        ])
                    GG = df1[df1['ISBN'].notnull()
                             & (df1['ISBN'] == float(username))]
                    lista = GG.loc[:, 'Period : 1':
                                   'Period : 114']  #lista is the range starting from p1 to p#
                    lista = lista.values.tolist()
                    lista = [item for sublist in lista for item in sublist]
                    lista = list(map(int, lista))
                    max_num = max(list(map(int, lista)))
                    listb = GG.loc[:,
                                   'First Sale Month']  # taking only the month from the list row
                    listc = GG.loc[:, 'First Sale Time']
                    listc = ''.join(listc.tolist())
                    listc = listc.split('/')
                    listc = listc[0]
                    listb = listb.get_value(listb.index[0])
                    myfile.write("<td>" + listc + "</td>")
                    date1 = datetime.strptime(str(listc) + "-1-1", "%Y-%m-%d")
                    if int(listb) == 1:
                        a = 12
                        b = (len(lista) / 12)
                        if isinstance(b, float) == True:
                            b = math.ceil(b)
                        for j in range(1, b):
                            if a == 12:
                                parts = lista[0:a]
                                pd_new = pd.DataFrame(parts)
                                Part_for_chart = parts
                                parts = [
                                    '<td>' + str(s) + '</td>' for s in parts
                                ]
                                str1 = ''.join(parts)
                                myfile.write(str1 + "</tr>")
                                a = a + 12
                            else:
                                parts = lista[a - 12:a]
                                if (len(parts)) != 12:
                                    lengthofparts = 12 - (len(parts))
                                    g = [
                                        parts.append(0)
                                        for z in range(0, lengthofparts)
                                    ]
                                pd_new = pd_new.append(parts)
                                for x in parts:
                                    Part_for_chart.append(x)
                                parts = [
                                    '<td>' + str(s) + '</td>' for s in parts
                                ]
                                str1 = ''.join(parts)
                                listd = '<td>' + str(int(listc) + 1) + '</td>'
                                myfile.write(listd + str1 + "</tr>")
                                a = a + 12
                                listc = int(listc) + 1
                    else:
                        for i in range(0, listb):
                            lista.insert(0, 0)
                        a = 12
                        b = (len(lista) / 12)
                        if isinstance(b, float) == True:
                            b = math.ceil(b)
                        for j in range(1, b):
                            if a == 12:
                                parts = lista[0:a]
                                pd_new = pd.DataFrame(parts)
                                Part_for_chart = parts
                                parts = [
                                    '<td>' + str(s) + '</td>' for s in parts
                                ]
                                str1 = ''.join(parts)
                                myfile.write(str1 + "</tr>")
                                a = a + 12
                            else:
                                parts = lista[a:a + 12]
                                if (len(parts)) != 12:
                                    lengthofparts = 12 - (len(parts))
                                    g = [
                                        parts.append(0)
                                        for z in range(0, lengthofparts)
                                    ]
                                pd_new = pd_new.append(parts)
                                for x in parts:
                                    Part_for_chart.append(x)
                                parts = [
                                    '<td>' + str(s) + '</td>' for s in parts
                                ]
                                str1 = ''.join(parts)
                                listd = '<td>' + str(int(listc) + 1) + '</td>'
                                myfile.write(listd + str1 + "</tr>")
                                a = a + 12
                                listc = int(listc) + 1
                    date2 = datetime.strptime(
                        str(listc + 1) + "-1-01", "%Y-%m-%d")
                    months_str = calendar.month_name
                    months = []
                    while date1 < date2:
                        month = date1.month
                        year = date1.year
                        month_str = months_str[month][0:3]
                        months.append("{0}-{1}".format(month_str,
                                                       str(year)[-2:]))
                        next_month = month + 1 if month != 12 else 1
                        next_year = year + 1 if next_month == 1 else year
                        date1 = date1.replace(month=next_month, year=next_year)
                    source = ColumnDataSource(data=dict(height=Part_for_chart,
                                                        weight=months,
                                                        names=Part_for_chart))
                    output_file(
                        "U:\\django_test\\mysitetest\\blog\\templates\\svg\\bar.svg"
                    )
                    HoverTool(
                        tooltips=[
                            ('date', '@date{%F}'),
                            ('close', '$@{adj close}{%0.2f}'),
                            # use @{ } for field names with spaces
                            ('volume', '@volume{0.00 a}'),
                        ],
                        # display a tooltip whenever the cursor is vertically in line with a glyph
                        mode='vline')
                    p = figure(plot_width=1500,
                               title=username + '- (Current Edition)',
                               tools="",
                               x_range=source.data["weight"],
                               y_range=ranges.Range1d(start=0,
                                                      end=(max_num + 100)),
                               toolbar_location=None)
                    p.line(months, Part_for_chart, line_width=2)
                    labels = LabelSet(x='weight',
                                      y='height',
                                      text='height',
                                      level='glyph',
                                      x_offset=-13.5,
                                      y_offset=0,
                                      source=source,
                                      text_font_size="10pt",
                                      render_mode='canvas')
                    p.xaxis.major_label_orientation = math.pi / 2
                    p.add_layout(labels)
                    save(p)
                myfile.write(
                    """<table class="inlineTable"><div id="chart" >{% include "svg/bar.svg" %}</div></table><div class="panel-footer">@Copyright Elsevier 2017. Created by [email protected]</div></div></div></div></div></div></div>"""
                )
                myfile.write("</tr>{% endblock content %}")
                myfile.close()
            return render(
                request,
                'blog/ISBN2.html',
            )
            # Define 20 color pallet using RGB values
            tableau20 = cycle([(31, 119, 180), (174, 199, 232), (255, 127, 14),
                               (255, 187, 120), (44, 160, 44), (152, 223, 138),
                               (214, 39, 40), (255, 152, 150), (148, 103, 189),
                               (197, 176, 213), (140, 86, 75), (196, 156, 148),
                               (227, 119, 194), (247, 182, 210),
                               (127, 127, 127), (199, 199, 199),
                               (188, 189, 34), (219, 219, 141), (23, 190, 207),
                               (158, 218, 229)])
            color = tableau20

            # Print 'Plotting Chart XX'
            print('Plotting ' + group.replace('_', ' '))

            # Create figure with set x-axis, set size, and available tools in bokeh package
            output_file(output_location + group + '.html', mode='cdn')
            p = figure(x_axis_label='Time(min)',
                       height=500,
                       width=1200,
                       tools=TOOLS,
                       title=group.replace('_', ' '),
                       x_range=Range1d(0, End_Time))

            # Begin cycling through channels
            for channel in channel_groups.get_group(group).index.values:

                # Skip plot quantity if channel name is blank
                if pd.isnull(channel):
                    continue

# Skip excluded channels listed in test description file
Example #36
0
                    title="label='cyl', values='mpg', marker='cross'")

# color whisker by cylinder
box_plot7 = BoxPlot(df,
                    label='cyl',
                    values='mpg',
                    whisker_color='cyl',
                    title="label='cyl', values='mpg', whisker_color='cyl'")

# remove outliers
box_plot8 = BoxPlot(
    df,
    label='cyl',
    values='mpg',
    outliers=False,
    title="label='cyl', values='mpg', outliers=False, tooltips=True",
    tooltips=True)

output_file("boxplot_multi.html", title="boxplot_multi.py example")

show(
    gridplot(box_plot,
             box_plot2,
             box_plot3,
             box_plot4,
             box_plot5,
             box_plot6,
             box_plot7,
             box_plot8,
             ncols=2))
Example #37
0
from bokeh.charts import Scatter, output_file, show
from bokeh.sampledata.autompg import autompg as df

p = Scatter(df,
            x='mpg',
            y='hp',
            title="HP vs MPG",
            xlabel="Miles Per Gallon",
            ylabel="Horsepower")

output_file("scatter.html")

show(p)
Example #38
0
from bokeh.charts import Donut, show, output_file
from bokeh.charts.utils import df_from_json
from bokeh.sampledata.olympics2014 import data

import pandas as pd

# utilize utility to make it easy to get json/dict data converted to a dataframe
df = df_from_json(data)

# filter by countries with at least one medal and sort by total medals
df = df[df['total'] > 8]
df = df.sort("total", ascending=False)
df = pd.melt(df, id_vars=['abbr'],
             value_vars=['bronze', 'silver', 'gold'],
             value_name='medal_count', var_name='medal')

# original example
d = Donut(df, label=['abbr', 'medal'], values='medal_count',
          text_font_size='8pt', hover_text='medal_count')

output_file("donut.html")
show(d)
Example #39
0
from bokeh.charts import Donut, output_file, show

output_file('donut.html')

# prepare the data
data = [[2., 5., 3.], [4., 1., 4.], [6., 4., 3.]]

donut = Donut(data, ['cpu1', 'cpu2', 'cpu3'])

show(donut)
Example #40
0
from collections import OrderedDict

from bokeh.charts import Area, show, output_file

# create some example data
xyvalues = OrderedDict(
    python=[2, 3, 7, 5, 26, 221, 44, 233, 254, 265, 266, 267, 120, 111],
    pypy=[12, 33, 47, 15, 126, 121, 144, 233, 254, 225, 226, 267, 110, 130],
    jython=[22, 43, 10, 25, 26, 101, 114, 203, 194, 215, 201, 227, 139, 160],
)

output_file(filename="area.html")

area = Area(xyvalues,
            title="Area Chart",
            xlabel='time',
            ylabel='memory',
            stacked=True,
            legend="top_left").legend("top_left")

show(area)
Example #41
0
# ch29.py

# ref:
# http://bokeh.pydata.org/en/latest/docs/user_guide/charts.html#color-groups

# However, the color parameter can also be used to group the data. If
# the value of the color parameter is one of the DataFrame column
# names, the data is first grouped by this column, and a histogram is
# generated for each group. Each histogram is automatically colored
# differently, and a legend displayed:

from bokeh.charts import Histogram, output_file, show
from bokeh.sampledata.autompg import autompg as df

p = Histogram(df, values='hp', color='cyl',
              title="HP Distribution (color grouped by CYL)",
              legend='top_right')

output_file("/tmp/ch29.html")

show(p)


Example #42
0
# ch11.py

# ref:
# http://bokeh.pydata.org/en/latest/docs/user_guide/charts.html#aggregations

# The agg parameter may be used to specify how each group should be aggregated:

from bokeh.charts import Bar, output_file, show
from bokeh.sampledata.autompg import autompg as df

p = Bar(df, label='yr', values='mpg', agg='mean', title="Average MPG by YR")

output_file("/tmp/ch11.html")

show(p)
Example #43
0
from bokeh.charts import Histogram, output_file, show
from bokeh.layouts import row
from bokeh.sampledata.autompg import autompg as df

hist = Histogram(df, values='mpg', title="Auto MPG Histogram", plot_width=400)
hist2 = Histogram(df, values='mpg', label='cyl', color='cyl', legend='top_right',
                  title="MPG Histogram by Cylinder Count", plot_width=400)

output_file('hist.html')
show(row(hist, hist2))
Example #44
0
from bokeh.charts import Bar, output_file, show
from bokeh.charts.operations import blend
from bokeh.charts.attributes import cat, color
from bokeh.charts.utils import df_from_json
from bokeh.sampledata.olympics2014 import data

# utilize utility to make it easy to get json/dict data converted to a dataframe
df = df_from_json(data)

# filter by countries with at least one medal and sort by total medals
df = df[df['total'] > 0]
df = df.sort("total", ascending=False)

bar = Bar(df,
          values=blend('bronze',
                       'silver',
                       'gold',
                       name='medals',
                       labels_name='medal'),
          label=cat(columns='abbr', sort=False),
          stack=cat(columns='medal', sort=False),
          color=color(columns='medal',
                      palette=['SaddleBrown', 'Silver', 'Goldenrod'],
                      sort=False),
          legend='top_right',
          title="Medals per Country, Sorted by Total Medals",
          tooltips=[('medal', '@medal'), ('country', '@abbr')])

output_file("stacked_bar.html")
show(bar)
from bokeh.charts import HeatMap, output_file, show

# (dict, OrderedDict, lists, arrays and DataFrames are valid inputs)
data = {'fruit': ['apples']*3 + ['bananas']*3 + ['pears']*3,
        'fruit_count': [4, 5, 8, 1, 2, 4, 6, 5, 4],
        'sample': [1, 2, 3]*3}

hm = HeatMap(data, x='fruit', y='sample', values='fruit_count',
             title='Fruits', stat=None)

output_file('heatmap.html')
show(hm)
Example #46
0
from bokeh.charts import Histogram, output_file, show
from bokeh.sampledata.autompg import autompg as df

p = Histogram(df, values='hp', color='navy', title="HP Distribution")

output_file("histogram_color.html")

show(p)
            var.split('*')[0].strip() for var in item[1].split('+')[:5]
        ]
        corpus_one = corpus
        for i, var in enumerate(index_one):
            corpus_one[var] = float(value_one[i])
        value_mt.append([int(1000 * var) for var in corpus_one.values()])

df = pd.DataFrame(value_mt)
topic_words = pd.DataFrame(corpus.keys())
df2 = df.transpose().set_index(topic_words[topic_words.columns[0]])
df3 = df2.transpose()
topic_label = pd.DataFrame(['topic_' + str(i) for i in range(topic_number)])
df3 = df3.set_index(topic_label[topic_label.columns[0]])

html_path = folder_name + str(topic_number) + '_topic_Weight_Management.html'
output_file(html_path,
            title=str(topic_number) + '_topic_Weight_Management.html')

palette = palette[::
                  -1]  # Reverse the color order so dark red is highest unemployment
hm = HeatMap(df3,
             title=str(topic_number) + '_topic_Weight_Management.html',
             tools="reset,resize",
             width=1300,
             height=700,
             palette=palette)

show(hm)

#==============================================================================
# generate all urls under each topic
#==============================================================================
Example #48
0
from bokeh.charts import Scatter, output_file, show
from bokeh.sampledata.iris import flowers as data

scatter = Scatter(data,
                  x='petal_length',
                  y='petal_width',
                  color='species',
                  marker='species',
                  title='Iris Dataset Color and Marker by Species',
                  legend=True)

output_file("iris_simple.html", title="iris_simple.py example")

show(scatter)
Example #49
0
from bokeh.charts import HeatMap, output_file, show
from bokeh.sampledata.unemployment1948 import data

# pandas magic
df = data[data.columns[:-2]]
df2 = df.set_index(df[df.columns[0]].astype(str))
df2.drop(df.columns[0], axis=1, inplace=True)
df3 = df2.transpose()

output_file("cat_heatmap.html")

hm = HeatMap(df3, title="categorical heatmap", width=800)

show(hm)
Example #50
0
              values='cyl',
              stat='mean',
              legend='top_right')

hm9 = HeatMap(fruits, y='year', x='fruit', values='fruit_count', stat=None)

hm10 = HeatMap(unempl,
               x='Year',
               y='Month',
               values='Unemployment',
               stat=None,
               sort_dim={'x': False},
               width=900,
               plot_height=500)

output_file("hm10.html", title="Bokeh heatmap example (hm10.py)")

show(
    column(
        gridplot(hm1,
                 hm2,
                 hm3,
                 hm4,
                 hm5,
                 hm6,
                 hm7,
                 hm8,
                 hm9,
                 ncols=2,
                 plot_width=400,
                 plot_height=400), hm10))
Example #51
0
# I could just use Counter from Collections but too bad
def collectUniqueWords(filename):
    file_to_check = open(filename, 'r')
    dict1 = {}
    lines = file_to_check.readlines()
    file_to_check.close()
    for line in lines:
        line = line.split()
        for word in line:
            if word.lower() in dict1:
                dict1[word.lower()] += 1
            else:
                dict1[word.lower()] = 1

    return dict1


dictVals = collectUniqueWords("example.txt")

frequencies = pd.DataFrame(list(dictVals.items()))

frequencies.columns = ["word", "frequency"]

print(frequencies)

p = Bar(frequencies[:30], 'word', values='frequency', title="Word Frequency")

output_file("bar.html")

show(p)
Example #52
0
from collections import OrderedDict

import numpy as np

from bokeh.charts import Horizon, output_file, show

x = np.linspace(0, np.pi * 4, 137)
y = (2 * np.random.normal(size=137) + x**2)
xx = np.hstack([-1 * x[::-1], x])
yy = np.hstack([-1 * y[::-1], y])

xyvalues = OrderedDict(x=xx, y=yy, y2=yy, y3=yy, y4=yy, y5=yy)

output_file("horizon_folds.html")

hp = Horizon(xyvalues, index='x', title="test horizon", ylabel='Random')

show(hp)
from bokeh.charts import BoxPlot, output_file, show
from bokeh.sampledata.autompg import autompg as df

p = BoxPlot(df, values='mpg', label='cyl', color='cyl',
            title="MPG Summary (grouped and shaded by CYL)")

output_file("boxplot.html")

show(p)
Example #54
0
from bokeh.charts import Line, show, output_file

# build a dataset where multiple columns measure the same thing
data = dict(python=[2, 3, 7, 5, 26, 221, 44, 233, 254, 265, 266, 267, 120, 111],
            pypy=[12, 33, 47, 15, 126, 121, 144, 233, 254, 225, 226, 267, 110, 130],
            jython=[22, 43, 10, 25, 26, 101, 114, 203, 194, 215, 201, 227, 139, 160],
            test=['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'bar',
                  'foo', 'bar', 'foo', 'bar']
            )

# create a line chart where each column of measures receives a unique color and dash style
line = Line(data, y=['python', 'pypy', 'jython'],
            dash=['python', 'pypy', 'jython'],
            color=['python', 'pypy', 'jython'],
            title="Interpreter Sample Data", ylabel='Duration', legend=True)

output_file("line_single.html")

show(line)
Example #55
0
from bokeh.charts import Histogram, output_file, show
from bokeh.sampledata.autompg import autompg as df

p = Histogram(df, values='mpg', bins=50, title="MPG Distribution (50 bins)")

output_file("histogram_bins.html")

show(p)
Example #56
0
df2 = df_from_json(data)
df2 = df2.sort('total', ascending=False)

df2 = df2.head(10)
df2 = pd.melt(df2, id_vars=['abbr', 'name'])

scatter5 = Scatter(df2,
                   x='value',
                   y='name',
                   color='variable',
                   title="x='value', y='name', color='variable'",
                   xlabel="Medals",
                   ylabel="Top 10 Countries",
                   legend='bottom_right')

scatter6 = Scatter(
    flowers,
    x=blend('petal_length', 'sepal_length', name='length'),
    y=blend('petal_width', 'sepal_width', name='width'),
    color='species',
    title=
    'x=petal_length+sepal_length, y=petal_width+sepal_width, color=species',
    legend='top_right')
scatter6.title_text_font_size = '10pt'

output_file("scatter_multi.html", title="scatter_multi.py example")

show(
    vplot(hplot(scatter0, scatter1), hplot(scatter2, scatter3),
          hplot(scatter4, scatter5), hplot(scatter6)))
Example #57
0
# utilize utility to make it easy to get json/dict data converted to a dataframe
df = df_from_json(data)

# filter by countries with at least one medal and sort by total medals
df = df[df['total'] > 8]
df = df.sort("total", ascending=False)
df = pd.melt(df, id_vars=['abbr'],
             value_vars=['bronze', 'silver', 'gold'],
             value_name='medal_count', var_name='medal')

# original example
d = Donut(df, label=['abbr', 'medal'], values='medal_count',
          text_font_size='8pt', hover_text='medal_count')

output_file("donut.html", title="donut.py example")

show(d)


<nav class="w3-sidebar w3-bar-block w3-animate-left w3-grey" style="display:none", id="my_sidebar">
<button class="w3-bar-item w3-button w3-xlarge" onclick="w3_close()">Close &times;</button>
<a href="#" class="w3-bar-item w3-button w3-padding-large w3-grey">
 <i class="fa fa-home w3-xxlarge">

 </i>
 <p>Home</p>
</a>
<a href="/Runners.html" class="w3-bar-item w3-button w3-padding-large w3-grey w3-hover-dark-grey">
 <i class="fa fa-users w3-xxlarge">
Example #58
0
from bokeh.charts import Bar, output_file, show
from bokeh.charts.attributes import cat, color
from bokeh.charts.operations import blend
from bokeh.charts.utils import df_from_json
from bokeh.sampledata.olympics2014 import data

# utilize utility to make it easy to get json/dict data converted to a dataframe
df = df_from_json(data)

# filter by countries with at least one medal and sort by total medals
df = df[df['total'] > 0]
df = df.sort_values(by="total", ascending=False)

bar = Bar(df,
          values=blend('bronze', 'silver', 'gold', name='medals', labels_name='medal'),
          label=cat(columns='abbr', sort=False),
          stack=cat(columns='medal', sort=False),
          color=color(columns='medal', palette=['SaddleBrown', 'Silver', 'Goldenrod'],
                      sort=False),
          legend='top_right',
          title="Medals per Country, Sorted by Total Medals",
          tooltips=[('medal', '@medal'), ('country', '@abbr')])


output_file("stacked_bar.html", title="stacked_bar.py example")

show(bar)
Example #59
0
    title="Interpreters (x='date', y, dash=['python', 'pypy', 'jython'])",
    ylabel='Duration',
    legend=True)

line3 = Line(
    df,
    x='date',
    y=['python', 'pypy', 'jython'],
    dash=['python', 'pypy', 'jython'],
    color=['python', 'pypy', 'jython'],
    title=
    "Interpreters (x='date', y, dash, color=['python', 'pypy', 'jython'])",
    ylabel='Duration',
    legend=True)

line4 = Line(
    df,
    x='date',
    y=['python', 'pypy', 'jython'],
    dash='test',
    color=['python', 'pypy', 'jython'],
    title=
    "Interpreters (x='date', y, color=['python', 'pypy', 'jython'], dash='test') with tooltips",
    ylabel='Duration',
    legend=True,
    tooltips=[('series', '@series'), ('test', '@test')])

output_file("line_multi.html", title="line examples")

show(gridplot(line, line0, line1, line2, line3, line4, ncols=2))
Example #60
0
Freq = trips.groupby(["Start station",
                      "End station"]).size().reset_index(name="Frequency")

# Set the stations as nodes and the number of trips as links
nodes_df = pd.DataFrame(Station)
links_df = pd.DataFrame(Freq)

# Left join node and link dataframes
source_data = links_df.merge(nodes_df,
                             how='left',
                             left_on='Start station',
                             right_index=True)
source_data = source_data.merge(nodes_df,
                                how='left',
                                left_on='End station',
                                right_index=True)

# Find high-traffic stations
source_data = source_data[source_data["Frequency"] > 3500]

# Define chord chart
StationChord = Chord(source_data,
                     source="Start station",
                     target="End station",
                     value="Frequency")

# Write output file
output_file('StationChord.html', mode="inline")

# Show chord chart
show(StationChord)