def doPlot2(data, nrDataSource):
    plots = []
    for thisColumn in data.columns[1:]:
        plots.append(Bar(data, data.columns[0], values=thisColumn, title="Bar graph: " + nrDataSource['name'],
                         xlabel=data.columns[0], ylabel=thisColumn, responsive=True))
    c = components(vplot(*plots), resources=None, wrap_script=False, wrap_plot_info=True)
    return c
Esempio n. 2
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
Esempio n. 3
0
 def shows(self):
     bars = []
     for i in range(0, len(self.__vkey)):
         bar = Bar(self.__data[i], values=self.__vkey[i], label=self.__lkey[i], agg='sum', title=self.__title[i], legend=self.__legend, width=1000)
         bars.append(bar)
     
     show(vplot(*bars))
Esempio n. 4
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<400000: 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
Esempio n. 5
0
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)
Esempio n. 6
0
    def validate_trajectories(self):
        '''
		Project clade trajectories based on fitted fitness model and compare to observed trajectories
		'''
        self.trajectory_data = []
        series = 0
        for time in self.timepoints[:-1]:
            all_pred = self.predictor_arrays[time]
            all_freqs = self.freq_arrays[time]
            for clade in self.fit_clades[time]:
                initial_freq = clade.timepoint_freqs[time]
                pred = all_pred[clade.tips]
                freqs = all_freqs[clade.tips]
                interpolation = interp1d(self.rootnode.pivots,
                                         clade.freq['global'],
                                         kind='linear',
                                         bounds_error=False)
                for delta in np.arange(-0.5, 1.1, 0.1):
                    if time + delta >= self.rootnode.pivots[
                            0] and time + delta <= self.rootnode.pivots[-1]:
                        obs_freq = np.asscalar(interpolation(time + delta))
                        pred_freq = obs_freq
                        if delta >= 0:
                            total_pred_freq = np.sum(
                                self.projection(self.model_params, all_pred,
                                                all_freqs, delta))
                            pred_freq = np.sum(
                                self.projection(self.model_params, pred, freqs,
                                                delta)) / total_pred_freq
                        self.trajectory_data.append([
                            series,
                            str(clade), time, time + delta, obs_freq, pred_freq
                        ])
                series += 1

        import pandas as pd
        self.trajectory_data_df = pd.DataFrame(
            self.trajectory_data,
            columns=['series', 'clade', 'initial_time', 'time', 'obs', 'pred'])
        self.trajectory_data_df.to_csv("data/prediction_trajectories.tsv",
                                       sep="\t",
                                       index=False)
        import bokeh.charts as bk
        bk.defaults.height = 250
        bk.output_file("lines.html", title="line plot example")
        lines = []
        for time in self.timepoints[:-1]:
            line = bk.Line(self.trajectory_data_df[
                self.trajectory_data_df.initial_time == time],
                           x='time',
                           y=['obs', 'pred'],
                           dash=['obs', 'pred'],
                           color='clade',
                           xlabel='Date',
                           ylabel='Frequency',
                           tools=False)
            lines.append(line)
        bk.show(bk.vplot(*lines))
Esempio n. 7
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')
Esempio n. 8
0
def graphstocks(ssymbol, sdate, edate,color):
    stock = ssymbol
    if color not in colors:
        color="Black"
    api_url='https://www.quandl.com/api/v3/datasets/WIKI/%(symbol)s.json?api_key=%(key)s&start_date=%(sdate)s&end_date=%(edate)s' % {"symbol":stock, "key":YOURAPIKEY,"sdate":sdate, "edate":edate}
    session = requests.Session()
    session.mount('http://', requests.adapters.HTTPAdapter(max_retries=3))
    raw_data=session.get(api_url)
    aapl_stock=raw_data.json()
    color="Black"
    cnames = aapl_stock['dataset']['column_names']
    df = pandas.DataFrame(aapl_stock['dataset']['data'],columns=cnames) # create dataframe and assign column names
    df['Date']=pandas.to_datetime(df['Date']) # convert Date column to DateTime in place
    tsline = TimeSeries(df,x='Date', y='Close', ylabel=ssymbol+' Stock Prices', legend=True, color=colors[color])
    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=sdate,
        to=edate,
        symbol_lulu=ssymbol
    )
    return encode_utf8(html)
Esempio n. 9
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))
Esempio n. 10
0
def doPlot2(data, nrDataSource):
    plots = []
    for thisColumn in data.columns[1:]:
        plots.append(
            Bar(data,
                data.columns[0],
                values=thisColumn,
                title="Bar graph: " + nrDataSource['name'],
                xlabel=data.columns[0],
                ylabel=thisColumn,
                responsive=True))
    c = components(vplot(*plots),
                   resources=None,
                   wrap_script=False,
                   wrap_plot_info=True)
    return c
Esempio n. 11
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
Esempio n. 12
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)
        
     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)                   
              
     output_file(self.output_filename + '.html', title=self.run_name)
     save(vplot(hplot(occ_plot, tot_plot, lv1id_plot), scan_pix_hist, status_plot))
Esempio n. 13
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))
Esempio n. 14
0
def graphPacketsInfo(web_browsers, oses, devices, activity_map, first_date):
    browser_data={"x":web_browsers.keys(), "y": web_browsers.values()}
    os_data={"x":oses.keys(), "y":oses.values()}
    devices_data={"x":devices.keys(), "y":devices.values()}

    output_file("browsers.html", title="Browser distribution")
    browser_chart=Bar(browser_data, width=600, height=600, label="x",values="y",
                      xlabel="Browser", ylabel="Count", title="Browser distribution")

    os_chart = Bar(os_data, width=600,height=600, label="x", values="y",
                   xlabel="OS", ylabel="Count", title="OS distribution")

    devices_chart = Bar(devices_data, width=600, height=600, label="x", values="y",
                        xlabel="Device", ylabel="Count", title="Device distribution")

    activity_chart = figure(plot_width=1600, plot_height=400, title="Network activity over time")
    activity_chart.xaxis.axis_label = "Time in seconds"
    activity_chart.yaxis.axis_label = "Number of packets"
    activity_x = [(time-first_date).total_seconds() for time in activity_map.keys()]
    activity_y = activity_map.values()
    activity_chart.line(activity_x,activity_y)

    show(vplot(browser_chart, os_chart, devices_chart, activity_chart))
Esempio n. 15
0
                   title="iris dataset, dict_input",
                   xlabel="petal_length",
                   ylabel="petal_width",
                   legend='top_left')

pdict = OrderedDict()
for i in groupped_df.groups.keys():
    labels = groupped_df.get_group(i).columns
    xname = labels[0]
    yname = labels[1]
    x = getattr(groupped_df.get_group(i), xname)
    y = getattr(groupped_df.get_group(i), yname)
    pdict[i] = list(zip(x, y))

df = pd.DataFrame(pdict)
scatter3 = Scatter(df,
                   title="iris dataset, dict_input",
                   xlabel="petal_length",
                   ylabel="petal_width",
                   legend='top_left')

scatter4 = Scatter(list(xyvalues.values()),
                   title="iris dataset, dict_input",
                   xlabel="petal_length",
                   ylabel="petal_width",
                   legend='top_left')

output_file("scatter.html")

show(vplot(scatter1, scatter2, scatter3, scatter4))
Esempio n. 16
0
File: area.py Progetto: chakas/bokeh
from bokeh.charts import Area, show, vplot, output_file, defaults

defaults.width = 400
defaults.height = 400

# create some example data
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],
)

area1 = Area(data, title="Area Chart", legend="top_left",
             xlabel='time', ylabel='memory')

area2 = Area(data, title="Stacked Area Chart", legend="top_left",
             stack=True, xlabel='time', ylabel='memory')

output_file(filename="area.html")

show(vplot(area1, area2))
Esempio n. 17
0
# given a categorical series of data with no aggregation
d5 = Donut(autompg.groupby(['cyl', 'origin']).displ.mean(), hover_text='mean')

# no values specified
d6 = Donut(autompg, label='cyl', agg='count')

# explicit examples
d7 = Donut(autompg, label='cyl', values='displ', agg='mean')

# nested donut chart for the provided labels, with colors assigned
# by the first level
d8 = Donut(autompg, label=['cyl', 'origin'], values='displ', agg='mean')

# show altering the spacing in levels
d9 = Donut(autompg,
           label=['cyl', 'origin'],
           values='displ',
           agg='mean',
           level_spacing=0.15)

# show altering the spacing in levels
d10 = Donut(autompg,
            label=['cyl', 'origin'],
            values='displ',
            agg='mean',
            level_spacing=[0.8, 0.3])

output_file("donut_multi.html")
show(vplot(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10))
Esempio n. 18
0
                          cat=categories,
                          title="All negative input | Grouped",
                          ylabel="Random Number",
                          width=width,
                          height=height)

np_custom = Bar(mixed,
                cat=categories,
                title="Custom range (start=-3, end=0.4)",
                ylabel="Random Number",
                width=width,
                height=height,
                continuous_range=Range1d(start=-3, end=0.4))

np_mixed_grouped = Bar(mixed,
                       cat=categories,
                       title="Mixed-sign input | Grouped",
                       ylabel="Random Number",
                       width=width,
                       height=height)

# collect and display
output_file("bar.html")

show(
    vplot(
        hplot(dict_stacked, df_grouped),
        hplot(np_stacked, np_negative_grouped),
        hplot(np_mixed_grouped, np_custom),
    ))
Esempio n. 19
0
for idx, row in tqdm(workframe.iterrows()):
    temp_stamp = int(row['Event.Date'][:4])
    if row['Total.Fatal.Injuries'] == '0' or temp_stamp < this_year - 20:
        continue
    if temp_stamp in twenty_year_fatalities.keys():
        twenty_year_fatalities[temp_stamp] += row['Total.Fatal.Injuries']
    else:
        twenty_year_fatalities.update(
            {temp_stamp: row['Total.Fatal.Injuries']})
twenty_year_stats = []

for k, v in twenty_year_fatalities.items():
    twenty_year_stats.append((k, v))
twenty_year_stats.sort(reverse=False)

result_df = pd.DataFrame(twenty_year_stats, columns=['Year', 'Fatalities'])

result_dict = {}
for row in result_df.itertuples():
    result_dict.update({row[1]: row[2]})

mx, my = zip(*sorted(result_dict.items()))
result_data = pd.Series(my, mx)
chart = Line(result_data,
             title="Fatal Injury Distribution",
             legend="top_right",
             ylabel='Number of Fatalities',
             xlabel='Year')

p = vplot(chart)
show(p)
Esempio n. 20
0
from bokeh.charts import Area, show, vplot, output_file, defaults

defaults.width = 400
defaults.height = 400

# create some example data
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],
)

area1 = Area(data,
             title="Area Chart",
             legend="top_left",
             xlabel='time',
             ylabel='memory')

area2 = Area(data,
             title="Stacked Area Chart",
             legend="top_left",
             stack=True,
             xlabel='time',
             ylabel='memory')

output_file(filename="area.html")

show(vplot(area1, area2))
Esempio n. 21
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))
from bokeh.charts import Bar, show, output_file, vplot

output_file("example.html")

category_list= [{'Pass Rate': [74.78632478632478, 69.12751677852349], 'Categories': ['M', 'F']}, {'Pass Rate': [72.54901960784314, 61.29032258064516, 77.14285714285714, 73.07692307692308, 68.75, 58.333333333333336, 60.0, 70.45454545454545, 90.9090909090909, 80.0, 88.88888888888889, 60.714285714285715, 77.77777777777777], 'Categories': ['East Anglian Region', 'Scotland', 'North Western Region', 'South East Region', 'West Midlands Region', 'Wales', 'North Region', 'South Region', 'Ireland', 'South West Region', 'East Midlands Region', 'Yorkshire Region', 'London Region']}, {'Pass Rate': [73.46938775510205, 71.1340206185567, 73.49397590361446, 87.5], 'Categories': ['HE Qualification', 'A Level or Equivalent', 'Lower Than A Level', 'Post Graduate Qualification']}, {'Pass Rate': [84.61538461538461, 73.03370786516854, 70.39106145251397], 'Categories': ['55<=', '35-55', '0-35']}]
categories = ['gender','region','highest_education','age_band']

p1 = Bar(category_list[0], values = 'Pass Rate', label = 'Categories', title = categories[0], width=1000)
p2 = Bar(category_list[1], values = 'Pass Rate', label = 'Categories', title = categories[1], width=1000)
p3 = Bar(category_list[2], values = 'Pass Rate', label = 'Categories', title = categories[2], width=1000)
p4 = Bar(category_list[3], values = 'Pass Rate', label = 'Categories', title = categories[3], width=1000)

p = vplot(p1,p2,p3,p4)

show(p)
Esempio n. 23
0
import pandas as pd
from bokeh.charts import Donut, Bar, show, vplot, Line, output_file

df = pd.read_csv("aviationdataset.csv", encoding='latin1').fillna(0)
print("file loaded")

fatality_dict = {}
for phase in df['Broad.Phase.of.Flight'].unique():
    if phase != 0:
        fatality_dict.update({
            phase:
            sum(df[df['Broad.Phase.of.Flight'] == phase]
                ['Total.Fatal.Injuries']) /
            len(df[df['Broad.Phase.of.Flight'] == phase]) * 100
        })
x, y = zip(*sorted(fatality_dict.items()))
data = pd.Series(y, x)
pie_chart = Donut(
    data,
    plot_width=800,
    plot_height=800,
    title=
    "How do the flight phases (ex. take off, cruise, landing..) contribute to fatalities?"
)

p = vplot(pie_chart)
show(p)
Esempio n. 24
0
np_stacked = Bar(
    random, cat=categories, title="Numpy Array input | Stacked",
    ylabel="Random Number", xlabel="", width=width, height=height,
    stacked=True
)

np_negative_grouped = Bar(
    random * -1, cat=categories, title="All negative input | Grouped",
    ylabel="Random Number", width=width, height=height
)

np_custom = Bar(
    mixed, cat=categories, title="Custom range (start=-3, end=0.4)",
    ylabel="Random Number", width=width, height=height,
    continuous_range=Range1d(start=-3, end=0.4)
)

np_mixed_grouped = Bar(
    mixed, cat=categories, title="Mixed-sign input | Grouped",
    ylabel="Random Number", width=width, height=height
)

# collect and display
output_file("bar.html")

show(vplot(
    hplot(dict_stacked, df_grouped),
    hplot(np_stacked, np_negative_grouped),
    hplot(np_mixed_grouped, np_custom),
))
Esempio n. 25
0
                     ylabel='Size (bytes)')


def diff_size_hist(repo, branch='master'):
    diffs = [commit_diff_size(c)
             for c in repo.iter_commits('master')]
    return Histogram(diffs, bins=100,
                     title='Diff sizes',
                     ylabel='Size (bytes)')


def message_length_v_diff_size(repo, branch='master'):
    diff_data = [(len(c.message), commit_diff_size(c))
                 for c in repo.iter_commits('master')]

    return Scatter([diff_data],
                   title='Message length vs. Diff size',
                   xlabel='Commit message length',
                   ylabel='Diff size')


output_file("git_stuff.html")

repo = Repo('/users/sixtynorth/projects/cosmic-ray')

plots = [message_length_hist(repo),
         diff_size_hist(repo),
         message_length_v_diff_size(repo)]

show(vplot(*plots))
Esempio n. 26
0
bar_plot6 = Bar(df, label='origin', values='mpg', agg='mean', stack='cyl',
                title="label='origin' values='mpg' agg='mean' stack='cyl'",
                legend='top_right')
bar_plot6.title_text_font_size = '10pt'

bar_plot7 = Bar(df, label='cyl', values='displ', agg='mean', group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')
bar_plot7.title_text_font_size = '10pt'

bar_plot8 = Bar(df, label='cyl', values='neg_mpg', agg='mean', group='origin',
                color='origin', legend='top_right',
                title="label='cyl' values='neg_mpg' agg='mean' group='origin'")
bar_plot8.title_text_font_size = '9pt'

# infer labels from index
df = df.set_index('cyl')
bar_plot9 = Bar(df, values='mpg', agg='mean', legend='top_right', title='inferred labels')
bar_plot9.title_text_font_size = '10pt'

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

show(vplot(
    hplot(bar_plot,  bar_plot2),
    hplot(bar_plot3, bar_plot4),
    hplot(bar_plot5, bar_plot6),
    hplot(bar_plot7, bar_plot8),
    hplot(bar_plot9)
))
Esempio n. 27
0
from bokeh.charts import Bar, output_file, show, vplot
from numpy.random import rand
from pandas import DataFrame

N = 10
data = DataFrame({'A': rand(N), 'B': rand(N), 'C': rand(N)})
# Stack columns A,B,C and convert the multiindices to columns
sdata = data.stack().reset_index()
sdata.columns = ['labels', 'stack', 'values']

bar = Bar(sdata, values='values', label='labels', stack='stack', legend='top_right')
bar2 = Bar(sdata, values='values', label='labels', stack='stack', legend='top_right')
bar2.x_range = bar.x_range  # Link the x axes

output_file("stacked_bar.html")
show(vplot(bar, bar2))
Esempio n. 28
0
                group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')
bar_plot7.title_text_font_size = '10pt'

bar_plot8 = Bar(df,
                label='cyl',
                values='neg_mpg',
                agg='mean',
                group='origin',
                color='origin',
                legend='top_right',
                title="label='cyl' values='neg_mpg' agg='mean' group='origin'")
bar_plot8.title_text_font_size = '9pt'

# infer labels from index
df = df.set_index('cyl')
bar_plot9 = Bar(df,
                values='mpg',
                agg='mean',
                legend='top_right',
                title='inferred labels')
bar_plot9.title_text_font_size = '10pt'

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

show(
    vplot(hplot(bar_plot, bar_plot2), hplot(bar_plot3, bar_plot4),
          hplot(bar_plot5, bar_plot6), hplot(bar_plot7, bar_plot8),
          hplot(bar_plot9)))
Esempio n. 29
0
from bokeh.charts import Histogram, defaults, vplot, hplot, show, output_file
from bokeh.sampledata.autompg import autompg as df

defaults.plot_width = 400
defaults.plot_height = 350

# input options
hist = Histogram(df['mpg'], title="df['mpg']")
hist2 = Histogram(df, 'displ', title="df, 'displ'")
hist3 = Histogram(df, values='hp', title="df, values='hp'")

hist4 = Histogram(df,
                  values='hp',
                  color='cyl',
                  title="df, values='hp', color='cyl'",
                  legend='top_right')

hist5 = Histogram(df, values='mpg', bins=50, title="df, values='mpg', bins=50")

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

show(vplot(hplot(hist, hist2), hplot(hist3, hist4), hplot(hist5)))
Esempio n. 30
0
def scan_pix_hist(h5_file_name, scurve_sel_pix=200):
    with tb.open_file(h5_file_name, 'r') as in_file_h5:
        meta_data = in_file_h5.root.meta_data[:]
        hit_data = in_file_h5.root.hit_data[:]
        en_mask = in_file_h5.root.scan_results.en_mask[:]
        Noise_gauss = in_file_h5.root.Noise_results.Noise_pure.attrs.fitdata_noise
        Noise_pure = in_file_h5.root.Noise_results.Noise_pure[:]
        Thresh_gauss = in_file_h5.root.Thresh_results.Threshold_pure.attrs.fitdata_thresh
        Threshold_pure = in_file_h5.root.Thresh_results.Threshold_pure[:]
        scan_args = yaml.load(in_file_h5.root.meta_data.attrs.kwargs)
        scan_range = scan_args['scan_range']
        scan_range_inx = np.arange(scan_range[0], scan_range[1], scan_range[2])

        # np.set_printoptions(threshold=np.nan)
        param = np.unique(meta_data['scan_param_id'])
        ret = []
        for i in param:
            wh = np.where(hit_data['scan_param_id'] == i)  # this can be faster and multi threaded
            hd = hit_data[wh[0]]
            hits = hd['col'].astype(np.uint16)
            hits = hits * 64
            hits = hits + hd['row']
            value = np.bincount(hits)
            value = np.pad(value, (0, 64 * 64 - value.shape[0]), 'constant')
            if len(ret):
                ret = np.vstack((ret, value))
            else:
                ret = value
        repeat_command = max(ret[-3])
        shape = en_mask.shape
        ges = 1
        for i in range(2):
            ges = ges * shape[i]
        ret_pure = ()
        en_mask = en_mask.reshape(ges)
        for n in range(param[-1]):
            ret_pure1 = ()
            for i in range(ges):
                if (str(en_mask[i]) == 'True'):
                    ret_pure1 = np.append(ret_pure1, ret[n][i])
            if n == 0:
                ret_pure = ret_pure1
                continue
            ret_pure = np.vstack((ret_pure, ret_pure1))

        ret_pure = ret_pure.astype(int)
        s_hist = np.swapaxes(ret_pure, 0, 1)

        pix_scan_hist = np.empty((s_hist.shape[1], repeat_command + 10))
        for param in range(s_hist.shape[1]):
            h_count = np.bincount(s_hist[:, param])
            h_count = h_count[:repeat_command + 10]
            pix_scan_hist[param] = np.pad(h_count, (0, (repeat_command + 10) - h_count.shape[0]), 'constant')

        log_hist = np.log10(pix_scan_hist)
        log_hist[~np.isfinite(log_hist)] = 0
        data = {
            'scan_param': np.ravel(np.indices(pix_scan_hist.shape)[0]),
            'count': np.ravel(np.indices(pix_scan_hist.shape)[1]),
            'value': np.ravel(log_hist)
        }

        x = scan_range_inx
        px = scurve_sel_pix  # 1110 #1539
        single_scan = figure(title="Single pixel scan " + str(px), x_axis_label="Injection[V]", y_axis_label="Hits")
        single_scan.diamond(x=x, y=s_hist[px], size=5, color="#1C9099", line_width=2)
        yf = analysis.scurve(x, 100, Threshold_pure[px], Noise_pure[px])
        single_scan.cross(x=x, y=yf, size=5, color="#E6550D", line_width=2)

        hist, edges = np.histogram(Threshold_pure, density=False, bins=50)

        hm1 = HeatMap(data, x='scan_param', y='count', values='value', title='Threshold Heatmap',
                      palette=Spectral11[::-1], stat=None, plot_width=1000)  # , height=4100)
        hm1.extra_x_ranges = {
            "e": Range1d(start=edges[0] * 1000 * analysis.cap_fac(), end=edges[-1] * 1000 * analysis.cap_fac())}

        hm_th = figure(title="Threshold", x_axis_label="pixel #", y_axis_label="threshold [V]",
                       y_range=(scan_range_inx[0], scan_range_inx[-1]), plot_width=1000)
        hm_th.diamond(y=Threshold_pure, x=range(64 * 64), size=1, color="#1C9099", line_width=2)
        hm_th.extra_y_ranges = {"e": Range1d(start=scan_range_inx[0] * 1000 * analysis.cap_fac(),
                                             end=scan_range_inx[-1] * 1000 * analysis.cap_fac())}
        hm_th.add_layout(LinearAxis(y_range_name="e"), 'right')
        plt_th_dist = figure(title='Threshold Distribution ', x_axis_label="threshold [V]", y_axis_label="#Pixel",
                             y_range=(0, 1.1 * np.max(hist[1:])))
        plt_th_dist.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564",
                         line_color="#033649",
                         legend="# {0:d}  mean={1:.2f}  std={2:.2f}".format(int(np.sum(hist[:])), round(
                             Thresh_gauss['mu'] * 1000 * analysis.cap_fac(), 4),
                                                                            round(Thresh_gauss[
                                                                                      'sigma'] * 1000 * analysis.cap_fac(),
                                                                                  4)))
        plt_th_dist.extra_x_ranges = {"e": Range1d(start=edges[0] * 1000 * analysis.cap_fac(),
                                                   end=edges[-1] * 1000 * analysis.cap_fac())}  # better 7.4?
        plt_th_dist.add_layout(LinearAxis(x_range_name="e"), 'above')
        plt_th_dist.line(np.arange(edges[1], edges[-1], 0.0001),
                         analysis.gauss(np.arange(edges[1], edges[-1], 0.0001), Thresh_gauss['height'],
                                        Thresh_gauss['mu'], Thresh_gauss['sigma']), line_color="#D95B43", line_width=8,
                         alpha=0.7)

        hist, edges = np.histogram(Noise_pure, density=False, bins=50)
        hm_noise = figure(title="Noise", x_axis_label="pixel #", y_axis_label="noise [V]", y_range=(0, edges[-1]),
                          plot_width=1000)
        hm_noise.diamond(y=Noise_pure, x=range(64 * 64), size=2, color="#1C9099", line_width=2)
        hm_noise.extra_y_ranges = {"e": Range1d(start=0, end=edges[-1] * 1000 * analysis.cap_fac())}  # default 7.6
        hm_noise.add_layout(LinearAxis(y_range_name="e"), 'right')

        plt_noise_dist = figure(title='Noise Distribution ', x_axis_label="noise [V]", y_axis_label="#Pixel",
                                y_range=(0, 1.1 * np.max(hist[1:])))
        plt_noise_dist.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564",
                            line_color="#033649",
                            legend="# {0:d}  mean={1:.2f}  std={2:.2f}".format(int(np.sum(hist[:])), round(
                                Noise_gauss['mu'] * 1000 * analysis.cap_fac(), 4), round(
                                Noise_gauss['sigma'] * 1000 * analysis.cap_fac(), 4)))
        plt_noise_dist.extra_x_ranges = {
            "e": Range1d(start=edges[0] * 1000 * analysis.cap_fac(), end=edges[-1] * 1000 * analysis.cap_fac())}
        plt_noise_dist.add_layout(LinearAxis(x_range_name="e"), 'above')
        plt_noise_dist.line(np.arange(edges[0], edges[-1], 0.0001),
                            analysis.gauss(np.arange(edges[0], edges[-1], 0.0001), Noise_gauss['height'],
                                           Noise_gauss['mu'], Noise_gauss['sigma']), line_color="#D95B43", line_width=8,
                            alpha=0.7)

        return vplot(hplot(hm_th, plt_th_dist), hplot(hm_noise, plt_noise_dist), hplot(hm1, single_scan)), s_hist
Esempio n. 31
0
                values='displ',
                agg='mean',
                group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')

dot_plot8 = Dot(df,
                label='cyl',
                values='neg_mpg',
                agg='mean',
                group='origin',
                color='origin',
                legend='top_right',
                title="label='cyl' values='neg_mpg' agg='mean' group='origin'")
dot_plot8.title_text_font_size = '11pt'

# infer labels from index
df = df.set_index('cyl')
dot_plot9 = Dot(df,
                values='mpg',
                agg='mean',
                legend='top_right',
                title='inferred labels')

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

show(
    vplot(hplot(dot_plot, dot_plot2), hplot(dot_plot3, dot_plot4),
          hplot(dot_plot5, dot_plot6), hplot(dot_plot7, dot_plot8),
          hplot(dot_plot9)))
Esempio n. 32
0
                    title="label='cyl' color='blue'",
                    color='blue')

# color by one dimension and label by two dimensions
box_plot5 = BoxPlot(df, label=['cyl', 'origin'], values='mpg',
                    title="label=['cyl', 'origin'] color='cyl'",
                    color='cyl')

# specify custom marker for outliers
box_plot6 = BoxPlot(df, label='cyl', values='mpg', marker='cross',
                    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")

# collect and display
output_file("boxplot_multi.html")

show(
    vplot(
        hplot(box_plot, box_plot2, box_plot3),
        hplot(box_plot4, box_plot5, box_plot6),
        hplot(box_plot7, box_plot8)
    )
)
Esempio n. 33
0
from bokeh.charts import Histogram, defaults, vplot, hplot, show, output_file
from bokeh.sampledata.autompg import autompg as df

defaults.plot_width = 400
defaults.plot_height = 350

# input options
hist  = Histogram(df['mpg'], title="df['mpg']")
hist2 = Histogram(df, 'displ', title="df, 'displ'")
hist3 = Histogram(df, values='hp', title="df, values='hp'")

hist4 = Histogram(df, values='hp', color='cyl',
                  title="df, values='hp', color='cyl'", legend='top_right')

hist5 = Histogram(df, values='mpg', bins=50,
                  title="df, values='mpg', bins=50")

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

show(vplot(
    hplot(hist, hist2),
    hplot(hist3, hist4),
    hplot(hist5)
))
Esempio n. 34
0
scatter1 = Scatter(xyvalues, title="iris dataset, dict_input", xlabel="petal_length",
                  ylabel="petal_width", legend='top_left', marker="triangle")


groupped_df = flowers[["petal_length", "petal_width", "species"]].groupby("species")
scatter2 = Scatter(groupped_df, title="iris dataset, dict_input", xlabel="petal_length",
                  ylabel="petal_width", legend='top_left')

pdict = OrderedDict()
for i in groupped_df.groups.keys():
    labels = groupped_df.get_group(i).columns
    xname = labels[0]
    yname = labels[1]
    x = getattr(groupped_df.get_group(i), xname)
    y = getattr(groupped_df.get_group(i), yname)
    pdict[i] = list(zip(x, y))

df = pd.DataFrame(pdict)
scatter3 = Scatter(
    df, title="iris dataset, dict_input",
    xlabel="petal_length", ylabel="petal_width", legend='top_left')

scatter4 = Scatter(
    list(xyvalues.values()), title="iris dataset, dict_input",
    xlabel="petal_length", ylabel="petal_width", legend='top_left')

output_file("scatter.html")

show(vplot(scatter1, scatter2, scatter3, scatter4))
Esempio n. 35
0
                     dash=['IBM', 'MSFT', 'AAPL'],
                     title="Timeseries (Line Explicit)",
                     tools=TOOLS,
                     ylabel='Stock Prices')

# step
tsstep = TimeSeries(data,
                    x='Date',
                    y=['IBM', 'MSFT', 'AAPL'],
                    legend=True,
                    builder_type='step',
                    title="Timeseries (Step)",
                    tools=TOOLS,
                    ylabel='Stock Prices')

# point
tspoint = TimeSeries(data,
                     x='Date',
                     y=['IBM', 'MSFT', 'AAPL'],
                     legend=True,
                     builder_type='point',
                     marker=['IBM', 'MSFT', 'AAPL'],
                     color=['IBM', 'MSFT', 'AAPL'],
                     title="Timeseries (Point)",
                     tools=TOOLS,
                     ylabel='Stock Prices')

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

show(vplot(tsline, tsline2, tsstep, tspoint))
Esempio n. 36
0
 def tdc_table(self, scanrange):
     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[:]
         if (meta_data.shape[0] == 0): return
         repeat_command = in_file_h5.root.meta_data.attrs.kwargs
         a = repeat_command.rfind("repeat_command: ")
         repeat_command = repeat_command[a + len("repeat_command: "):a +
                                         len("repeat_command: ") + 7]
         a = repeat_command.rfind("\n")
         repeat_command = int(repeat_command[0:a])
         param, index = np.unique(meta_data['scan_param_id'],
                                  return_index=True)
         pxl_list = []
         for p in param:
             pix_no = int(p) / int(len(self.inj_charge))
             pxl_list.append(self.pixel_list[pix_no][0] * 64 +
                             self.pixel_list[pix_no][1])
         index = index[1:]
         index = np.append(index, meta_data.shape[0])
         index = index - 1
         stops = meta_data['index_stop'][index]
         split = np.split(raw_data, stops)
         avg_tdc = []
         avg_tdc_err = []
         avg_del = []
         avg_del_err = []
         hits = []
         deletelist = ()
         for i in range(len(split[:-1])):  # loop on pulses
             rwa_data_param = split[i]
             tdc_data = rwa_data_param & 0xFFF  # take last 12 bit
             tdc_delay = (rwa_data_param & 0x0FF00000) >> 20
             counter = 0.0
             TOT_sum = 0.0
             DEL_sum = 0.0
             if (tdc_data.shape[0] == 0 or tdc_data.shape[0] == 1):
                 counter = 1.0
             for j in range(tdc_data.shape[0]):  # loop on repeats
                 if (j > 0):
                     counter += 1
                     TOT_sum += tdc_data[j]
                     DEL_sum += tdc_delay[j]
             if (counter > 1):
                 hits.append(counter)
                 avg_tdc.append((float(TOT_sum) / float(counter)) * 1.5625)
                 avg_tdc_err.append(1.5625 / (np.sqrt(12.0 * counter)))
                 avg_del.append((float(DEL_sum) / float(counter)) * 1.5625)
                 avg_del_err.append(1.5625 / (np.sqrt(12.0 * counter)))
             else:
                 deletelist = np.append(deletelist, i)
         pxl_list = np.delete(pxl_list, deletelist)
         newpix = [0]
         pix_no_old = pxl_list[0]
         runparam = 0
         for p in pxl_list:
             if p != pix_no_old:
                 newpix = np.append(newpix, runparam)
             pix_no_old = p
             runparam = runparam + 1
             addedvalues = 0
         for pixels in range(len(newpix)):
             missingvalues = 0
             if newpix[pixels] == newpix[-1]:
                 missingvalues = scanrange - abs(newpix[pixels] +
                                                 addedvalues - len(hits))
             else:
                 if abs(newpix[pixels] - newpix[pixels + 1]) < scanrange:
                     missingvalues = scanrange - abs(newpix[pixels] -
                                                     newpix[pixels + 1])
             if missingvalues != 0:
                 hits = np.insert(hits, newpix[pixels] + addedvalues,
                                  np.zeros(missingvalues))
                 avg_tdc = np.insert(avg_tdc, newpix[pixels] + addedvalues,
                                     np.zeros(missingvalues))
                 avg_tdc_err = np.insert(avg_tdc_err,
                                         newpix[pixels] + addedvalues,
                                         np.zeros(missingvalues))
                 avg_del = np.insert(avg_del, newpix[pixels] + addedvalues,
                                     np.zeros(missingvalues))
                 avg_del_err = np.insert(avg_del_err,
                                         newpix[pixels] + addedvalues,
                                         np.zeros(missingvalues))
                 pxl_list = np.insert(
                     pxl_list, newpix[pixels] + addedvalues,
                     (pxl_list[newpix[pixels] + addedvalues]) *
                     np.ones(missingvalues))
             addedvalues = addedvalues + missingvalues
         injections = []
         for pixels in range(int(len(pxl_list) / len(self.inj_charge))):
             for i in range(len(self.inj_charge)):
                 injections = np.append(injections, self.inj_charge[i])
         pix, stop = np.unique(pxl_list, return_index=True)
         stop = np.sort(stop)
         stop = list(stop)
         stop.append(len(avg_tdc))
         repeat_command_dic = {}
         repeat_command_dic['repeat_command'] = repeat_command
         avg_tab = np.rec.fromarrays([
             injections, pxl_list, hits, avg_tdc, avg_tdc_err, avg_del,
             avg_del_err
         ],
                                     dtype=[('charge', float),
                                            ('pixel_no', int),
                                            ('hits', int),
                                            ('tot_ns', float),
                                            ('err_tot_ns', float),
                                            ('delay_ns', float),
                                            ('err_delay_ns', float)])
         tdc_table = in_file_h5.createTable(in_file_h5.root,
                                            'tdc_data',
                                            avg_tab,
                                            filters=self.filter_tables)
         tdc_table.attrs.repeat_command = repeat_command_dic
         thresholds = ()
         expfit0 = ()
         expfit1 = ()
         expfit2 = ()
         expfit3 = ()
         pixels = ()
         for i in range(len(stop) - 1):
             s1 = int(stop[i])
             s2 = int(stop[i + 1])
             A, mu, sigma = analysis.fit_scurve(hits[s1:s2],
                                                injections[s1:s2],
                                                repeat_command)
             if np.max(
                     hits[s1:s2]) > (repeat_command + 200):  # or mu > 3000:
                 thresholds = np.append(thresholds, 0)
                 expfit0 = np.append(expfit0, 0)
                 expfit1 = np.append(expfit1, 0)
                 expfit2 = np.append(expfit2, 0)
                 expfit3 = np.append(expfit3, 0)
                 pixels = np.append(pixels, pxl_list[s1])
                 continue
             for values in range(s1, s2):
                 if injections[values] >= 5 / 4 * mu:
                     s1 = values
                     break
             numberer = 0
             hitvaluesold = hits[-1]
             for hitvalues in hits[s1:s2]:
                 if abs(hitvalues - hitvaluesold) <= 1 and hitvalues != 0:
                     break
                 numberer = numberer + 1
                 hitvaluesold = hitvalues
             if numberer == len(avg_del[s1:s2]):
                 numberer = 0
             expfit = analysis.fit_exp(injections[s1:s2], avg_del[s1:s2],
                                       mu, abs(numberer))
             startexp = -expfit[0] * np.log(
                 (25.0 + np.min(avg_del[s1:s2]) - expfit[3]) /
                 expfit[2]) - expfit[1]
             if np.isnan(startexp) or startexp >= 2000:
                 startexp = 0
             thresholds = np.append(thresholds, startexp)
             expfit0 = np.append(expfit0, expfit[0])
             expfit1 = np.append(expfit1, expfit[1])
             expfit2 = np.append(expfit2, expfit[2])
             expfit3 = np.append(expfit3, expfit[3])
             pixels = np.append(pixels, pxl_list[s1])
         thresh = np.rec.fromarrays(
             [pixels, thresholds, expfit0, expfit1, expfit2, expfit3],
             dtype=[('pixel_no', int), ('td_threshold', float),
                    ('expfit0', float), ('expfit1', float),
                    ('expfit2', float), ('expfit3', float)])
         in_file_h5.createTable(in_file_h5.root,
                                'td_threshold',
                                thresh,
                                filters=self.filter_tables)
     p1, p2, single_scan = plotting.plot_timewalk(h5_filename)
     output_file(self.output_filename + '.html', title=self.run_name)
     status = plotting.plot_status(h5_filename)
     save(hplot(vplot(p1, p2, status), single_scan))
Esempio n. 37
0
def single_timewalk_plot(h5_filename):
    output_file('/home/mark/Desktop/Stuff/single.html')
    p1, p2, single_scan = plot_timewalk2(h5_filename)
    save(hplot(vplot(p1, p2), single_scan))
Esempio n. 38
0
from bokeh.charts import Histogram
from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import defaults, vplot, hplot, show, output_file

defaults.width = 450
defaults.height = 350

# input options
hist = Histogram(df['mpg'], title="df['mpg']")
hist2 = Histogram(df, 'displ', title="df, 'displ'")
hist3 = Histogram(df, values='hp', title="df, values='hp'")

hist4 = Histogram(df,
                  values='hp',
                  color='cyl',
                  title="df, values='hp', color='cyl'",
                  legend='top_right')

hist5 = Histogram(df, values='mpg', bins=50, title="df, values='mpg', bins=50")

output_file("histograms.html")

show(vplot(hplot(hist, hist2, hist3), hplot(hist4, hist5)))
Esempio n. 39
0
              palette=palette,
              title="categorical heatmap, pd_input",
              height=400,
              width=1000)

hm_data = df3.values.T
hm2 = HeatMap(hm_data,
              palette=palette,
              title="Unemployment (Array)",
              xlabel='Years since 1948',
              ylabel='Months',
              height=400,
              width=1000)

simple_df = pd.DataFrame(
    {
        'apples': [4, 5, 8, 12, 4],
        'pears': [6, 5, 4, 8, 7],
        'bananas': [1, 2, 4, 8, 12]
    },
    index=['2009', '2010', '2011', '2012', '2013'])
hm3 = HeatMap(simple_df,
              palette=palette,
              title="Fruit comsumption per year",
              height=400,
              width=1000)

output_file("heatmap.html")

show(vplot(hm1, hm2, hm3))
Esempio n. 40
0
                values='displ',
                agg='mean',
                group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')

bar_plot8 = Bar(df,
                label='cyl',
                values='neg_mpg',
                agg='mean',
                group='origin',
                color='origin',
                legend='top_right',
                title="label='cyl' values='neg_mpg' agg='mean' group='origin'")

# infer labels from index
df = df.set_index('cyl')
bar_plot9 = Bar(df,
                values='mpg',
                agg='mean',
                legend='top_right',
                title='inferred labels')

# collect and display
output_file("bar_multi.html")

show(
    vplot(hplot(bar_plot, bar_plot2, bar_plot3),
          hplot(bar_plot4, bar_plot5, bar_plot6),
          hplot(bar_plot7, bar_plot8, bar_plot9)))
Esempio n. 41
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')",
    ylabel='Duration',
    legend=True)

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

show(vplot(hplot(line), hplot(line0, line1), hplot(line2, line3),
           hplot(line4)))
Esempio n. 42
0
    Date=ym,
    Deaths=fatal_mon['NUM'].tolist(),
)

tsline = TimeSeries(data,
    x='Date', y='Deaths',
    title="Traffic Deaths in NYC", ylabel='Monthly Crash Deaths', legend=True, plot_width=1000)


p = bokeh.plotting.figure(x_axis_type = "datetime",
  tools="pan,wheel_zoom,box_zoom,reset,resize,previewsave",plot_width=1000,
  name="myplot")

output_file("/Users/grad/Desktop/timeseries.html")

show(vplot(tsline))

# get the lat lons without nan values
lata = lat[lat.notnull()].tolist()
lona = lon[lon.notnull()].tolist()

locs = []
for i in range(0,len(lata)):
    locs.append([lata[i], lona[i]])

lat_fatal = latf[latf.notnull()].tolist()
lon_fatal = lonf[lonf.notnull()].tolist()

locsf = []
for i in range(0,len(lat_fatal)):
    locsf.append([lat_fatal[i], lon_fatal[i]])
Esempio n. 43
0
             title="Interpreters (y=['python', 'pypy', 'jython'])", ylabel='Duration', legend=True)

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

line2 = Line(df, x='date', y=['python', 'pypy', 'jython'],
             dash=['python', 'pypy', 'jython'],
             title="Interpreters (x='date', y, dash=['python', 'pypy', 'jython'])", ylabel='Duration', legend=True)
line2.title_text_font_size = '11pt'

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)
line3.title_text_font_size = '11pt'

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(vplot(
    hplot(line),
    hplot(line0, line1),
    hplot(line2, line3),
    hplot(line4)
))
Esempio n. 44
0
    IBM=IBM['Adj Close'],
)

TOOLS="resize,pan,wheel_zoom,box_zoom,reset,previewsave"

output_file("timeseries.html")

# line simple
tsline = TimeSeries(
    xyvalues, x='Date', y=['IBM', 'AAPL'], legend=True,
    title="Timeseries (Line)", tools=TOOLS, ylabel='Stock Prices')

# line explicit
tsline2 = TimeSeries(
    xyvalues, x='Date', y=['IBM', 'AAPL'], color=['IBM', 'AAPL'],
    dash=['IBM', 'AAPL'], legend=True,
    title="Timeseries (Line Explicit)", tools=TOOLS, ylabel='Stock Prices')

# step
tsstep = TimeSeries(
    xyvalues, x='Date', y=['IBM', 'AAPL'], legend=True, builder_type='step',
    title="Timeseries (Step)", tools=TOOLS, ylabel='Stock Prices')

# point
tspoint = TimeSeries(
    xyvalues, x='Date', y=['IBM', 'AAPL'], marker=['IBM', 'AAPL'], legend=True,
    color=['IBM', 'AAPL'], builder_type='point',
    title="Timeseries (Point)", tools=TOOLS, ylabel='Stock Prices')

show(vplot(tsline, tsline2, tsstep, tspoint))
Esempio n. 45
0
int_vhover.line_policy = 'interp'

iphover = int_point_line.select(HoverTool)
iphover.mode = 'mouse'
iphover.line_policy = 'interp'

tphover = point_line.select(HoverTool)
tphover.mode = 'mouse'

shover = scatter.select(HoverTool)
shover.mode = 'vline'

shoverp = scatter_point.select(HoverTool)
shoverp.mode = 'mouse'

# set up tooltips
int_vhover.tooltips = int_hhover.tooltips = TOOLTIPS
tphover.tooltips = iphover.tooltips = TOOLTIPS
shover.tooltips = shoverp.tooltips = TOOLTIPS
vhover.tooltips = hhover.tooltips = TOOLTIPS

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

show(
    vplot(
        hplot(hline, vline),
        hplot(int_hline, int_vline),
        hplot(int_point_line, point_line),
        hplot(scatter_point, scatter),
    ))
Esempio n. 46
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)))
Esempio n. 47
0
from bokeh.charts import BoxPlot, output_file, show
from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import defaults, vplot, hplot

defaults.width = 450
defaults.height = 350

box_plot = BoxPlot(df, label='cyl', values='mpg', title="label='cyl', values='mpg'")

box_plot2 = BoxPlot(df, label=['cyl', 'origin'], values='mpg', title="label=['cyl', 'origin'], values='mpg'")

box_plot3 = BoxPlot(df, label='cyl', values='mpg', agg='mean',
                title="label='cyl' values='mpg' agg='mean'")

box_plot4 = BoxPlot(df, label='cyl', title="label='cyl' color='DimGray'", color='dimgray')

# collect and display
output_file("boxplot.html")

show(
    vplot(
        hplot(box_plot, box_plot2),
        hplot(box_plot3, box_plot4),
    )
)
Esempio n. 48
0
    def render_html(self, kind):
        """
        Render HTML-based timeseries plots for dygraphs, Bokeh and Vega.
        """

        # Variable aliases
        bucket = self.bucket
        df = self.dataframe

        if kind == 'dygraphs':
            # http://dygraphs.com/

            # Compute data_uri, forward "from" and "to" parameters
            data_uri = get_data_uri(bucket, 'data.csv', {'pad': 'true'})

            # Render HTML snippet containing dygraphs widget
            page = DygraphsPage(data_uri=data_uri, bucket=bucket)
            bucket.request.setHeader('Content-Type',
                                     'text/html; charset=utf-8')
            return renderElement(bucket.request, page)

        elif kind == 'bokeh':
            # http://bokeh.pydata.org/

            from bokeh.io import save
            from bokeh.charts import TimeSeries, vplot

            # Propagate non-null values forward or backward, otherwise
            # Bokeh would not plot the sparse data frame properly.
            # With time series data, using pad/ffill is extremely common so that the “last known value” is available at every time point.
            # http://pandas.pydata.org/pandas-docs/stable/missing_data.html#filling-missing-values-fillna
            df.fillna(method='pad', inplace=True)

            # Plot using matplotlib
            # http://bokeh.pydata.org/en/latest/docs/user_guide/compat.html#userguide-compat
            # https://github.com/bokeh/bokeh/tree/master/examples/compat/
            # https://github.com/bokeh/bokeh/blob/master/examples/compat/pandas_dataframe.py
            # https://github.com/bokeh/bokeh/blob/master/examples/compat/ggplot_line.py
            #df.plot()
            #what = mpl.to_bokeh()

            # Plot using Bokeh TimeSeries
            # http://bokeh.pydata.org/en/latest/docs/reference/charts.html#timeseries
            # http://bokeh.pydata.org/en/0.11.1/docs/user_guide/styling.html#location
            linegraph = TimeSeries(df,
                                   x='time',
                                   title=bucket.title.human,
                                   legend="top_left",
                                   width=800)

            # Plot TimeSeries object
            what = vplot(linegraph)

            # Render using Bokeh
            t = tempfile.NamedTemporaryFile(suffix='.html', delete=False)
            save(what, filename=t.name, title=bucket.title.human)

            # Forward html to http response
            bucket.request.setHeader('Content-Type',
                                     'text/html; charset=utf-8')
            return t.read()

        elif kind == 'vega':
            # https://github.com/wrobstory/vincent

            # Compute data_uri, forward "from" and "to" parameters
            data_uri = get_data_uri(bucket, 'data.vega.json', {
                'pad': 'true',
                'backfill': 'true'
            })

            template = Template(
                str(resource_string('kotori.io.export', 'vega_template.html')))
            bucket.request.setHeader('Content-Type',
                                     'text/html; charset=utf-8')
            response = template.substitute(path=data_uri,
                                           title=bucket.title.human)
            return response.encode('utf-8')
Esempio n. 49
0
# specify custom marker for outliers
box_plot6 = BoxPlot(df,
                    label='cyl',
                    values='mpg',
                    marker='cross',
                    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)
box_plot8.title_text_font_size = '11pt'

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

show(
    vplot(hplot(box_plot, box_plot2), hplot(box_plot3, box_plot4),
          hplot(box_plot5, box_plot6), hplot(box_plot7, box_plot8)))
Esempio n. 50
0
 def tdc_table(self, scanrange):
     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[:]
         if (meta_data.shape[0] == 0): return
         repeat_command = in_file_h5.root.meta_data.attrs.kwargs
         a = repeat_command.rfind("repeat_command: ")
         repeat_command = repeat_command[a + len("repeat_command: "):a + len("repeat_command: ") + 7]
         a = repeat_command.rfind("\n")
         repeat_command = int(repeat_command[0:a])
         param, index = np.unique(meta_data['scan_param_id'], return_index=True)
         pxl_list = []
         for p in param:
             pix_no = int(p) / int(len(self.inj_charge))
             pxl_list.append(self.pixel_list[pix_no][0] * 64 + self.pixel_list[pix_no][1])
         index = index[1:]
         index = np.append(index, meta_data.shape[0])
         index = index - 1
         stops = meta_data['index_stop'][index]
         split = np.split(raw_data, stops)
         avg_tdc = []
         avg_tdc_err = []
         avg_del = []
         avg_del_err = []
         hits = []
         deletelist = ()
         for i in range(len(split[:-1])):  # loop on pulses
             rwa_data_param = split[i]
             tdc_data = rwa_data_param & 0xFFF  # take last 12 bit
             tdc_delay = (rwa_data_param & 0x0FF00000) >> 20
             counter = 0.0
             TOT_sum = 0.0
             DEL_sum = 0.0
             if (tdc_data.shape[0] == 0 or tdc_data.shape[0] == 1):
                 counter = 1.0
             for j in range(tdc_data.shape[0]):  # loop on repeats
                 if (j > 0):
                     counter += 1
                     TOT_sum += tdc_data[j]
                     DEL_sum += tdc_delay[j]
             if (counter > 1):
                 hits.append(counter)
                 avg_tdc.append((float(TOT_sum) / float(counter)) * 1.5625)
                 avg_tdc_err.append(1.5625 / (np.sqrt(12.0 * counter)))
                 avg_del.append((float(DEL_sum) / float(counter)) * 1.5625)
                 avg_del_err.append(1.5625 / (np.sqrt(12.0 * counter)))
             else:
                 deletelist = np.append(deletelist, i)
         pxl_list = np.delete(pxl_list, deletelist)
         newpix = [0]
         pix_no_old = pxl_list[0]
         runparam = 0
         for p in pxl_list:
             if p != pix_no_old:
                 newpix = np.append(newpix, runparam)
             pix_no_old = p
             runparam = runparam + 1
             addedvalues = 0
         for pixels in range(len(newpix)):
             missingvalues = 0
             if newpix[pixels] == newpix[-1]:
                 missingvalues = scanrange - abs(newpix[pixels] + addedvalues - len(hits))
             else:
                 if abs(newpix[pixels] - newpix[pixels + 1]) < scanrange:
                     missingvalues = scanrange - abs(newpix[pixels] - newpix[pixels + 1])
             if missingvalues != 0:
                 hits = np.insert(hits, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 avg_tdc = np.insert(avg_tdc, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 avg_tdc_err = np.insert(avg_tdc_err, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 avg_del = np.insert(avg_del, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 avg_del_err = np.insert(avg_del_err, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 pxl_list = np.insert(pxl_list, newpix[pixels] + addedvalues,
                                      (pxl_list[newpix[pixels] + addedvalues]) * np.ones(missingvalues))
             addedvalues = addedvalues + missingvalues
         injections = []
         for pixels in range(int(len(pxl_list) / len(self.inj_charge))):
             for i in range(len(self.inj_charge)):
                 injections = np.append(injections, self.inj_charge[i])
         pix, stop = np.unique(pxl_list, return_index=True)
         stop = np.sort(stop)
         stop = list(stop)
         stop.append(len(avg_tdc))
         repeat_command_dic={}
         repeat_command_dic['repeat_command']=repeat_command
         avg_tab = np.rec.fromarrays([injections, pxl_list, hits, avg_tdc, avg_tdc_err, avg_del, avg_del_err],
                                     dtype=[('charge', float), ('pixel_no', int), ('hits', int),
                                            ('tot_ns', float), ('err_tot_ns', float), ('delay_ns', float),
                                            ('err_delay_ns', float)])
         tdc_table=in_file_h5.createTable(in_file_h5.root, 'tdc_data', avg_tab, filters=self.filter_tables)
         tdc_table.attrs.repeat_command = repeat_command_dic
         thresholds = ()
         expfit0 = ()
         expfit1 = ()
         expfit2 = ()
         expfit3 = ()
         pixels = ()
         for i in range(len(stop) - 1):
             s1 = int(stop[i])
             s2 = int(stop[i + 1])
             A, mu, sigma = analysis.fit_scurve(hits[s1:s2], injections[s1:s2],repeat_command)
             if np.max(hits[s1:s2]) > (repeat_command + 200):  # or mu > 3000:
                 thresholds = np.append(thresholds, 0)
                 expfit0 = np.append(expfit0, 0)
                 expfit1 = np.append(expfit1, 0)
                 expfit2 = np.append(expfit2, 0)
                 expfit3 = np.append(expfit3, 0)
                 pixels = np.append(pixels, pxl_list[s1])
                 continue
             for values in range(s1, s2):
                 if injections[values] >= 5 / 4 * mu:
                     s1 = values
                     break
             numberer = 0
             hitvaluesold = hits[-1]
             for hitvalues in hits[s1:s2]:
                 if abs(hitvalues - hitvaluesold) <= 1 and hitvalues != 0:
                     break
                 numberer = numberer + 1
                 hitvaluesold = hitvalues
             if numberer == len(avg_del[s1:s2]):
                 numberer = 0
             expfit = analysis.fit_exp(injections[s1:s2], avg_del[s1:s2], mu, abs(numberer))
             startexp = -expfit[0] * np.log((25.0 + np.min(avg_del[s1:s2]) - expfit[3]) / expfit[2]) - expfit[1]
             if np.isnan(startexp) or startexp >= 2000:
                 startexp = 0
             thresholds = np.append(thresholds, startexp)
             expfit0 = np.append(expfit0, expfit[0])
             expfit1 = np.append(expfit1, expfit[1])
             expfit2 = np.append(expfit2, expfit[2])
             expfit3 = np.append(expfit3, expfit[3])
             pixels = np.append(pixels, pxl_list[s1])
         thresh = np.rec.fromarrays([pixels, thresholds, expfit0, expfit1, expfit2, expfit3],
                                    dtype=[('pixel_no', int), ('td_threshold', float),
                                           ('expfit0', float), ('expfit1', float), ('expfit2', float),
                                           ('expfit3', float)])
         in_file_h5.createTable(in_file_h5.root, 'td_threshold', thresh, filters=self.filter_tables)
     p1, p2, single_scan = plotting.plot_timewalk(h5_filename)
     output_file(self.output_filename + '.html', title=self.run_name)
     status = plotting.plot_status(h5_filename)
     save(hplot(vplot(p1, p2, status), single_scan))
Esempio n. 51
0
line1 = Line(df, x='date', y=['python', 'pypy', 'jython'],
             title="Interpreters (x='date', y=['python', 'pypy', 'jython'])", ylabel='Duration', legend=True)

line2 = Line(df, x='date', y=['python', 'pypy', 'jython'],
             dash=['python', 'pypy', 'jython'],
             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')", ylabel='Duration',
             legend=True)


output_file("lines.html", title="line.py example")


show(
    vplot(
        hplot(line0, line1),
        hplot(line2, line3),
        hplot(line4)
    )
)
Esempio n. 52
0
import pandas as pd
import operator
from bokeh.charts import Donut, Bar, show, vplot, Line, output_file

df = pd.read_csv("aviationdataset.csv", encoding ='latin1').fillna(0)
print("file loaded")

df['Location'] = df['Location'].apply(lambda word: str(word)[-2:])
us_states = df.loc[df['Country'] == 'United States']['Location'].unique()

injury_dict = {}
for state in us_states:
    injury_dict.update({ state : sum(df[df['Location'] == state][cat]) for cat in ['Total.Fatal.Injuries', 'Total.Serious.Injuries', 'Total.Minor.Injuries']} )
result_dict = dict(sorted(injury_dict.items(), key=operator.itemgetter(1), reverse=True)[:5])
x, y = zip(*sorted(result_dict.items()))
data = pd.Series(y, x)
bar2 = Bar(data, title="Top 5 States Of Aviation Injuries", plot_width=400)

p = vplot(bar2)
show(p)
Esempio n. 53
0
#        fatal = row['Total.Fatal.Injuries']
#        alive = sum(row[cat] for cat in ['Total.Serious.Injuries', 'Total.Minor.Injuries', 'Total.Uninjured'])
#        year_fatal.update({year : year_fatal.get(year) + fatal})
#        year_alive.update({year : year_alive.get(year) + alive})
#fx, fy = zip(*sorted(year_fatal.items()))
#fatal_data = pd.Series(fy, fx, name="fatal")
##print(fatal_data.head(5))

#ax, ay = zip(*sorted(year_alive.items()))
#alive_data = pd.Series(ay, ax, name="alive")
##print(alive_data.head(5))

#data = pd.concat([alive_data, fatal_data], axis=1)

#http://datascience.stackexchange.com/questions/10322/how-to-plot-multiple-variables-with-pandas-and-bokeh

#chart = Bar(data,title="Fatal Injury Distribution", legend="top_right", ylabel='Number of Fatalities', xlabel='Year')
#chart = Bar(data,
#          values=blend('fatal', 'alive', name='persons', labels_name='person'),
#          label=cat(columns='year', sort=False),
#          stack=cat(columns='person', sort=False),
#          color=color(columns='person',
#          palette=['SaddleBrown', 'Silver'],
#          sort=False))

#chart = Bar(data, stacked=True)
#show(chart)

p = vplot(pie_chart, bar2, minor_chart, serious_chart, fatal_chart, chart)
show(p)
Esempio n. 54
0
# given a categorical series of data with no aggregation
d4 = Donut(autompg.groupby('cyl').displ.mean())

# given a categorical series of data with no aggregation
d5 = Donut(autompg.groupby(['cyl', 'origin']).displ.mean(),
           hover_text='mean')

# no values specified
d6 = Donut(autompg, label='cyl', agg='count')

# explicit examples
d7 = Donut(autompg, label='cyl',
           values='displ', agg='mean')

# nested donut chart for the provided labels, with colors assigned
# by the first level
d8 = Donut(autompg, label=['cyl', 'origin'],
           values='displ', agg='mean')

# show altering the spacing in levels
d9 = Donut(autompg, label=['cyl', 'origin'],
           values='displ', agg='mean', level_spacing=0.15)

# show altering the spacing in levels
d10 = Donut(autompg, label=['cyl', 'origin'],
           values='displ', agg='mean', level_spacing=[0.8, 0.3])

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

show(vplot(d1, d2, d3, d4, d5, d6, d7, d8, d9, d10))
Esempio n. 55
0
from bokeh.charts import Histogram
from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import defaults, vplot, hplot, show, output_file

defaults.width = 450
defaults.height = 350

# input options
hist = Histogram(df['mpg'], title="df['mpg']")
hist2 = Histogram(df, 'displ', title="df, 'displ'")
hist3 = Histogram(df, values='hp', title="df, values='hp'")

hist4 = Histogram(df, values='hp', color='cyl',
                  title="df, values='hp', color='cyl'", legend='top_right')

hist5 = Histogram(df, values='mpg', bins=50,
                  title="df, values='mpg', bins=50")

output_file("histograms.html")

show(
    vplot(
        hplot(hist, hist2, hist3),
        hplot(hist4, hist5)
    )
)
Esempio n. 56
0
def scan_pix_hist(h5_file_name, scurve_sel_pix=200):
    with tb.open_file(h5_file_name, 'r') as in_file_h5:
        meta_data = in_file_h5.root.meta_data[:]
        hit_data = in_file_h5.root.hit_data[:]
        en_mask = in_file_h5.root.scan_results.en_mask[:]
        Noise_gauss = in_file_h5.root.Noise_results.Noise_pure.attrs.fitdata_noise
        Noise_pure = in_file_h5.root.Noise_results.Noise_pure[:]
        Thresh_gauss = in_file_h5.root.Thresh_results.Threshold_pure.attrs.fitdata_thresh
        Threshold_pure = in_file_h5.root.Thresh_results.Threshold_pure[:]
        scan_args = yaml.load(in_file_h5.root.meta_data.attrs.kwargs)
        scan_range = scan_args['scan_range']
        scan_range_inx = np.arange(scan_range[0], scan_range[1], scan_range[2])

        # np.set_printoptions(threshold=np.nan)
        param = np.unique(meta_data['scan_param_id'])
        ret = []
        for i in param:
            wh = np.where(hit_data['scan_param_id'] == i)  # this can be faster and multi threaded
            hd = hit_data[wh[0]]
            hits = hd['col'].astype(np.uint16)
            hits = hits * 64
            hits = hits + hd['row']
            value = np.bincount(hits)
            value = np.pad(value, (0, 64 * 64 - value.shape[0]), 'constant')
            if len(ret):
                ret = np.vstack((ret, value))
            else:
                ret = value
        repeat_command = max(ret[-3])
        shape = en_mask.shape
        ges = 1
        for i in range(2):
            ges = ges * shape[i]
        ret_pure = ()
        en_mask = en_mask.reshape(ges)
        for n in range(param[-1]):
            ret_pure1 = ()
            for i in range(ges):
                if (str(en_mask[i]) == 'True'):
                    ret_pure1 = np.append(ret_pure1, ret[n][i])
            if n == 0:
                ret_pure = ret_pure1
                continue
            ret_pure = np.vstack((ret_pure, ret_pure1))

        ret_pure = ret_pure.astype(int)
        s_hist = np.swapaxes(ret_pure, 0, 1)

        pix_scan_hist = np.empty((s_hist.shape[1], repeat_command + 10))
        for param in range(s_hist.shape[1]):
            h_count = np.bincount(s_hist[:, param])
            h_count = h_count[:repeat_command + 10]
            pix_scan_hist[param] = np.pad(h_count, (0, (repeat_command + 10) - h_count.shape[0]), 'constant')

        log_hist = np.log10(pix_scan_hist)
        log_hist[~np.isfinite(log_hist)] = 0
        data = {
            'scan_param': np.ravel(np.indices(pix_scan_hist.shape)[0]),
            'count': np.ravel(np.indices(pix_scan_hist.shape)[1]),
            'value': np.ravel(log_hist)
        }

        x = scan_range_inx
        px = scurve_sel_pix  # 1110 #1539
        single_scan = figure(title="Single pixel scan " + str(px), x_axis_label="Injection[V]", y_axis_label="Hits")
        single_scan.diamond(x=x, y=s_hist[px], size=5, color="#1C9099", line_width=2)
        yf = analysis.scurve(x, 100, Threshold_pure[px], Noise_pure[px])
        single_scan.cross(x=x, y=yf, size=5, color="#E6550D", line_width=2)

        hist, edges = np.histogram(Threshold_pure, density=False, bins=50)#50

        hm1 = HeatMap(data, x='scan_param', y='count', values='value', title='Threshold Heatmap',
                      palette=Spectral11[::-1], stat=None, plot_width=1000)  # , height=4100)
        hm1.extra_x_ranges = {
            "e": Range1d(start=edges[0] * 1000 * analysis.cap_fac(), end=edges[-1] * 1000 * analysis.cap_fac())}

        hm_th = figure(title="Threshold", x_axis_label="pixel #", y_axis_label="threshold [V]",
                       y_range=(scan_range_inx[0], scan_range_inx[-1]), plot_width=1000)
        hm_th.diamond(y=Threshold_pure, x=range(64 * 64), size=1, color="#1C9099", line_width=2)
        hm_th.extra_y_ranges = {"e": Range1d(start=scan_range_inx[0] * 1000 * analysis.cap_fac(),
                                             end=scan_range_inx[-1] * 1000 * analysis.cap_fac())}
        hm_th.add_layout(LinearAxis(y_range_name="e"), 'right')
        plt_th_dist = figure(title='Threshold Distribution ', x_axis_label="threshold [V]", y_axis_label="#Pixel",
                             y_range=(0, 1.1 * np.max(hist[1:])))
        plt_th_dist.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564",
                         line_color="#033649",
                         legend="# {0:d}  mean={1:.2f}  std={2:.2f}".format(int(np.sum(hist[:])), round(
                             Thresh_gauss['mu'] * 1000 * analysis.cap_fac(), 4),
                                                                            round(Thresh_gauss[
                                                                                      'sigma'] * 1000 * analysis.cap_fac(),
                                                                                  4)))
        plt_th_dist.extra_x_ranges = {"e": Range1d(start=edges[0] * 1000 * analysis.cap_fac(),
                                                   end=edges[-1] * 1000 * analysis.cap_fac())}  # better 7.4?
        plt_th_dist.add_layout(LinearAxis(x_range_name="e"), 'above')
        plt_th_dist.line(np.arange(edges[1], edges[-1], 0.0001),
                         analysis.gauss(np.arange(edges[1], edges[-1], 0.0001), Thresh_gauss['height'],
                                        Thresh_gauss['mu'], Thresh_gauss['sigma']), line_color="#D95B43", line_width=8,
                         alpha=0.7)

        hist, edges = np.histogram(Noise_pure, density=False, bins=50) #50
        hm_noise = figure(title="Noise", x_axis_label="pixel #", y_axis_label="noise [V]", y_range=(0, edges[-1]),
                          plot_width=1000)
        hm_noise.diamond(y=Noise_pure, x=range(64 * 64), size=2, color="#1C9099", line_width=2)
        hm_noise.extra_y_ranges = {"e": Range1d(start=0, end=edges[-1] * 1000 * analysis.cap_fac())}  # default 7.6
        hm_noise.add_layout(LinearAxis(y_range_name="e"), 'right')

        plt_noise_dist = figure(title='Noise Distribution ', x_axis_label="noise [V]", y_axis_label="#Pixel",
                                y_range=(0, 1.1 * np.max(hist[1:])))
        plt_noise_dist.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564",
                            line_color="#033649",
                            legend="# {0:d}  mean={1:.2f}  std={2:.2f}".format(int(np.sum(hist[:])), round(
                                Noise_gauss['mu'] * 1000 * analysis.cap_fac(), 4), round(
                                Noise_gauss['sigma'] * 1000 * analysis.cap_fac(), 4)))
        plt_noise_dist.extra_x_ranges = {
            "e": Range1d(start=edges[0] * 1000 * analysis.cap_fac(), end=edges[-1] * 1000 * analysis.cap_fac())}
        plt_noise_dist.add_layout(LinearAxis(x_range_name="e"), 'above')
        plt_noise_dist.line(np.arange(edges[0], edges[-1], 0.0001),
                            analysis.gauss(np.arange(edges[0], edges[-1], 0.0001), Noise_gauss['height'],
                                           Noise_gauss['mu'], Noise_gauss['sigma']), line_color="#D95B43", line_width=8,
                            alpha=0.7)

        return vplot(hplot(hm_th, plt_th_dist), hplot(hm_noise, plt_noise_dist), hplot(hm1, single_scan)), s_hist
Esempio n. 57
0
int_vhover.line_policy = 'interp'

iphover = int_point_line.select(dict(type=HoverTool))
iphover.mode = 'mouse'
iphover.line_policy = 'interp'

tphover = point_line.select(dict(type=HoverTool))
tphover.mode = 'mouse'

shover = scatter.select(dict(type=HoverTool))
shover.mode = 'vline'

shoverp = scatter_point.select(dict(type=HoverTool))
shoverp.mode = 'mouse'

int_vhover.tooltips = int_hhover.tooltips = tphover.tooltips = iphover.tooltips = shover.tooltips = shoverp.tooltips = vhover.tooltips = hhover.tooltips = OrderedDict([
    ("y", "$~y"),
    ("x", "$~x"),
    # ("data_x", "$~x"),
    # ("data_y", "$~y"),
])

show(
    vplot(
        hplot(hline, vline),
        hplot(int_hline, int_vline),
        hplot(int_point_line, point_line),
        hplot(scatter_point, scatter),
    )
)
Esempio n. 58
0
File: bar.py Progetto: nkhuyu/bokeh
bar_plot3 = Bar(df, label='cyl', values='mpg', agg='mean',
                title="label='cyl' values='mpg' agg='mean'")

bar_plot4 = Bar(df, label='cyl', title="label='cyl' color='DimGray'", color='dimgray')

# multiple columns
bar_plot5 = Bar(df, label=['cyl', 'origin'], values='mpg', agg='mean',
                title="label=['cyl', 'origin'] values='mpg' agg='mean'")

bar_plot6 = Bar(df, label='origin', values='mpg', agg='mean', stack='cyl',
                title="label='origin' values='mpg' agg='mean' stack='cyl'", legend='top_right')

bar_plot7 = Bar(df, label='cyl', values='displ', agg='mean', group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'", legend='top_right')

# ToDo: negative values
# bar_plot8 = Bar(df, label='cyl', values='neg_displ', agg='mean', group='origin', color='origin',
#                 title="label='cyl' values='displ' agg='mean' group='origin'", legend='top_right')


# collect and display
output_file("bar.html")

show(
    vplot(
        hplot(bar_plot, bar_plot2, bar_plot3),
        hplot(bar_plot4, bar_plot5, bar_plot6),
        hplot(bar_plot7)
    )
)