コード例 #1
0
    def knit_html(self,es):
        #col1
        fig1 = figure(width=250,height=250)
        vis_bokeh.draw_1d_hist_from_es("dummy1",0,35,30,es,"run*",ax=fig1) #changes fig1, but also returns it

        fig2=figure(width=250,height=250)
        xmin,xmax = 0,65
        xbins = 20
        xname = "hcalEnergy"
        ymin,ymax = 0,65
        ybins = 20
        yname = "muonHits"
        vis_bokeh.draw_2d_hist_from_es(xname,xmin,xmax,xbins,yname,ymin,ymax,ybins,es,
                                         index="run*",ax=fig2)
        fig_column1 = vplot(fig1,fig2)

        #col2
        fig3 = figure(width=250,height=250)
        fig3=vis_bokeh.draw_1d_hist_from_es("dummy23",0,100,30,es,"run*",ax=fig3,hist_drawer="classic")
        fig4 = figure(width=250,height=250)
        fig4=vis_bokeh.draw_1d_hist_from_es("dummy45",0,40,30,es,"run*",ax=fig4)
        fig_column2 = vplot(fig3,fig4)

        fig_grid = hplot(fig_column1,fig_column2)
        
        return vis_bokeh.fig_to_html(fig_grid)
コード例 #2
0
def mk_stat_plot(df):
    p1 = Bar(df, label='TARGET_SITE', values='TOTAL_TIME', agg='mean', group='PIPELINE', 
         title="Mean Processing for each site grouped by Pipeline"+"(Data Size:"+str(len(df.index))+")",
         legend='top_right',height=500,width=1000)
    df_camp_firstcut = df[ (df.TARGET_SITE == "descampuscluster") & (df.PIPELINE == "firstcut") ]
    df_fermi_firstcut = df[ (df.TARGET_SITE == "fermigrid") & (df.PIPELINE == "firstcut") ]
    df_camp_multi = df[ (df.TARGET_SITE == "descampuscluster") & (df.PIPELINE == "multiepoch") ]
    df_fermi_multi = df[ (df.TARGET_SITE == "fermigrid") & (df.PIPELINE == "multiepoch") ]
    p2 = Bar(df_camp_firstcut, label='EXEC_HOST', 
         values='TOTAL_TIME', agg='mean', title="Mean Processing of firstcut in Campuscluster for each Exac_host"+"(Data Size:"+str(len(df_camp_firstcut.index))+")",
         height=500, width=1000)
    p3 = Bar(df_fermi_firstcut, label='EXEC_HOST', values='TOTAL_TIME',
         agg='mean', title="Mean Processing of firstcut in Fermigrid for each Exac_host"+"(Data Size:"+str(len(df_fermi_firstcut.index))+")",
         height=500,width=1000)
    p4 = Bar(df_camp_multi, label='EXEC_HOST', values='TOTAL_TIME',
         agg='mean', title="Mean Processing of multiepoch in Campuscluster for each Exac_host"+"(Data Size:"+str(len(df_camp_multi.index))+")",
         height=500,width=1000)
    p5 = Bar(df_fermi_multi, label='EXEC_HOST', values='TOTAL_TIME',
         agg='mean', title="Mean Processing of multiepoch in Fermigrid for each Exac_host"+"(Data Size:"+str(len(df_fermi_multi.index))+")",
         height=500,width=1000)
    p6 = Bar(df, label='TARGET_SITE', values='TOTAL_TIME', stack='PIPELINE',
         title="Total time used by each Target site", legend='top_right',
         height=500,width=1000)
    p = vplot(p1,p2,p3,p4,p5,p6)
    return p
コード例 #3
0
def print_graphs(scores):
    output_file(s.plots + ".html")
    properties_per_dataset = {
        'train': {
            'line_color': 'firebrick'
        },
        'test': {
            'line_color': 'orange'
        },
        'valid': {
            'line_color': 'olive'
        }
    }

    plots = []
    for metric in ConfusionMatrix._fields:
        plot = figure(width=500, plot_height=500, title=metric)
        for dataset_name in scores:
            metric_scores = [
                score.value for score in scores[dataset_name][metric]
            ]
            plot.line(range(len(metric_scores)),
                      metric_scores,
                      legend=dataset_name,
                      **properties_per_dataset[dataset_name])
        plots.append(plot)
    p = vplot(*plots)
    save(p)
コード例 #4
0
def temporal_lda_plot(max_documents=50000000,
                      max_words_per_doc=50000000,
                      n_topics=100):
    # load the model:
    lda_model = pickle.load(open('../workspace/lda_model.m', 'rb'))
    # get top words per topic for title above plots:
    top_words = []
    for topic in lda_model.show_topics(num_topics=100,
                                       num_words=15,
                                       formatted=False):
        top_words.append(" ".join([w for _, w in topic]))

    # extract years from in the file ids in the original file:
    text_ids = list(
        DirectoryIterator(
            path_pattern='../workspace/wikified_periodicals/*.wikified',
            max_documents=max_documents,
            max_words_per_doc=max_words_per_doc,
            get='filename'))
    years = [id_.split('-')[-1].replace('.wikified', '') for id_ in text_ids]
    year_scores = {y: list() for y in years}

    # extract topic scores for each document:
    for line, year in zip(
            codecs.open('../workspace/mallet_output/doctopics.txt', 'r',
                        'utf8'), years):
        line = line.strip()
        if not line:
            continue
        comps = line.strip().split()
        topic_scores = [float(t) for t in comps[2:]]
        year_scores[year].append(topic_scores)

    for year in year_scores:
        m = np.asarray(year_scores[year], dtype='float32')
        year_scores[year] = np.mean(m, axis=0)

    year_scores = [(int(year), matrix) for year, matrix in year_scores.items()
                   if int(year) <= 2010]
    year_scores = sorted(year_scores, key=itemgetter(0))

    output_file("../figures/topics.html")
    plots = []

    year_labels = [year for year, _ in year_scores if int(year) <= 2010]

    for topic_idx in range(n_topics):
        scores = [m[topic_idx] for y, m in year_scores]

        p = figure(title=top_words[topic_idx],
                   plot_width=1200,
                   plot_height=400,
                   title_text_font_size='12pt')
        p.line(year_labels, scores, line_width=2)
        plots.append(p)

    p = vplot(*plots)
    save(p)
コード例 #5
0
def domains_dashboard(response, extra_plots=None):
    """
    Domains dashboard plot function. Takes an arguments for extra plots which
    will be added in a tab with the other plots.
    """
    # Parsed Response Data
    urls = [x[0][0] for x in response["pages"]]
    parsed_urls = [urlparse(x).hostname for x in urls]

    # Domain names Bar chart.
    domains = Counter(parsed_urls).most_common(PLOT_ELEMENTS)
    xdomains = [x[0] for x in domains]
    ydomains = [y[1] for y in domains]

    source_domains = ColumnDataSource(data=dict(x=xdomains, y=ydomains))
    bar_domains = Bar(source_domains.data, values="y", label="x", title="Most Common Domains by Number",
            bar_width=BAR_WIDTH, height=584, xlabel="Domains",
            ylabel="Occurences")
    panel_domains = Panel(child=bar_domains, title="Domains")

    # Domain Information Table
    columns_domain = [
            TableColumn(field="x", title="Domain"),
            TableColumn(field="y", title="Count"),
        ]
    data_table_domain = DataTable(source=source_domains, columns=columns_domain, width=400,
            height=280)

    # Top level Domains Bar Chart
    endings = Counter([x[x.rfind("."):] for x in parsed_urls]).most_common(PLOT_ELEMENTS)
    xendings = [x[0] for x in endings]
    yendings = [y[1] for y in endings]

    source_top_level = ColumnDataSource(data=dict(x=xendings, y=yendings))
    bar_top_level = Bar(source_top_level.data, values="y", label="x",
            title="Most Common URL Endings by Number", bar_width=BAR_WIDTH, height=584)
    panel_top_level = Panel(child=bar_top_level, title="Endings")

    # Top level domains table
    columns_top_level = [
            TableColumn(field="x", title="Top Level Domain"),
            TableColumn(field="y", title="Count"),
        ]
    data_table_top_level = DataTable(source=source_top_level,
            columns=columns_top_level, width=400, height=280)

    # Add the plots and charts to a vform and organize them with VBox and HBox
    plot_tabs = Tabs(tabs=[panel_domains, panel_top_level])

    # Take the two tables and the graph, turn them into VBox, then organize them
    # side by side in an HBox.
    vbox_tables = VBox(children=[data_table_domain, data_table_top_level])
    vbox_plots = VBox(children=[plot_tabs])
    hbox_dashboard = HBox(children=[vbox_tables, vbox_plots])
    return components(vplot(hbox_dashboard))
コード例 #6
0
 def start(self):
     freemem_graph, freemem_table, cpu_graph, cpu_table, bat_graph, bat_table, temp_graph, temp_table, data_graph, events_table = self.last_report(
     )
     graph = vplot(events_table, freemem_graph, freemem_table, cpu_graph,
                   cpu_table, bat_graph, bat_table, temp_graph, temp_table,
                   data_graph)
     s = self.folder[0] + '/' + 'report_%s.html' % self.build[0].replace(
         '.', '_')
     output_file(s,
                 title=self.build[0] + '-' + self.devicename[0] + 'Report')
     return show(graph)
コード例 #7
0
ファイル: orbit.py プロジェクト: helgee/plyades
 def plot_elements(self):
     elements = (
         'semi_major_axis',
         'eccentricity',
         'inclination',
         'ascending_node',
         'argument_of_periapsis',
         'true_anomaly',
     )
     plots = [self.plot_element(element, show_plot=False) for element in elements]
     show(vplot(*plots))
コード例 #8
0
def endings_dashboard(response):
    urls = [x[0][0] for x in response["pages"]]
    parsed_urls = [urlparse(x).hostname for x in urls]
    endings_counter = Counter([x[x.rfind("."):] for x in parsed_urls]).most_common(ENDING_PLOT_LIMIT)
    xendings = [x[0] for x in endings_counter]
    yendings = [y[1] for y in endings_counter]
    source = ColumnDataSource(data=dict(x=xendings, y=yendings))

    table = VBox(children=[endings_table(source)])
    plot = VBox(children=[endings_plot(source)])
    return components(vplot(HBox(children=[table, plot])))
コード例 #9
0
def endings_dashboard(response):
    urls = [x[0][0] for x in response["pages"]]
    parsed_urls = [urlparse(x).hostname for x in urls]
    endings_counter = Counter([x[x.rfind("."):] for x in parsed_urls
                               ]).most_common(ENDING_PLOT_LIMIT)
    xendings = [x[0] for x in endings_counter]
    yendings = [y[1] for y in endings_counter]
    source = ColumnDataSource(data=dict(x=xendings, y=yendings))

    table = VBox(children=[endings_table(source)])
    plot = VBox(children=[endings_plot(source)])
    return components(vplot(HBox(children=[table, plot])))
コード例 #10
0
ファイル: orbit.py プロジェクト: vikashkodati/plyades
 def plot_elements(self):
     elements = (
         'semi_major_axis',
         'eccentricity',
         'inclination',
         'ascending_node',
         'argument_of_periapsis',
         'true_anomaly',
     )
     plots = [
         self.plot_element(element, show_plot=False) for element in elements
     ]
     show(vplot(*plots))
コード例 #11
0
def author_frequency_barplot(nb_top_ners=50, tf=True):
    if tf:
        output_file('../figures/tf_authors.html')
        ner_freqs = pickle.load(open('../workspace/tf.m', "rb"))
    else:
        output_file('../figures/df_authors.html')
        ner_freqs = pickle.load(open('../workspace/df.m', "rb"))

    top_ners = [w for w, _ in ner_freqs.most_common(nb_top_ners)]
    top_freqs = [c for _, c in ner_freqs.most_common(nb_top_ners)]

    names = []
    for name in top_ners:
        name = name.replace('*', '')
        if '(' in name:
            name = name.split('(')[0].strip()
        name = ' '.join([n.lower().capitalize() for n in name.split('_')])
        name = ''.join([
            c for c in unicodedata.normalize('NFKD', name)
            if not unicodedata.combining(c)
        ])
        names.append(name)

    data = pd.DataFrame({'values': top_freqs[:25], 'labels': names[:25]})
    bar1 = Bar(data,
               label=CatAttr(columns=['labels'], sort=False),
               values='values',
               title='Author Frequency (1-25)',
               width=800,
               height=400)
    xaxis = bar1.select(dict(type=Axis))[1]
    xaxis.major_label_standoff = 0
    xaxis.major_label_orientation = np.pi / 2
    xaxis.major_label_standoff = 6
    xaxis.major_tick_out = 0

    data = pd.DataFrame({'values': top_freqs[25:50], 'labels': names[25:50]})
    bar2 = Bar(data,
               label=CatAttr(columns=['labels'], sort=False),
               values='values',
               title='Author Frequency (25-50)',
               width=800,
               height=400)
    xaxis = bar2.select(dict(type=Axis))[1]
    xaxis.major_label_standoff = 0
    xaxis.major_label_orientation = np.pi / 2
    xaxis.major_label_standoff = 6
    xaxis.major_tick_out = 0
    p = vplot(bar1, bar2)
    save(p)
コード例 #12
0
def domains_dashboard(response, extra_plots=None):
    """
    Domains dashboard plot function. Takes an arguments for extra plots which
    will be added in a tab with the other plots.
    """
    # Parsed Response Data
    urls = [x[0][0] for x in response["pages"]]
    parsed_urls = [urlparse(x).hostname for x in urls]

    # Domain names Bar chart.
    domains_counter = Counter(parsed_urls).most_common(DOMAIN_PLOT_LIMIT)
    xdomains = [x[0] for x in domains_counter]
    ydomains = [y[1] for y in domains_counter]
    source_domains = ColumnDataSource(data=dict(x=xdomains, y=ydomains))

    bar_domains = Bar(source_domains.data,
                      values="y",
                      label="x",
                      title="Most Common Sites by Number",
                      bar_width=BAR_WIDTH,
                      height=584,
                      xlabel="Sites",
                      ylabel="Occurences")
    panel_domains = Panel(child=bar_domains, title="Sites")

    # Domain Information Table
    table_domains_counter = Counter(parsed_urls).most_common(
        DOMAIN_TABLE_LIMIT)
    xdomains_table = [x[0] for x in table_domains_counter]
    ydomains_table = [y[1] for y in table_domains_counter]
    source_table_domains = ColumnDataSource(
        data=dict(x=xdomains_table, y=ydomains_table))

    columns_domain = [
        TableColumn(field="x", title="Site Name"),
        TableColumn(field="y", title="Count"),
    ]
    data_table_domain = DataTable(source=source_table_domains,
                                  columns=columns_domain,
                                  width=400,
                                  height=280)

    # Add the plots and charts to a vform and organize them with VBox and HBox
    plot_tabs = Tabs(tabs=[panel_domains, extra_plots])

    # Take the plot and table and arrange them in a hbox.
    vbox_tables = VBox(children=[data_table_domain])
    vbox_plots = VBox(children=[plot_tabs])
    hbox_dashboard = HBox(children=[vbox_tables, vbox_plots])
    return components(vplot(hbox_dashboard))
コード例 #13
0
 def knit_html(self,es):
     
     figs = []
     for i in range(len(self.hists)):
         figs.append(
             [self.make_figure(hist,model,es,"run*") for hist,model in zip(self.hists[i],self.models[i])]
             )
     hrows = [hplot(*row) for row in figs]
     grid = vplot(*hrows)
         
         
         
     
     return vis_bokeh.fig_to_html(grid)
コード例 #14
0
ファイル: plot.py プロジェクト: bkreider/misc
def main():
    setup_logging()
    logging.getLogger("requests").setLevel(logging.WARNING)

    output_server("Temp Chart")

    window = 200
    width = 800
    height = 200

    now = datetime.now()
    start = now - timedelta(hours=window)
    r_start = time.mktime(start.timetuple()) * 1000 - 20000000
    r_end = time.mktime(now.timetuple()) * 1000 - 20000000
    ran = Range1d(r_start, r_end)

    # line chart
    line_fig = figure(plot_width=width, plot_height=height) #, x_range=ran)
    line = line_fig.line(x=[], y=[])

    # circle chart
    c_fig = figure(plot_width=width, plot_height=height)
    circle = c_fig.circle(x=[], y=[], size=1)

    # format axes
    line_fig.xaxis[0].formatter = DatetimeTickFormatter(formats=dict(days=["%T"]))
    line_fig.xaxis.major_label_orientation = pi/4
    c_fig.xaxis[0].formatter = DatetimeTickFormatter(formats=dict(days=["%T"]))
    c_fig.xaxis.major_label_orientation = pi/4

    p = vplot(line_fig, c_fig)
    show(p)

    line_ds = line.select(dict(type=GlyphRenderer))[0].data_source
    circle_ds = circle.select(dict(type=GlyphRenderer))[0].data_source

    lines = tail_generator(exit_after=0)
    if True:
        for line in lines:
            line = decimate(lines, skip=300)
            temp, date = parse_line(line)
            if temp is None:
                continue
            update_series(line_ds, date, temp)
            update_range(line_ds, line_fig, 60)
            update_series(circle_ds, date, temp)
            update_range(circle_ds, c_fig, 12)
            time.sleep(0.01)

    return c_fig, circle
コード例 #15
0
def make_dts_plot():

    plots = []
    etime = datetime.combine(date.today(), datetime.min.time())
    stime = etime - timedelta(14)
    graphstime = datetime.strptime('01-01-15 00:00:00', '%m-%d-%y %H:%M:%S')
    days = 1

    ### Fetch Data ###
    accept_df = get_data.get_accept_time()
    ingest_df = get_data.get_ingest_time()
    sispi_df = pd.DataFrame(query.query_exptime(query.connect_to_db('db-sispi')[1], etime, datetime.now()), columns = ['sispi_time','filename'])
    weekly_df = pd.DataFrame(query.query_dts_delay(query.connect_to_db('db-destest')[1], stime, etime), columns = ['total_time', 'ncsa_time', 'noao_time', 'xtime'])
    alltime_df = pd.DataFrame(query.query_dts_delay(query.connect_to_db('db-destest')[1], graphstime, etime), columns = ['total_time', 'ncsa_time', 'noao_time', 'xtime']) 


    ### Standardize file names for merge ###
    trimed_fn = []
    for i, line in sispi_df.iterrows():
        try:
            trimed_fn.append(os.path.basename(line['filename'].split(':')[1]))
        except:
            trimed_fn.append(os.path.basename(line['filename']))
    sispi_df['filename']=trimed_fn

    ### Merge data ###
    log_df = pd.merge(accept_df, ingest_df, how='inner', on=['filename'])
    live_df = pd.merge(log_df, sispi_df, how='inner', on=['filename'])

    live_df = get_data.convert_timezones(live_df)

    ### Smooth plot ###
    sm_df = get_data.smooth_dts(weekly_df)
    av_df = get_data.average_dts(alltime_df, graphstime, days)

    ### Plot Data ###
    plots.append(plotter.plot_realtime_dts(sm_df, live_df))
    plots.append(plotter.plot_monthly_dts(av_df, days))
    plots.append(plotter.plot_average_dts(alltime_df, days))

    ### Writing plots to HTML ###    
    html = file_html(vplot(*plots),INLINE,'dts')
    filename = 'dts_plot.html'
    filepath = os.path.join(app.config["STATIC_PATH"],filename)
    with open(filepath,'w') as h:
        h.write('<h5> Last updated on: %s </h5>' % "{0}".format(datetime.now()))
        h.write('<center>\n')
        h.write(html)
        h.write('</center>\n')
コード例 #16
0
ファイル: ui.py プロジェクト: ricsirke/SoundFreqPlotter
	def init_controls(self):
		btnStop = Button(label="Stop", type="danger")
		btnStart = Button(label="Start", type="success")	
		
		btnStop.on_click(self.handle_btnStop_press)
		btnStart.on_click(self.handle_btnStart_press)
				
		curdoc().add_root(btnStop)
		curdoc().add_root(btnStart)
		

		sliderHPThreshold = Slider(start=0, end=500, value=100, step=1, title="High pass threshold")
			
		sliderHPThreshold.on_change('value', self.onChangeHPThreshold)
		curdoc().add_root(vplot(sliderHPThreshold))
コード例 #17
0
def main():

    data = [[1, 1]]
    data += [[2, 3]]
    data += [[4, 3]]
    data += [[3, 2]]
    data += [[5, 5]]

    output_file("test.html")
    lineGraph = figure(plot_width=800,
                       plot_height=800,
                       title=None,
                       toolbar_location='below',
                       toolbar_sticky=False)

    # plotting data
    xcord = [item[0] for item in data]
    ycord = [item[1] for item in data]
    lineGraph.square(xcord, ycord, size=10)

    w = [0, 0]
    learningRate = 0.001

    errorArray = []
    for test in range(100):
        errorSum = 0
        for point in data:
            error = point[1] - evaluate(w, point[0])
            w[0] = w[0] + (error * learningRate)
            w[1] = w[1] + (error * learningRate * point[0])
            errorSum += (error * error)
        errorArray.append((1.0 / 5) * errorSum)

        print(w)

    lineGraph.line([0, 10], [w[0], evaluate(w, 10)], line_width=2)

    errorGraph = figure(plot_width=800,
                        plot_height=800,
                        title=None,
                        toolbar_location='below',
                        toolbar_sticky=False)

    errorGraph.line(range(len(errorArray)), errorArray, line_width=2)

    graphs = vplot(lineGraph, errorGraph)
    show(graphs)
コード例 #18
0
ファイル: ui.py プロジェクト: ricsirke/SoundFreqPlotter
    def init_controls(self):
        btnStop = Button(label="Stop", type="danger")
        btnStart = Button(label="Start", type="success")

        btnStop.on_click(self.handle_btnStop_press)
        btnStart.on_click(self.handle_btnStart_press)

        curdoc().add_root(btnStop)
        curdoc().add_root(btnStart)

        sliderHPThreshold = Slider(start=0,
                                   end=500,
                                   value=100,
                                   step=1,
                                   title="High pass threshold")

        sliderHPThreshold.on_change('value', self.onChangeHPThreshold)
        curdoc().add_root(vplot(sliderHPThreshold))
コード例 #19
0
def make_system_plots(sys_df, res, des_df):
    
    plots = []
    
    try:
        p_du = plotter.data_usage_plot(des_df)
        plots.append(p_du)
    except:
        print "data_usage failed"
        pass
    try:
        p_ttfts = plotter.plot_tape_tar_file_transfer_status(sys_df['run_time'],sys_df['number_transferred'],sys_df['number_not_transferred'])
        plots.append(p_ttfts)
    except:
        print "tape_tar_file failed"
        pass
    try:
        p_bs = plotter.plot_backup_size(sys_df['run_time'],sys_df['size_transferred'],sys_df['size_to_be_transferred'])
        plots.append(p_bs)
    except:
        print "backup_size failed"
        pass
    try:
        p_prp = plotter.plot_pipeline_run_progress(sys_df['run_time'],sys_df['pipe_processed'],sys_df['pipe_to_be_processed'])
        plots.append(p_prp)
    except:
        print "pipeline_run failed"
        pass
    try:
        p_dtss = plotter.plot_dts_status(sys_df['run_time'],sys_df['raw_processed'],sys_df['raw_to_be_processed'])
        plots.append(p_dtss)
    except:
        print "dts_status failed"
        pass
    try:
        p_ts = plotter.plot_system_transfer_rates(res['tdate'],res['tsize'],res['tav'])
        plots.append(p_ts)
    except:
        print "system_transfer failed"
        pass

    html_vplots = vplot(*plots)

    return html_vplots
コード例 #20
0
ファイル: plot_functions.py プロジェクト: orianac/ipynb
def bokeh_plot(site, obs, obs_label, data_dict, outfile, title, resample_frequency, add_statistics=True):
    '''
    Plots a bokeh (interactive) daily or weekly series. 
    Inputs:
    site: a string ID which is input to the obs and data_dict objects
    obs: a pandas dataframe with columns labeled with the site IDs
    data_dict: an ordered dictionary with keys each of the series you want to plot with structure:
    {'series_name': {'data': pandas_dataframe, 'color': 'the color you want the timeseries to plot as'}}
    outfile: path where you want to save the bokeh plot
    title: title string for your plot
    resample_frequency: either 'w' for weekly or 'd' for daily (this is used to decide the frequency of the plotting)
    add_statistics: if True (default) will include the statistics of KGE and bias in the plot's legend
    '''
    reset_output()
    resample_dict = {'W': 'Weekly',
                'D': 'Daily'}
    output_file(outfile, title=title)

    p1 = figure(width=1000, height=400, x_axis_type = "datetime", title=title)
    obs_resampled =obs.resample(resample_frequency, how='mean')
    p1.line(obs_resampled.index.values,obs_resampled.values/100000, color='#000000',  legend=obs_label, line_width=2)
    
    for scenario in data_dict.keys():
        sim = data_dict[scenario]['data'][site]
        daily_kge = str(np.round(kge(sim, obs, 'D'), 2))
        weekly_kge = str(np.round(kge(sim, obs, 'W'), 2))
        scenario_bias = str(np.round(bias(sim, obs),2))
        if add_statistics:
            legend_label = scenario+', Daily KGE='+daily_kge+',\nWeekly KGE='+weekly_kge+' Bias='+scenario_bias+'%'
        else:
            legend_label = scenario
        sim_resampled = data_dict[scenario]['data'][site].resample(resample_frequency, how='mean')
        p1.line(sim_resampled.index.values, sim_resampled.values/100000, 
            color=data_dict[scenario]['color'], line_width=2, 
                legend=legend_label)
    p1.grid.grid_line_alpha=0.3
    p1.xaxis.axis_label = 'Date'
    p1.yaxis.axis_label = 'Streamflow [CFS*100,000]'
    p1.legend.label_text_font_size = '8'

    window_size = 30
    window = np.ones(window_size)/float(window_size)
    g = vplot(p1)
    save(g)    
コード例 #21
0
ファイル: execute_plot.py プロジェクト: rmcgibbo/osprey
def execute(args, parser):
    config = Config(args.config, verbose=False)
    with config.trialscontext() as session:
        q = (session.query(Trial)
             .filter(Trial.status == 'SUCCEEDED')
             .order_by(Trial.started))
        data = [curr.to_dict() for curr in q.all()]

    bk.output_file(args.filename, title='osprey')
    p4 = plot_4(data)
    p1 = plot_1(data)
    p2 = plot_2(data)
    p3 = plot_3(data, config.search_space())

    p = vplot(p1, p2, p3, *p4)
    if args.browser:
        bk.show(p)
    else:
        bk.save(p)
コード例 #22
0
def domains_dashboard(response, extra_plots=None):
    """
    Domains dashboard plot function. Takes an arguments for extra plots which
    will be added in a tab with the other plots.
    """
    # Parsed Response Data
    urls = [x[0][0] for x in response["pages"]]
    parsed_urls = [urlparse(x).hostname for x in urls]

    # Domain names Bar chart.
    domains_counter = Counter(parsed_urls).most_common(DOMAIN_PLOT_LIMIT)
    xdomains = [x[0] for x in domains_counter]
    ydomains = [y[1] for y in domains_counter]
    source_domains = ColumnDataSource(data=dict(x=xdomains, y=ydomains))

    bar_domains = Bar(source_domains.data, values="y", label="x", title="Most Common Sites by Number",
            bar_width=BAR_WIDTH, height=584, xlabel="Sites",
            ylabel="Occurences")
    panel_domains = Panel(child=bar_domains, title="Sites")

    # Domain Information Table
    table_domains_counter = Counter(parsed_urls).most_common(DOMAIN_TABLE_LIMIT)
    xdomains_table = [x[0] for x in table_domains_counter]
    ydomains_table = [y[1] for y in table_domains_counter]
    source_table_domains = ColumnDataSource(data=dict(x=xdomains_table,
        y=ydomains_table))

    columns_domain = [
            TableColumn(field="x", title="Site Name"),
            TableColumn(field="y", title="Count"),
        ]
    data_table_domain = DataTable(source=source_table_domains, columns=columns_domain, width=400,
            height=280)

    # Add the plots and charts to a vform and organize them with VBox and HBox
    plot_tabs = Tabs(tabs=[panel_domains, extra_plots])

    # Take the plot and table and arrange them in a hbox.
    vbox_tables = VBox(children=[data_table_domain])
    vbox_plots = VBox(children=[plot_tabs])
    hbox_dashboard = HBox(children=[vbox_tables, vbox_plots])
    return components(vplot(hbox_dashboard))
コード例 #23
0
ファイル: main.py プロジェクト: lobachevzky/database_nn
def print_graphs(scores):
    output_file(s.plots + ".html")
    properties_per_dataset = {
        'train': {'line_color': 'firebrick'},
        'test': {'line_color': 'orange'},
        'valid': {'line_color': 'olive'}
    }

    plots = []
    for metric in ConfusionMatrix._fields:
        plot = figure(width=500, plot_height=500, title=metric)
        for dataset_name in scores:
            metric_scores = [score.value for score in scores[dataset_name][metric]]
            plot.line(range(len(metric_scores)),
                      metric_scores,
                      legend=dataset_name,
                      **properties_per_dataset[dataset_name])
        plots.append(plot)
    p = vplot(*plots)
    save(p)
コード例 #24
0
def makeFeaturePlots(modelFolder, outputFolder, drugName):
    clf = joblib.load(modelFolder + drugName)
    output_file(outputFolder +  drugName + ".html", title = drugName + ' Features')
    featureDataFrame = joblib.load('../output/emptyDataFrame.pkl')
    featureDataFrame['Feature Importance'] = clf.coef_
    featureDataFrame.sort(columns='Feature Importance', inplace=True)
    
    resistanceGenes= featureDataFrame.index.values[:25]
    resistanceValues= featureDataFrame['Feature Importance'].values[:25]
    
    featureDataFrame.sort(columns='Feature Importance', inplace=True, ascending= False)

    sensitivityGenes = featureDataFrame.index.values[:25]
    sensitivityValues = featureDataFrame['Feature Importance'].values[:25]
    
    
    s1 = Bar(resistanceValues, cat=resistanceGenes.tolist(), title="Top 25 Resistance Genes for " + drugName, xlabel='Genes', ylabel = 'Coefficient', width=800, height=400, tools = False)
    s2 = Bar(sensitivityValues, cat=sensitivityGenes.tolist(), title="Top 25 Senitivity Genes for " + drugName, xlabel='Genes', ylabel = 'Coefficient', width=800, height=400, tools = False, palette = ['#82CC9B'])
    p = vplot(s1, s2)
    show(p)
コード例 #25
0
    def _init_plot(self):
        # get recoating data
        query = "SELECT MAX(ReplacementDate) AS ReplacementDate, SegmentPosition" \
                "       FROM MirrorRecoating" \
                "       GROUP BY SegmentPosition ORDER BY ReplacementDate, SegmentPosition"
        df = pd.read_sql(query, db.engine)

        # add missing segment positions
        missing_positions = [p for p in range(1, 92) if p not in df.SegmentPosition.values]
        df_missing = pd.DataFrame(dict(SegmentPosition=missing_positions,
                                       ReplacementDate=len(missing_positions) * [datetime.date(1970, 1, 1)]))
        df = df.append(df_missing, ignore_index=True)

        # sort by date (in descending order)
        df.sort_values(by='ReplacementDate', ascending=False, inplace=True)

        # add cumulative number of replacements since one recoating period ago
        start = self.now - datetime.timedelta(self.RECOATING_PERIOD)
        recoatings = len(df[df.ReplacementDate >= start])
        df['RecoatingsSinceYearStart'] = [max(recoatings - i, 0) for i in range(0, 91)]

        # add days since recoating
        df['DaysSinceReplacement'] = [(self.now - d).days for d in df.ReplacementDate.values]

        # add segment position coordinates
        df['SegmentPositionX'] = [self.mirror_positions[m][0] for m in df.SegmentPosition]
        df['SegmentPositionY'] = [self.mirror_positions[m][1] for m in df.SegmentPosition]
        df['SegmentPositionCornerXs'] = [self._segment_corners(m)[0] for m in df.SegmentPosition]
        df['SegmentPositionCornerYs'] = [self._segment_corners(m)[1] for m in df.SegmentPosition]

        # create data source
        source = ColumnDataSource(df)

        table = self._table(source)
        replacement_plot = self._replacement_plot(source)
        segment_plot = self._segment_plot(source)

        srp = vplot(replacement_plot, segment_plot)

        self.plot = hplot(table, srp)
コード例 #26
0
ファイル: guitest.py プロジェクト: YDnepr/asda
def getPlot(fileName):
    source = ColumnDataSource(mpg)
    
    manufacturers = sorted(mpg["manufacturer"].unique())
    models = sorted(mpg["model"].unique())

    
    columns = [
        TableColumn(field="manufacturer", title="Manufacturer", editor=SelectEditor(options=manufacturers), formatter=StringFormatter(font_style="bold")),
        TableColumn(field="model",        title="Model",        editor=StringEditor(completions=models)),
        TableColumn(field="displ",        title="Displacement", editor=NumberEditor(step=0.1),              formatter=NumberFormatter(format="0.0")),
        TableColumn(field="year",         title="Year",         editor=IntEditor()),
        TableColumn(field="cyl",          title="Cylinders",    editor=IntEditor()),
        TableColumn(field="cty",          title="City MPG",     editor=IntEditor()),
        TableColumn(field="hwy",          title="Highway MPG",  editor=IntEditor()),
    ]
    data_table = DataTable(source=source, columns=columns, editable=True)
    
    plot = Plot(title=None, x_range= DataRange1d(), y_range=DataRange1d(), plot_width=1000, plot_height=300)
    
    # Set up x & y axis
    plot.add_layout(LinearAxis(), 'below')
    yaxis = LinearAxis()
    plot.add_layout(yaxis, 'left')
    plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))
    
    
    # Add Glyphs
    cty_glyph = Circle(x="index", y="cty", fill_color="#396285", size=8, fill_alpha=0.5, line_alpha=0.5)
    hwy_glyph = Circle(x="index", y="hwy", fill_color="#CE603D", size=8, fill_alpha=0.5, line_alpha=0.5)
    plot.add_glyph(source, cty_glyph)
    plot.add_glyph(source, hwy_glyph)

    layout = vplot(plot, data_table)
    script, div = components(layout)
    html = readHtmlFile(fileName)
    html = gui.insertScriptIntoHeader(html, script)
    html = gui.appendElementContent(html, div, "div", "bokehContent")

    return html
コード例 #27
0
def make_coadd_html():
    try:
        all_df, processed_df, band_df = get_data.create_coadd_map('db-desoper',"Y3A1_COADD")
        p = plotter.plot_coadd(all_df, processed_df, band_df, "Y3A1_COADD")
    except:
        print 'Coadd plot not rendered!'
        pass    

    # Creating output path
    path = os.path.join(app.config["STATIC_PATH"],"reports/coadd/")
    if not os.path.isdir(path): os.makedirs(path)

    # Writing plots to HTML    
    html = file_html(vplot(p),INLINE,'coadd')
    filename = 'coadd_map_save.html'
    includepath = 'reports/coadd/coadd_map_save.html'
    filepath = os.path.join(path,filename)
    with open(filepath,'w') as h:
        h.write('<h5> Last updated on: %s </h5>' % "{0}".format(datetime.now()))
        h.write('<center>\n')
        h.write(html)
        h.write('</center>\n')
コード例 #28
0
ファイル: bokeh_plot.py プロジェクト: NSLS-II/album
def plot_table_by_time(table):
    plots = []
    table = table.set_index('time')
    for col in table:
        s = table[col]
        s.dropna(inplace=True)
        if not np.isscalar(s.values[0]):
            # replace with the sum
            s = s.apply(np.sum)
        x_range = plots[0].x_range if plots else None
        fig = figure(title=col, x_axis_type='datetime', x_range=x_range)
        fig.line(s.index, s, line_width=2)
        fig.circle(s.index, s, fill_color='white', size=8)
        plots.append(fig)

    ncols = int(np.ceil(np.sqrt(len(plots))))
    nrows = int(np.ceil(len(plots) / ncols))
    rows = [hplot(*plots[row*ncols:(row+1)*ncols]) for row in range(nrows)]
    plot = vplot(*rows)
    print('plot = %s' % plot)
    script, div = components(plot)
    return {'plot_div': div, 'plot_resources': PLOT_RESOURCES,
            'plot_script': script, 'bokeh_version': bokeh.__version__}
コード例 #29
0
ファイル: execute_plot.py プロジェクト: brookehus/osprey
def execute(args, parser):
    config = Config(args.config, verbose=False)
    with config.trialscontext() as session:
        q = (session.query(Trial)
             .filter(Trial.status == 'SUCCEEDED')
             .order_by(Trial.started))
        data = [curr.to_dict() for curr in q.all()]

    bk.output_file(args.filename, title='osprey')

    plots = []
    ss = config.search_space()
    for plot in PLOTS:
        plt = plot(data, ss)
        if plt is not None:
            plt = plt if isinstance(plt, list) else [plt]
            plots.extend(plt)

    p = vplot(*plots)
    if args.browser:
        bk.show(p)
    else:
        bk.save(p)
コード例 #30
0
    def create_objects(cls, symbol, df, securities):
        descr_box = Paragraph(text='content loading...')

        btn_close_loading = Button(label='Close Loading')
        dialog_loading = Dialog(title='loading',
                                content=vplot(descr_box),
                                name='loading_dialog',
                                buttons=[btn_close_loading],
                                visible=False)

        source_data = dict(df)
        main_source = ColumnDataSource(dict(df))
        source = ColumnDataSource(source_data)

        # TODO: REMOVE THIS COMMENTED CODE! IT'S JUST THE PREVIOUS
        # VERSION USED BEFORE NEW P&D Cached results and algorithm
        # get the cached results of the P&D algorithm computed with the
        # "default" configuration
        # intervals = utils.cached_pumps.get(symbol, pumps.to_dicts(((),(),(),(),(),())))
        # intervals['bottom'] = [0] * len(intervals['start'])
        # intervals['values'] = [max(df['price'])] * len(intervals['start'])
        #
        # intervals = pd.DataFrame(intervals)

        # new version
        stats = utils.get_symbols_cached_stats()[symbol]
        intervals = pd.DataFrame(stats)
        intervals['bottom'] = [0] * len(intervals['start'])
        intervals['values'] = [max(df['price'])] * len(intervals['start'])

        conv = lambda x: utils.to_seconds(pd.to_datetime(x))

        intervals = intervals[
            (pd.to_datetime(intervals['start']) > conv(config.date_range[0])) &
            (pd.to_datetime(intervals['start']) < conv(config.date_range[1]))]

        # Create P&Ds intervals DataSource
        intervals_source = ColumnDataSource(intervals)
        source.tags = ['main_source']

        trends = utils.load_trends_data(symbol, start_date=min(df['dt']))
        trends_source = ColumnDataSource(trends)

        trades = Slider(title="trades",
                        name='trades',
                        value=0,
                        start=0,
                        end=124,
                        step=1)

        # Selectors
        symbol = Select.create(options=securities,
                               value=symbol,
                               name='symbol',
                               title="")
        window_selector = Select.create(options=['---'],
                                        name='period_selector',
                                        title="Search intervals with:")
        symbol_filter = Select.create(
            options=['All', 'Stocks with Spam', 'Stocks without Spam'],
            name='symbol_filter',
            title="Filter Symbols:",
            value='Stocks with Spam')
        callback = Callback(args={
            'symbol_filter': symbol_filter,
            'dialog_loading': dialog_loading
        },
                            code=callbacks.symbol_filter)
        symbol_filter.callback = callback

        btn_detect_pumps = Button(label='Configure P&D Detection',
                                  name='config_pumps')

        main_tab = Panel(title="Main")
        tabs = Tabs()

        # Create STOCKS TABLE
        ranks = utils.get_pumps_rank()
        # quotient_metrics = utils.get_quotient_metrics()
        # ranks['quotient'] = quotient_metrics['quotient']

        foo = lambda x: utils.spams_count.get(x, 0)
        ranks['spams'] = map(foo, ranks['symbol'])
        ranks = ranks.sort(['spams', 'vol_quotient'], ascending=False)

        cls._pre_filtered_ranks = {
            'All': {k: ranks[k]
                    for k in ranks.columns},
            'Stocks with Spam':
            dict(ranks[ranks['spams'] > 0].sort('vol_quotient',
                                                ascending=False)),
            'Stocks without Spam':
            dict(ranks[ranks['spams'] == 0].sort('vol_quotient',
                                                 ascending=False)),
        }

        source_stocks_rank = ColumnDataSource(cls._pre_filtered_ranks['All'])

        table_stocks_rank = DataTable(
            source=source_stocks_rank,
            width=560,
            height=450,
            selectable=True,
            editable=True,
            columns=[
                TableColumn(field='symbol',
                            title='symbol',
                            width=130,
                            editor=StringEditor()),
                TableColumn(field='vol_quotient',
                            title='volume ratio',
                            editor=StringEditor(),
                            default_sort='descending'),
                TableColumn(field='risk_score',
                            title='risk',
                            width=100,
                            editor=StringEditor(),
                            default_sort='descending'),
                TableColumn(field='spams',
                            title='spams',
                            width=130,
                            editor=StringEditor(),
                            default_sort='descending'),
            ])

        callback = Callback(args={
            'tr': table_stocks_rank,
            'sr': source_stocks_rank,
            'symb': symbol,
            'dialog_loading': dialog_loading
        },
                            code=callbacks.source_stocks_rank)
        source_stocks_rank.callback = callback

        return locals()
コード例 #31
0
ファイル: visualisation.py プロジェクト: prajdabre/knmt
           0.9,
           source=source,
           color='colors',
           alpha='alphas',
           line_color=None)

    p.grid.grid_line_color = None
    p.axis.axis_line_color = None
    p.axis.major_tick_line_color = None
    p.axis.major_label_text_font_size = "10pt"
    p.axis.major_label_standoff = 0
    p.xaxis.major_label_orientation = np.pi / 3

    hover = p.select(dict(type=HoverTool))
    hover.tooltips = [
        ('tgt/src', '@yname, @xname'),
        ('attn', '@count'),
    ]

    return p

if __name__ == '__main__':
    src = ["le", "est", "un"]
    tgt = ["the", "one", "is", "about"]
    alignment = np.array([[0, 1, 2, 5], [2, 4, 6, 7], [9, 1, 3, 3]]) / 10.0
    print alignment
    p1 = make_alignment_figure(src, tgt, alignment)
    p2 = make_alignment_figure(src, tgt, alignment)
    p_all = vplot(p1, p2)
    show(p)
コード例 #32
0
ファイル: orbit.py プロジェクト: vikashkodati/plyades
 def plot(self):
     plots = [
         vis.plot_plane(self, plane=plane, show_plot=False)
         for plane in ('XY', 'XZ', 'YZ')
     ]
     show(vplot(*plots))
コード例 #33
0
ファイル: glyphs.py プロジェクト: brianpanneton/bokeh
p = figure(title="diamond")
p.scatter(x, y, marker="diamond", size=sizes, color="#1C9099", line_width=2)
plots.append(p)

p = figure(title="inverted_triangle")
p.scatter(x, y, marker="inverted_triangle", size=sizes, color="#DE2D26")
plots.append(p)

p = figure(title="square_x")
p.scatter(x, y, marker="square_x", size=sizes, color="#FDAE6B", fill_color=None, line_width=2)
plots.append(p)

p = figure(title="asterisk")
p.scatter(x, y, marker="asterisk", size=sizes, color="#F0027F", line_width=2)
plots.append(p)

p = figure(title="square_cross")
p.scatter(x, y, marker="square_cross", size=sizes, color="#7FC97F", fill_color=None, line_width=2)
plots.append(p)

p = figure(title="diamond_cross")
p.scatter(x, y, marker="diamond_cross", size=sizes, color="#386CB0", fill_color=None, line_width=2)
plots.append(p)

p = figure(title="circle_cross")
p.scatter(x, y, marker="circle_cross", size=sizes, color="#FB8072", fill_color=None, line_width=2)
plots.append(p)

show(vplot(*plots))  # open a browser
コード例 #34
0
def queries_dashboard(response):
    table = VBox(children=[queries_table(response)])
    plot = VBox(children=[queries_plot(response)])
    return components(vplot(HBox(children=[table, plot])))
コード例 #35
0
ファイル: plot.py プロジェクト: CaptainAL/Spyder
    def initialize_plot(self, ranges=None):
        ranges = self.compute_ranges(self.layout, self.keys[-1], None)
        plots = [[] for i in range(self.rows)]
        passed_plots = []
        tab_titles = {}
        insert_rows, insert_cols = [], []
        adjoined = False
        for r, c in self.coords:
            subplot = self.subplots.get((r, c), None)
            if subplot is not None:
                shared_plots = passed_plots if self.shared_axes else None
                subplots = subplot.initialize_plot(ranges=ranges, plots=shared_plots)

                # Computes plotting offsets depending on
                # number of adjoined plots
                offset = sum(r >= ir for ir in insert_rows)
                if len(subplots) > 2:
                    adjoined = True
                    # Add pad column in this position
                    insert_cols.append(c)
                    if r not in insert_rows:
                        # Insert and pad marginal row if none exists
                        plots.insert(r+offset, [None for _ in range(len(plots[r]))])
                        # Pad previous rows
                        for ir in range(r):
                            plots[ir].insert(c+1, None)
                        # Add to row offset
                        insert_rows.append(r)
                        offset += 1
                    # Add top marginal
                    plots[r+offset-1] += [subplots.pop(-1), None]
                elif len(subplots) > 1:
                    adjoined = True
                    # Add pad column in this position
                    insert_cols.append(c)
                    # Pad previous rows
                    for ir in range(r):
                        plots[r].insert(c+1, None)
                    # Pad top marginal if one exists
                    if r in insert_rows:
                        plots[r+offset-1] += 2*[None]
                else:
                    # Pad top marginal if one exists
                    if r in insert_rows:
                        plots[r+offset-1] += [None] * (1+(c in insert_cols))
                plots[r+offset] += subplots
                if len(subplots) == 1 and c in insert_cols:
                    plots[r+offset].append(None)
                passed_plots.append(subplots[0])

            if self.tabs:
                if isinstance(self.layout, Layout):
                    tab_titles[r, c] = ' '.join(self.paths[r,c])
                else:
                    dim_vals = zip(self.layout.kdims, self.paths[r, c])
                    tab_titles[r, c] = ', '.join([d.pprint_value_string(k)
                                                  for d, k in dim_vals])

        # Replace None types with empty plots
        # to avoid bokeh bug
        if adjoined:
            plots = layout_padding(plots)

        # Determine the most appropriate composite plot type
        # If the object cannot be displayed in a single layout
        # it will be split into Tabs, for 1-row or 1-column
        # Layouts we use the vplot and hplots.
        # If there is a table and multiple rows and columns
        # everything will be forced to a vertical layout
        if self.tabs:
            panels = [Panel(child=child, title=tab_titles.get(r, c))
                      for r, row in enumerate(plots)
                      for c, child in enumerate(row)
                      if child is not None]
            layout_plot = Tabs(tabs=panels)
        elif len(plots) == 1 and not adjoined:
            layout_plot = vplot(hplot(*plots[0]))
        elif len(plots[0]) == 1:
            layout_plot = vplot(*[p[0] for p in plots])
        else:
            layout_plot = gridplot(plots)

        self.handles['plot'] = layout_plot
        self.handles['plots'] = plots
        self.drawn = True

        return self.handles['plot']
コード例 #36
0
def plot():

    # FIGURES AND X-AXIS
    fig1 = Figure(title = 'Dive Profile',  plot_width = WIDTH, plot_height = HEIGHT, tools = TOOLS)
    fig2 = Figure(title = 'Dive Controls', plot_width = WIDTH, plot_height = HEIGHT, tools = TOOLS, x_range=fig1.x_range)
    fig3 = Figure(title = 'Attitude',      plot_width = WIDTH, plot_height = HEIGHT, tools = TOOLS, x_range=fig1.x_range)
    figs = gridplot([[fig1],[fig2],[fig3]])

    # Formatting x-axis
    timeticks = DatetimeTickFormatter(formats=dict(seconds =["%b%d %H:%M:%S"],
                                                   minutes =["%b%d %H:%M"],
                                                   hourmin =["%b%d %H:%M"],
                                                   hours =["%b%d %H:%M"],
                                                   days  =["%b%d %H:%M"],
                                                   months=["%b%d %H:%M"],
                                                   years =["%b%d %H:%M %Y"]))
    fig1.xaxis.formatter = timeticks
    fig2.xaxis.formatter = timeticks
    fig3.xaxis.formatter = timeticks

    # removing gridlines
    fig1.xgrid.grid_line_color = None
    fig1.ygrid.grid_line_color = None
    fig2.xgrid.grid_line_color = None
    fig2.ygrid.grid_line_color = None
    fig3.xgrid.grid_line_color = None
    fig3.ygrid.grid_line_color = None

    # INPUT WIDGETS
    collection_list = CONN[DB].collection_names(include_system_collections=False)
    gliders = sorted([platformID for platformID in collection_list if len(platformID)>2])
    gliders = Select(title = 'PlatformID', value = gliders[0], options = gliders)
    prev_glider = Button(label = '<')
    next_glider = Button(label = '>')
    glider_controlbox = HBox(children = [gliders, prev_glider, next_glider], height=80)

    chunkations = Select(title = 'Chunkation', value = 'segment', options = ['segment', '24hr', '30days', '-ALL-'])
    chunk_indicator = TextInput(title = 'index', value = '0')
    prev_chunk = Button(label = '<')
    next_chunk = Button(label = '>')
    chunk_ID   = PreText(height=80)
    chunk_controlbox = HBox(chunkations,
                            HBox(chunk_indicator, width=25),
                            prev_chunk, next_chunk,
                            chunk_ID,
                            height = 80)

    control_box = HBox(glider_controlbox,
                        chunk_controlbox)

    # DATA VARS
    deadby_date = ''
    depth    = ColumnDataSource(dict(x=[],y=[]))
    vert_vel = ColumnDataSource(dict(x=[],y=[]))

    mbpump   = ColumnDataSource(dict(x=[],y=[]))
    battpos  = ColumnDataSource(dict(x=[],y=[]))
    pitch    = ColumnDataSource(dict(x=[],y=[]))

    mfin      = ColumnDataSource(dict(x=[],y=[]))
    cfin      = ColumnDataSource(dict(x=[],y=[]))
    mroll     = ColumnDataSource(dict(x=[],y=[]))
    mheading = ColumnDataSource(dict(x=[],y=[]))
    cheading = ColumnDataSource(dict(x=[],y=[]))

    # AXIS setup
    colors = COLORS[:]

    fig1.y_range.flipped = True
    fig1.yaxis.axis_label = 'm_depth (m)'
    fig1.extra_y_ranges = {'vert_vel': Range1d(start=-50, end=50),
                           'dummy':    Range1d(start=0, end=100)}
    fig1.add_layout(place = 'right',
                    obj = LinearAxis(y_range_name = 'vert_vel',
                                     axis_label   = 'vertical velocity (cm/s)'))
    fig1.add_layout(place = 'left',
                    obj = LinearAxis(y_range_name = 'dummy',
                                     axis_label   = ' '))
    fig1.yaxis[1].visible = False
    fig1.yaxis[1].axis_line_alpha = 0
    fig1.yaxis[1].major_label_text_alpha = 0
    fig1.yaxis[1].major_tick_line_alpha = 0
    fig1.yaxis[1].minor_tick_line_alpha = 0


    fig2.yaxis.axis_label = 'pitch (deg)'
    fig2.y_range.start, fig2.y_range.end = -40,40
    fig2.extra_y_ranges = {'battpos': Range1d(start=-1, end = 1),
                           'bpump':   Range1d(start=-275, end=275)}
    fig2.add_layout(place = 'right',
                    obj = LinearAxis(y_range_name = 'battpos',
                                     axis_label = 'battpos (in)'))
    fig2.add_layout(place = 'left',
                    obj = LinearAxis(y_range_name = 'bpump',
                                     axis_label   = 'bpump (cc)'))
    fig2.yaxis[1].visible = False # necessary for spacing. later gets set to true


    fig3.yaxis.axis_label = 'fin/roll (deg)'
    fig3.y_range.start, fig3.y_range.end = -30, 30
    fig3.extra_y_ranges = {'heading': Range1d(start=0, end=360), #TODO dynamic avg centering
                           'dummy':   Range1d(start=0, end=100)}
    fig3.add_layout(place = 'right',
                    obj = LinearAxis(y_range_name = 'heading',
                                     axis_label   = 'headings (deg)'))
    fig3.add_layout(place = 'left',
                    obj = LinearAxis(y_range_name = 'dummy',
                                     axis_label   = ' '))
    fig3.yaxis[1].visible = False
    fig3.yaxis[1].axis_line_alpha = 0
    fig3.yaxis[1].major_label_text_alpha = 0
    fig3.yaxis[1].major_tick_line_alpha = 0
    fig3.yaxis[1].minor_tick_line_alpha = 0

    # PLOT OBJECTS
    fig1.line(  'x', 'y', source = depth,    legend = 'm_depth',     color = 'red')
    fig1.circle('x', 'y', source = depth,    legend = 'm_depth',     color = 'red')
    fig1.line(  'x', 'y', source = vert_vel, legend = 'vert_vel',    color = 'green',     y_range_name = 'vert_vel')
    fig1.circle('x', 'y', source = vert_vel, legend = 'vert_vel',    color = 'green',     y_range_name = 'vert_vel')
    fig1.renderers.append(Span(location = 0, dimension = 'width',    y_range_name = 'vert_vel',
                               line_color= 'green', line_dash='dashed', line_width=1))

    fig2.line(  'x', 'y', source = pitch,   legend = "m_pitch",    color = 'indigo')
    fig2.circle('x', 'y', source = pitch,   legend = "m_pitch",    color = 'indigo')
    fig2.line(  'x', 'y', source = battpos, legend = 'm_battpos',  color = 'magenta',   y_range_name = 'battpos')
    fig2.circle('x', 'y', source = battpos, legend = 'm_battpos',  color = 'magenta',   y_range_name = 'battpos')
    fig2.line(  'x', 'y', source = mbpump,  legend = "m_'bpump'",  color = 'blue',      y_range_name = 'bpump')
    fig2.circle('x', 'y', source = mbpump,  legend = "m_'bpump'",  color = 'blue',      y_range_name = 'bpump')
    fig2.renderers.append(Span(location = 0, dimension = 'width',
                               line_color= 'black', line_dash='dashed', line_width=1))
    fig3.line(  'x', 'y', source = mfin,       legend = 'm_fin',     color = 'cyan')
    fig3.circle('x', 'y', source = mfin,       legend = 'm_fin',     color = 'cyan')
    fig3.line(  'x', 'y', source = cfin,       legend = 'c_fin',     color = 'orange')
    fig3.circle('x', 'y', source = cfin,       legend = 'c_fin',     color = 'orange')
    fig3.line(  'x', 'y', source = mroll,      legend = 'm_roll',    color = 'magenta')
    fig3.circle('x', 'y', source = mroll,      legend = 'm_roll',    color = 'magenta')
    fig3.line(  'x', 'y', source = mheading,   legend = 'm_heading', color = 'blue',    y_range_name = 'heading')
    fig3.circle('x', 'y', source = mheading,   legend = 'm_heading', color = 'blue',    y_range_name = 'heading')
    fig3.line(  'x', 'y', source = cheading,   legend = 'c_heading', color = 'indigo',  y_range_name = 'heading')
    fig3.circle('x', 'y', source = cheading,   legend = 'c_heading', color = 'indigo',  y_range_name = 'heading')
    fig3.renderers.append(Span(location = 0, dimension = 'width',    y_range_name = 'default',
                               line_color= 'black', line_dash='dashed', line_width=1))

    # CALLBACK FUNCS
    def update_data(attrib,old,new):
        g = gliders.value
        chnk = chunkations.value
        chindex = abs(int(chunk_indicator.value))

        depth.data    = dict(x=[],y=[])
        vert_vel.data = dict(x=[],y=[])
        mbpump.data   = dict(x=[],y=[])
        battpos.data  = dict(x=[],y=[])
        pitch.data    = dict(x=[],y=[])

        mfin.data     = dict(x=[],y=[])
        cfin.data     = dict(x=[],y=[])
        mroll.data    = dict(x=[],y=[])
        mheading.data = dict(x=[],y=[])
        cheading.data = dict(x=[],y=[])


        depth.data,startend   = load_sensor(g, 'm_depth', chnk, chindex)

        if chnk == 'segment':
            xbd = startend[2]
            chunk_ID.text = '{} {} \n{} ({}) \nSTART: {} \nEND:   {}'.format(g, xbd['mission'],
                                                                             xbd['onboard_filename'], xbd['the8x3_filename'],
                                                                             e2ts(xbd['start']), e2ts(xbd['end']))
            if len(set(depth.data['x']))<=1 and attrib == 'chunk':
                if old > new:
                    next_chunk.clicks += 1
                else:
                    prev_chunk.clicks += 1
                return
            elif len(set(depth.data['x']))<=1 and chunk_indicator.value == 0:
                chunk_indicator.value = 1

        elif chnk in ['24hr', '30days']:
            chunk_ID.text = '{} \nSTART: {} \nEND:   {}'.format(g, e2ts(startend[0]), e2ts(startend[1]))
        elif chnk == '-ALL-':
            chunk_ID.text = '{} \nSTART: {} \nEND:   {}'.format(g,e2ts(depth.data['x'][0] /1000),
                                                                  e2ts(depth.data['x'][-1]/1000))


        vert_vel.data  = calc_vert_vel(depth.data)

        mbpump.data,_     = load_sensor(g, 'm_de_oil_vol', chnk, chindex)
        if len(mbpump.data['x']) > 1:
            #for yax in fig2.select('mbpump'):
            #    yax.legend = 'm_de_oil_vol'
            pass
        else:
            mbpump.data,_     = load_sensor(g, 'm_ballast_pumped', chnk, chindex)
            #for yax in fig2.select('mbpump'):
            #    yax.legend = 'm_ballast_pumped'
        battpos.data,_ = load_sensor(g, 'm_battpos',    chnk, chindex)
        pitch.data,_   = load_sensor(g, 'm_pitch',      chnk, chindex)
        pitch.data['y'] = [math.degrees(y) for y in pitch.data['y']]

        mfin.data,_     = load_sensor(g, 'm_fin',     chnk, chindex)
        cfin.data,_     = load_sensor(g, 'c_fin',     chnk, chindex)
        mroll.data,_    = load_sensor(g, 'm_roll',    chnk, chindex)
        mheading.data,_ = load_sensor(g, 'm_heading', chnk, chindex)
        cheading.data,_ = load_sensor(g, 'c_heading', chnk, chindex)
        mfin.data['y']     = [math.degrees(y) for y in mfin.data['y']]
        cfin.data['y']     = [math.degrees(y) for y in cfin.data['y']]
        mheading.data['y'] = [math.degrees(y) for y in mheading.data['y']]
        cheading.data['y'] = [math.degrees(y) for y in cheading.data['y']]
        mroll.data['y']    = [math.degrees(y) for y in mroll.data['y']]

        fig1.yaxis[1].visible = True
        fig2.yaxis[1].visible = True
        fig3.yaxis[1].visible = True


    #GLIDER SELECTS
    def glider_buttons(increment):
        ops = gliders.options
        new_index = ops.index(gliders.value) + increment
        if new_index >= len(ops):
            new_index = 0
        elif new_index < 0:
            new_index = len(ops)-1
        gliders.value = ops[new_index]
        chunkation_update(None, None, None) #reset chunk indicator and clicks
    def next_glider_func():
        glider_buttons(1)
    def prev_glider_func():
        glider_buttons(-1)
    def update_glider(attrib,old,new):
        chunk_indicator.value = '0'
        #update_data(None,None,None)


    gliders.on_change('value', update_glider)
    next_glider.on_click(next_glider_func)
    prev_glider.on_click(prev_glider_func)


        #CHUNK SELECTS
    def chunkation_update(attrib,old,new):
        chunk_indicator.value = '0'
        prev_chunk.clicks = 0
        next_chunk.clicks = 0
        update_data(None,None,None)
        if new == '-ALL-':
            chunk_indicator.value = '-'

    def chunk_func():
        chunkdiff = prev_chunk.clicks - next_chunk.clicks
        if chunkdiff < 0:
            prev_chunk.clicks = 0
            next_chunk.clicks = 0
            chunkdiff = 0
        print (chunkdiff)
        chunk_indicator.value = str(chunkdiff)

    def chunk_indicator_update(attrib,old,new):
        try:
            if abs(int(old)-int(new))>1: #manual update, triggers new non-manual indicator update, ie else clause below
                prev_chunk.clicks = int(new)
                next_chunk.clicks = 0
            else:
                update_data('chunk',int(old),int(new))
            print("UPDATE", old, new)
        except Exception as e:
            print(type(e),e, old, new)

    chunkations.on_change('value', chunkation_update)
    chunk_indicator.on_change('value', chunk_indicator_update)
    next_chunk.on_click(chunk_func)
    prev_chunk.on_click(chunk_func)

    update_data(None,None,None)

    return vplot(control_box, figs)
コード例 #37
0
p.scatter(x,
          y,
          marker="square_cross",
          size=sizes,
          color="#7FC97F",
          fill_color=None,
          line_width=2)
plots.append(p)

p = figure(title="diamond_cross")
p.scatter(x,
          y,
          marker="diamond_cross",
          size=sizes,
          color="#386CB0",
          fill_color=None,
          line_width=2)
plots.append(p)

p = figure(title="circle_cross")
p.scatter(x,
          y,
          marker="circle_cross",
          size=sizes,
          color="#FB8072",
          fill_color=None,
          line_width=2)
plots.append(p)

show(vplot(*plots))  # open a browser
コード例 #38
0
ファイル: plot.py プロジェクト: gyenney/Tools
    def initialize_plot(self, ranges=None):
        ranges = self.compute_ranges(self.layout, self.keys[-1], None)
        plots = [[] for i in range(self.rows)]
        passed_plots = []
        tab_titles = {}
        insert_rows, insert_cols = [], []
        adjoined = False
        for r, c in self.coords:
            subplot = self.subplots.get((r, c), None)
            if subplot is not None:
                shared_plots = passed_plots if self.shared_axes else None
                subplots = subplot.initialize_plot(ranges=ranges,
                                                   plots=shared_plots)

                # Computes plotting offsets depending on
                # number of adjoined plots
                offset = sum(r >= ir for ir in insert_rows)
                if len(subplots) > 2:
                    adjoined = True
                    # Add pad column in this position
                    insert_cols.append(c)
                    if r not in insert_rows:
                        # Insert and pad marginal row if none exists
                        plots.insert(r + offset,
                                     [None for _ in range(len(plots[r]))])
                        # Pad previous rows
                        for ir in range(r):
                            plots[ir].insert(c + 1, None)
                        # Add to row offset
                        insert_rows.append(r)
                        offset += 1
                    # Add top marginal
                    plots[r + offset - 1] += [subplots.pop(-1), None]
                elif len(subplots) > 1:
                    adjoined = True
                    # Add pad column in this position
                    insert_cols.append(c)
                    # Pad previous rows
                    for ir in range(r):
                        plots[r].insert(c + 1, None)
                    # Pad top marginal if one exists
                    if r in insert_rows:
                        plots[r + offset - 1] += 2 * [None]
                else:
                    # Pad top marginal if one exists
                    if r in insert_rows:
                        plots[r + offset - 1] += [None] * (1 +
                                                           (c in insert_cols))
                plots[r + offset] += subplots
                if len(subplots) == 1 and c in insert_cols:
                    plots[r + offset].append(None)
                passed_plots.append(subplots[0])

            if self.tabs:
                if isinstance(self.layout, Layout):
                    tab_titles[r, c] = ' '.join(self.paths[r, c])
                else:
                    dim_vals = zip(self.layout.kdims, self.paths[r, c])
                    tab_titles[r, c] = ', '.join(
                        [d.pprint_value_string(k) for d, k in dim_vals])

        # Replace None types with empty plots
        # to avoid bokeh bug
        if adjoined:
            plots = layout_padding(plots)

        # Determine the most appropriate composite plot type
        # If the object cannot be displayed in a single layout
        # it will be split into Tabs, for 1-row or 1-column
        # Layouts we use the vplot and hplots.
        # If there is a table and multiple rows and columns
        # everything will be forced to a vertical layout
        if self.tabs:
            panels = [
                Panel(child=child, title=tab_titles.get(r, c))
                for r, row in enumerate(plots) for c, child in enumerate(row)
                if child is not None
            ]
            layout_plot = Tabs(tabs=panels)
        elif len(plots) == 1 and not adjoined:
            layout_plot = vplot(hplot(*plots[0]))
        elif len(plots[0]) == 1:
            layout_plot = vplot(*[p[0] for p in plots])
        else:
            layout_plot = gridplot(plots)

        self.handles['plot'] = layout_plot
        self.handles['plots'] = plots
        self.drawn = True

        return self.handles['plot']
コード例 #39
0
    global layout
    global energy_per_capita

    new_df = data_changed(energy_per_capita)
    if new_df is not None:
        energy_per_capita = new_df
        plots_box.children[0] = create_line(energy_per_capita)
        plots_box.children[1] = create_bar(energy_per_capita)


line = create_line(energy_per_capita)
bar = create_bar(energy_per_capita)
desc1 = Paragraph(text="""
This example shows live integration between bokeh server and Excel using
XLWings.""")
desc2 = Paragraph(text="""
*** YOU MUST HAVE EXCEL and XLWINGS INSTALLED ON YOUR MACHINE FOR IT TO WORK ***
""")
desc3 = Paragraph(text="""
It opens this plots window and an excel spreadsheet instance with the
values being plotted. When user changes the values on the excel spreadsheet
the plots will be updated accordingly. It's not required to save the spreadsheet for the plots to update.
""")
plots_box = hplot(line, bar)
layout = vplot(desc1, desc2, desc3, plots_box)
curdoc().add_root(layout)
curdoc().add_periodic_callback(update, 500)

session.show()  # open the document in a browser
session.loop_until_closed()  # run forever
コード例 #40
0
def run_chart(exchange, asset, limit):
    client = pymongo.MongoClient()
    db = client['bitpredict_' + exchange]
    collection = db[asset_ + '_predictions']

    def get_data():
        cursor = collection.find().limit(limit).sort('_id', pymongo.DESCENDING)
        data = pd.DataFrame(list(cursor))
        data = data.set_index('_id')
        data = data.sort_index(ascending=True)
        timestamps = pd.to_datetime(data.index, unit='s').to_series()
        prices = data.price
        predictions = data.prediction * 10000
        returns = (data.position * data.change).cumsum() * 10000
        return timestamps, prices, predictions, returns

    timestamps, prices, predictions, returns = get_data()
    output_server('bitpredict_' + exchange + '_extended')

    background = '#f2f2f2'
    ylabel_standoff = 0
    xformatter = DatetimeTickFormatter(formats=dict(hours=["%H:%M"]))
    yformatter = PrintfTickFormatter(format="%8.1f")
    p1 = figure(title=None,
                plot_width=750,
                plot_height=300,
                x_axis_type='datetime',
                min_border_top=10,
                min_border_bottom=33,
                background_fill=background,
                tools='',
                toolbar_location=None)
    p1.line(x=timestamps,
            y=prices,
            name='prices',
            color='#4271ae',
            line_width=1,
            legend='Bitcoin Bid/Ask Midpoint',
            line_cap='round',
            line_join='round')
    p1.legend.orientation = 'top_left'
    p1.legend.border_line_color = background
    p1.outline_line_color = None
    p1.xgrid.grid_line_color = 'white'
    p1.ygrid.grid_line_color = 'white'
    p1.axis.axis_line_color = None
    p1.axis.major_tick_line_color = None
    p1.axis.minor_tick_line_color = None
    p1.yaxis.axis_label = 'Price'
    p1.yaxis.axis_label_standoff = ylabel_standoff
    p1.xaxis.formatter = xformatter
    p1.yaxis.formatter = PrintfTickFormatter(format='%8.2f')
    p1.yaxis.major_label_text_font = 'courier'
    p1.xaxis.major_label_text_font = 'courier'

    p2 = figure(title=None,
                plot_width=750,
                plot_height=295,
                x_axis_type='datetime',
                min_border_top=5,
                min_border_bottom=33,
                background_fill=background,
                tools='',
                toolbar_location=None)
    p2.line(x=timestamps,
            y=predictions,
            name='predictions',
            color='#c82829',
            line_width=1,
            legend='30 Second Prediction',
            line_cap='round',
            line_join='round')
    p2.legend.orientation = 'top_left'
    p2.legend.border_line_color = background
    p2.outline_line_color = None
    p2.xgrid.grid_line_color = 'white'
    p2.ygrid.grid_line_color = 'white'
    p2.axis.axis_line_color = None
    p2.axis.major_tick_line_color = None
    p2.axis.minor_tick_line_color = None
    p2.yaxis.axis_label = 'Basis Points'
    p2.yaxis.axis_label_standoff = ylabel_standoff
    p2.xaxis.formatter = xformatter
    p2.yaxis.formatter = yformatter
    p2.yaxis.major_label_text_font = 'courier'
    p2.xaxis.major_label_text_font = 'courier'
    p2.x_range = p1.x_range

    p3 = figure(title=None,
                plot_width=750,
                plot_height=320,
                x_axis_type='datetime',
                min_border_top=5,
                min_border_bottom=10,
                background_fill=background,
                x_axis_label='Greenwich Mean Time',
                tools='',
                toolbar_location=None)
    p3.line(x=timestamps,
            y=returns,
            name='returns',
            color='#8959a8',
            line_width=1,
            legend='Cumulative Return',
            line_cap='round',
            line_join='round')
    p3.legend.orientation = 'top_left'
    p3.legend.border_line_color = background
    p3.outline_line_color = None
    p3.xgrid.grid_line_color = 'white'
    p3.ygrid.grid_line_color = 'white'
    p3.axis.axis_line_color = None
    p3.axis.major_tick_line_color = None
    p3.axis.minor_tick_line_color = None
    p3.yaxis.axis_label = 'Basis Points'
    p3.yaxis.axis_label_standoff = ylabel_standoff
    p3.xaxis.formatter = xformatter
    p3.yaxis.formatter = yformatter
    p3.xaxis.axis_label_standoff = 12
    p3.yaxis.major_label_text_font = 'courier'
    p3.xaxis.major_label_text_font = 'courier'
    p3.x_range = p1.x_range

    vp = vplot(p1, p2, p3)
    push()
    ip = load(urlopen('http://jsonip.com'))['ip']
    ssn = cursession()
    ssn.publish()
    embed.autoload_server(vp, ssn, public=True)

    renderer = p1.select(dict(name='prices'))
    ds_prices = renderer[0].data_source
    renderer = p2.select(dict(name='predictions'))
    ds_predictions = renderer[0].data_source
    renderer = p3.select(dict(name='returns'))
    ds_returns = renderer[0].data_source

    while True:
        timestamps, prices, predictions, returns = get_data(exchange, limit)
        ds_prices.data['x'] = timestamps
        ds_predictions.data['x'] = timestamps
        ds_returns.data['x'] = timestamps
        ds_prices.data['y'] = prices
        ds_predictions.data['y'] = predictions
        ds_returns.data['y'] = returns
        ssn.store_objects(ds_prices)
        ssn.store_objects(ds_predictions)
        ssn.store_objects(ds_returns)
        time.sleep(60)
コード例 #41
0
                  end=date(2004, 12, 31),
                  bounds=(date(2001, 1, 1), date(2006, 12, 31)))
y_range = Range1d(start=00, end=40, bounds=(10, 60))
y_range_extra = Range1d(start=300, end=700, bounds=(200, 1000))
###### -- end -- ########

plot_extra = figure(
    x_axis_type="datetime",
    x_range=x_range,
    y_range=y_range,
    title=
    "Multiple ranges x:(2001/1/1, 2006/12/31), y1:(10, 60), y2:(200, 1000)")
plot_extra.line(x, apple_y, color='lightblue')
plot_extra.extra_y_ranges = {'goog': y_range_extra}
plot_extra.line(x, google_y, color='pink', y_range_name='goog')
plot_extra.add_layout(
    LinearAxis(y_range_name="goog", major_label_text_color='pink'), 'left')

# Tweak the formats to make it all readable
plots = [
    plot_datarange, plot_range, plot_range_un, plot_range_rev,
    plot_cat_autobounded, plot_cat_unbounded, plot_cat_bounded, plot_extra
]
for plot in plots:
    plot.title_text_font_size = '12pt'

show(
    vplot(plot_datarange, hplot(plot_range, plot_range_un, plot_range_rev),
          hplot(plot_cat_autobounded, plot_cat_unbounded, plot_cat_bounded),
          plot_extra))
コード例 #42
0
        data['x'] = [];
        data['y'] = [];
    }
    else {
        if (mode == 'Linear') { interp = linear; }
        else if (mode == 'Step (before)') { interp = step; step.set('mode', 'before'); }
        else if (mode == 'Step (center)') { interp = step; step.set('mode', 'center'); }
        else if (mode == 'Step (after)')  { interp = step; step.set('mode', 'after');  }

        for (i=0; i < %d; i++) {
            data['x'][i] = i * dx
            data['y'][i] = interp.compute(data['x'][i])
        }
    }

    source.trigger('change')

""" % (N, N))

mode = Select(title='Interpolation Mode',
              value='None',
              options=[
                  'None', 'Linear', 'Step (before)', 'Step (center)',
                  'Step (after)'
              ],
              callback=callback)

output_file("transform_interpolator.html", title="Example Transforms")

show(vplot(hplot(mode), p))
コード例 #43
0
    def create(self):
        manufacturers = sorted(mpg["manufacturer"].unique())
        models = sorted(mpg["model"].unique())
        transmissions = sorted(mpg["trans"].unique())
        drives = sorted(mpg["drv"].unique())
        classes = sorted(mpg["class"].unique())

        manufacturer_select = Select(title="Manufacturer:", value="All", options=["All"] + manufacturers)
        manufacturer_select.on_change('value', self.on_manufacturer_change)
        model_select = Select(title="Model:", value="All", options=["All"] + models)
        model_select.on_change('value', self.on_model_change)
        transmission_select = Select(title="Transmission:", value="All", options=["All"] + transmissions)
        transmission_select.on_change('value', self.on_transmission_change)
        drive_select = Select(title="Drive:", value="All", options=["All"] + drives)
        drive_select.on_change('value', self.on_drive_change)
        class_select = Select(title="Class:", value="All", options=["All"] + classes)
        class_select.on_change('value', self.on_class_change)

        columns = [
            TableColumn(field="manufacturer", title="Manufacturer", editor=SelectEditor(options=manufacturers), formatter=StringFormatter(font_style="bold")),
            TableColumn(field="model",        title="Model",        editor=StringEditor(completions=models)),
            TableColumn(field="displ",        title="Displacement", editor=NumberEditor(step=0.1),              formatter=NumberFormatter(format="0.0")),
            TableColumn(field="year",         title="Year",         editor=IntEditor()),
            TableColumn(field="cyl",          title="Cylinders",    editor=IntEditor()),
            TableColumn(field="trans",        title="Transmission", editor=SelectEditor(options=transmissions)),
            TableColumn(field="drv",          title="Drive",        editor=SelectEditor(options=drives)),
            TableColumn(field="class",        title="Class",        editor=SelectEditor(options=classes)),
            TableColumn(field="cty",          title="City MPG",     editor=IntEditor()),
            TableColumn(field="hwy",          title="Highway MPG",  editor=IntEditor()),
        ]
        data_table = DataTable(source=self.source, columns=columns, editable=True)

        plot = Plot(title=None, x_range= DataRange1d(), y_range=DataRange1d(), plot_width=1000, plot_height=300)

        # Set up x & y axis
        plot.add_layout(LinearAxis(), 'below')
        yaxis = LinearAxis()
        plot.add_layout(yaxis, 'left')
        plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker))

        # Add Glyphs
        cty_glyph = Circle(x="index", y="cty", fill_color="#396285", size=8, fill_alpha=0.5, line_alpha=0.5)
        hwy_glyph = Circle(x="index", y="hwy", fill_color="#CE603D", size=8, fill_alpha=0.5, line_alpha=0.5)
        cty = plot.add_glyph(self.source, cty_glyph)
        hwy = plot.add_glyph(self.source, hwy_glyph)

        # Add the tools
        tooltips = [
            ("Manufacturer", "@manufacturer"),
            ("Model", "@model"),
            ("Displacement", "@displ"),
            ("Year", "@year"),
            ("Cylinders", "@cyl"),
            ("Transmission", "@trans"),
            ("Drive", "@drv"),
            ("Class", "@class"),
        ]
        cty_hover_tool = HoverTool(renderers=[cty], tooltips=tooltips + [("City MPG", "@cty")])
        hwy_hover_tool = HoverTool(renderers=[hwy], tooltips=tooltips + [("Highway MPG", "@hwy")])
        select_tool = BoxSelectTool(renderers=[cty, hwy], dimensions=['width'])
        plot.add_tools(cty_hover_tool, hwy_hover_tool, select_tool)


        controls = vplot(manufacturer_select, model_select, transmission_select, drive_select, class_select)
        top_panel = hplot(controls, plot)
        layout = vplot(top_panel, data_table)

        return layout
コード例 #44
0
ファイル: interactive_excel.py プロジェクト: deolsen/bokeh
def update():
    global layout
    global energy_per_capita

    new_df = data_changed(energy_per_capita)
    if new_df is not None:
        energy_per_capita = new_df
        plots_box.children[0] = create_line(energy_per_capita)
        plots_box.children[1] = create_bar(energy_per_capita)

line = create_line(energy_per_capita)
bar = create_bar(energy_per_capita)
desc1 = Paragraph(text="""
This example shows live integration between bokeh server and Excel using
XLWings.""")
desc2 = Paragraph(text="""
*** YOU MUST HAVE EXCEL and XLWINGS INSTALLED ON YOUR MACHINE FOR IT TO WORK ***
""")
desc3 = Paragraph(text="""
It opens this plots window and an excel spreadsheet instance with the
values being plotted. When user changes the values on the excel spreadsheet
the plots will be updated accordingly. It's not required to save the spreadsheet for the plots to update.
""")
plots_box = hplot(line, bar)
layout = vplot(desc1, desc2, desc3, plots_box)
curdoc().add_root(layout)
curdoc().add_periodic_callback(update, 500)

session.show() # open the document in a browser
session.loop_until_closed() # run forever
コード例 #45
0
ファイル: layout_vertical.py プロジェクト: zlxs23/bokeh
from bokeh.io import output_file, show, vplot
from bokeh.plotting import figure

output_file("layout.html")

x = list(range(11))
y0 = x
y1 = [10 - i for i in x]
y2 = [abs(i - 5) for i in x]

# create a new plot
s1 = figure(width=250, plot_height=250, title=None)
s1.circle(x, y0, size=10, color="navy", alpha=0.5)

# create another one
s2 = figure(width=250, height=250, title=None)
s2.triangle(x, y1, size=10, color="firebrick", alpha=0.5)

# create and another
s3 = figure(width=250, height=250, title=None)
s3.square(x, y2, size=10, color="olive", alpha=0.5)

# put all the plots in a VBox
p = vplot(s1, s2, s3)

# show the results
show(p)
コード例 #46
0
def make_patches_plot(x_range, y_range, source):
    with make_plot(x_range, y_range, source) as plot:
        glyph = Patches(xs='xs', ys='ys', fill_color='value', fill_alpha=0.8, line_color='#CCCCCC', line_alpha=0.8)
        plot.add_glyph(source, glyph)
    return plot


def make_multiline_plot(x_range, y_range, source):
    with make_plot(x_range, y_range, source) as plot:
        glyph = MultiLine(xs='xs', ys='ys', line_color='value', line_width=5, line_alpha=0.8)
        plot.add_glyph(source, glyph)
    return plot

patch = make_patch_plot(Range1d(2010, 2013), Range1d(0, 5), patch_data)
line = make_line_plot(Range1d(2010, 2013), Range1d(0, 5), patch_data)

patches = make_patches_plot(Range1d(-5, 10), Range1d(-5, 10), patches_data)
multiline = make_multiline_plot(Range1d(-5, 10), Range1d(-5, 10), patches_data)

patch_with_hole = make_patch_plot(Range1d(2010, 2017), Range1d(0, 5), patch_with_hole_data)
line_with_hole = make_line_plot(Range1d(2010, 2016), Range1d(0, 5), patch_with_hole_data)

patches_with_hole = make_patches_plot(Range1d(-5, 10), Range1d(-5, 10), patches_with_hole_data)
multiline_with_hole = make_multiline_plot(Range1d(-5, 10), Range1d(-5, 10), patches_with_hole_data)

show(vplot(
    patch, line, patches, multiline,
    patches_with_hole, line_with_hole, patches_with_hole, multiline_with_hole
))
コード例 #47
0
    def do_plot(self, inputDir, plotOutDir, plotOutFileName, simDataFile,
                validationDataFile, metadata):
        if metadata["variant"] != "tfActivity":
            print "This plot only runs for the 'tfActivity' variant."
            return

        if not os.path.isdir(inputDir):
            raise Exception, "inputDir does not currently exist as a directory"

        ap = AnalysisPaths(inputDir, variant_plot=True)
        variants = sorted(ap._path_data['variant'].tolist()
                          )  # Sorry for accessing private data

        if 0 in variants:
            variants.remove(0)

        if len(variants) == 0:
            return

        all_cells = sorted(
            ap.get_cells(variant=variants, seed=[0], generation=[0]))

        if not os.path.exists(plotOutDir):
            os.mkdir(plotOutDir)

        expectedProbBound = []
        simulatedProbBound = []
        expectedSynthProb = []
        simulatedSynthProb = []
        targetId = []
        targetCondition = []
        targetToTfType = {}

        for variant, simDir in zip(variants, all_cells):
            sim_data = cPickle.load(open(ap.get_variant_kb(variant), "rb"))

            shape = sim_data.process.transcription_regulation.recruitmentData[
                "shape"]
            hI = sim_data.process.transcription_regulation.recruitmentData[
                "hI"]
            hJ = sim_data.process.transcription_regulation.recruitmentData[
                "hJ"]
            hV = sim_data.process.transcription_regulation.recruitmentData[
                "hV"]
            H = np.zeros(shape, np.float64)
            H[hI, hJ] = hV
            colNames = sim_data.process.transcription_regulation.recruitmentColNames

            tfList = ["basal (no TF)"] + sorted(
                sim_data.tfToActiveInactiveConds)
            simOutDir = os.path.join(simDir, "simOut")
            tf = tfList[(variant + 1) // 2]
            tfStatus = None
            if variant % 2 == 1:
                tfStatus = "active"
            else:
                tfStatus = "inactive"

            bulkMoleculesReader = TableReader(
                os.path.join(simOutDir, "BulkMolecules"))
            bulkMoleculeIds = bulkMoleculesReader.readAttribute("objectNames")

            rnaSynthProbReader = TableReader(
                os.path.join(simOutDir, "RnaSynthProb"))
            rnaIds = rnaSynthProbReader.readAttribute("rnaIds")

            tfTargetBoundIds = []
            tfTargetBoundIndices = []
            tfTargetSynthProbIds = []
            tfTargetSynthProbIndices = []
            for tfTarget in sorted(sim_data.tfToFC[tf]):
                tfTargetBoundIds.append(tfTarget + "__" + tf)
                tfTargetBoundIndices.append(
                    bulkMoleculeIds.index(tfTargetBoundIds[-1]))
                tfTargetSynthProbIds.append(tfTarget + "[c]")
                tfTargetSynthProbIndices.append(
                    rnaIds.index(tfTargetSynthProbIds[-1]))
            tfTargetBoundCountsAll = bulkMoleculesReader.readColumn(
                "counts")[:, tfTargetBoundIndices]
            tfTargetSynthProbAll = rnaSynthProbReader.readColumn(
                "rnaSynthProb")[:, tfTargetSynthProbIndices]

            for targetIdx, tfTarget in enumerate(sorted(sim_data.tfToFC[tf])):
                tfTargetBoundCounts = tfTargetBoundCountsAll[:,
                                                             targetIdx].reshape(
                                                                 -1)

                expectedProbBound.append(sim_data.pPromoterBound[tf + "__" +
                                                                 tfStatus][tf])
                simulatedProbBound.append(tfTargetBoundCounts[5:].mean())

                tfTargetSynthProbId = [tfTarget + "[c]"]
                tfTargetSynthProbIndex = np.array(
                    [rnaIds.index(x) for x in tfTargetSynthProbId])
                tfTargetSynthProb = tfTargetSynthProbAll[:,
                                                         targetIdx].reshape(-1)

                rnaIdx = np.where(
                    sim_data.process.transcription.rnaData["id"] == tfTarget +
                    "[c]")[0][0]
                regulatingTfIdxs = np.where(H[rnaIdx, :])

                for i in regulatingTfIdxs[0]:
                    if colNames[i].split("__")[1] != "alpha":
                        if tfTarget not in targetToTfType:
                            targetToTfType[tfTarget] = []
                        targetToTfType[tfTarget].append(
                            sim_data.process.transcription_regulation.
                            tfToTfType[colNames[i].split("__")[1]])

                expectedSynthProb.append(
                    sim_data.process.transcription.rnaSynthProb[
                        tf + "__" + tfStatus][rnaIdx])
                simulatedSynthProb.append(tfTargetSynthProb[5:].mean())

                targetId.append(tfTarget)
                targetCondition.append(tf + "__" + tfStatus)

            bulkMoleculesReader.close()
            rnaSynthProbReader.close()

        expectedProbBound = np.array(expectedProbBound)
        simulatedProbBound = np.array(simulatedProbBound)
        expectedSynthProb = np.array(expectedSynthProb)
        simulatedSynthProb = np.array(simulatedSynthProb)

        regressionResult = scipy.stats.linregress(
            np.log10(expectedProbBound[expectedProbBound > NUMERICAL_ZERO]),
            np.log10(simulatedProbBound[expectedProbBound > NUMERICAL_ZERO]))
        regressionResultLargeValues = scipy.stats.linregress(
            np.log10(expectedProbBound[expectedProbBound > 1e-2]),
            np.log10(simulatedProbBound[expectedProbBound > 1e-2]))

        ax = plt.subplot(2, 1, 1)
        ax.scatter(np.log10(expectedProbBound), np.log10(simulatedProbBound))
        plt.xlabel("log10(Expected probability bound)", fontsize=6)
        plt.ylabel("log10(Simulated probability bound)", fontsize=6)
        plt.title(
            "Slope: %0.3f   Intercept: %0.3e      (Without Small Values:  Slope: %0.3f Intercept: %0.3e)"
            % (regressionResult.slope, regressionResult.intercept,
               regressionResultLargeValues.slope,
               regressionResultLargeValues.intercept),
            fontsize=6)
        ax.tick_params(which='both', direction='out', labelsize=6)

        regressionResult = scipy.stats.linregress(
            np.log10(expectedSynthProb[expectedSynthProb > NUMERICAL_ZERO]),
            np.log10(simulatedSynthProb[expectedSynthProb > NUMERICAL_ZERO]))

        ax = plt.subplot(2, 1, 2)
        ax.scatter(np.log10(expectedSynthProb), np.log10(simulatedSynthProb))
        plt.xlabel("log10(Expected synthesis probability)", fontsize=6)
        plt.ylabel("log10(Simulated synthesis probability)", fontsize=6)
        plt.title("Slope: %0.3f   Intercept: %0.3e" %
                  (regressionResult.slope, regressionResult.intercept),
                  fontsize=6)
        ax.tick_params(which='both', direction='out', labelsize=6)

        plt.tight_layout()

        exportFigure(plt, plotOutDir, plotOutFileName, metadata)
        plt.close("all")

        # Probability bound - hover for ID
        source1 = ColumnDataSource(data=dict(x=np.log10(expectedProbBound),
                                             y=np.log10(simulatedProbBound),
                                             ID=targetId,
                                             condition=targetCondition))
        hover1 = HoverTool(tooltips=[("ID", "@ID"), ("condition",
                                                     "@condition")])
        tools1 = [
            hover1,
            BoxZoomTool(),
            LassoSelectTool(),
            PanTool(),
            WheelZoomTool(),
            ResizeTool(),
            UndoTool(),
            RedoTool(), "reset"
        ]
        s1 = figure(x_axis_label="log10(Expected probability bound)",
                    y_axis_label="log10(Simulated probability bound)",
                    width=800,
                    height=500,
                    tools=tools1)
        s1.scatter("x", "y", source=source1)

        if not os.path.exists(os.path.join(plotOutDir, "html_plots")):
            os.makedirs(os.path.join(plotOutDir, "html_plots"))
        bokeh.io.output_file(os.path.join(
            plotOutDir, "html_plots",
            plotOutFileName + "__probBound" + ".html"),
                             title=plotOutFileName,
                             autosave=False)
        bokeh.io.save(s1)

        # Synthesis probability - hover for ID
        source2 = ColumnDataSource(data=dict(x=np.log10(expectedSynthProb),
                                             y=np.log10(simulatedSynthProb),
                                             ID=targetId,
                                             condition=targetCondition))
        hover2 = HoverTool(tooltips=[("ID", "@ID"), ("condition",
                                                     "@condition")])
        tools2 = [
            hover2,
            BoxZoomTool(),
            LassoSelectTool(),
            PanTool(),
            WheelZoomTool(),
            ResizeTool(),
            UndoTool(),
            RedoTool(), "reset"
        ]
        s2 = figure(x_axis_label="log10(Expected synthesis probability)",
                    y_axis_label="log10(Simulated synthesis probability)",
                    width=800,
                    height=500,
                    tools=tools2)
        s2.scatter("x", "y", source=source2)

        bokeh.io.output_file(os.path.join(
            plotOutDir, "html_plots",
            plotOutFileName + "__synthProb" + ".html"),
                             title=plotOutFileName,
                             autosave=False)
        bokeh.io.save(s2)

        # Synthesis probability - filter targets by TF type
        bokeh.io.output_file(os.path.join(
            plotOutDir, "html_plots",
            plotOutFileName + "__synthProb__interactive" + ".html"),
                             title=plotOutFileName,
                             autosave=False)

        tfTypes = []
        for i in targetId:
            if i in targetToTfType:
                uniqueSet = np.unique(targetToTfType[i])

                if uniqueSet.shape[0] == 1:
                    tfTypes.append(uniqueSet[0])
                elif uniqueSet.shape[0] == 3:
                    tfTypes.append("all")
                else:
                    tfTypes.append(uniqueSet[0] + "_" + uniqueSet[1])
            else:
                tfTypes.append("none")
        tfTypes = np.array(tfTypes)

        x0 = np.copy(expectedSynthProb)
        x0[np.where(tfTypes != "0CS")] = np.nan
        x1 = np.copy(expectedSynthProb)
        x1[np.where(tfTypes != "1CS")] = np.nan
        x2 = np.copy(expectedSynthProb)
        x2[np.where(tfTypes != "2CS")] = np.nan
        x01 = np.copy(expectedSynthProb)
        x01[np.where(tfTypes != "0CS_1CS")] = np.nan
        x02 = np.copy(expectedSynthProb)
        x02[np.where(tfTypes != "0CS_2CS")] = np.nan
        x12 = np.copy(expectedSynthProb)
        x12[np.where(tfTypes != "1CS_2CS")] = np.nan

        y0 = np.copy(simulatedSynthProb)
        y0[np.where(tfTypes != "0CS")] = np.nan
        y1 = np.copy(simulatedSynthProb)
        y1[np.where(tfTypes != "1CS")] = np.nan
        y2 = np.copy(simulatedSynthProb)
        y2[np.where(tfTypes != "2CS")] = np.nan
        y01 = np.copy(simulatedSynthProb)
        y01[np.where(tfTypes != "0CS_1CS")] = np.nan
        y02 = np.copy(simulatedSynthProb)
        y02[np.where(tfTypes != "0CS_2CS")] = np.nan
        y12 = np.copy(simulatedSynthProb)
        x12[np.where(tfTypes != "1CS_2CS")] = np.nan

        source_all = ColumnDataSource(data=dict(x=np.log10(expectedSynthProb),
                                                y=np.log10(simulatedSynthProb),
                                                ID=targetId,
                                                condition=targetCondition))
        source_tf = ColumnDataSource(
            data=dict(x0=np.log10(x0),
                      y0=np.log10(y0),
                      x1=np.log10(x1),
                      y1=np.log10(y1),
                      x2=np.log10(x2),
                      y2=np.log10(y2),
                      x01=np.log10(x01),
                      y01=np.log10(y01),
                      x02=np.log10(x02),
                      y02=np.log10(y02),
                      x12=np.log10(x12),
                      y12=np.log10(y12),
                      x123=np.log10(expectedSynthProb),
                      y123=np.log10(simulatedSynthProb),
                      ID=targetId,
                      condition=targetCondition))
        hover3 = HoverTool(tooltips=[("ID", "@ID"), ("condition",
                                                     "@condition")])
        tools3 = [
            hover3,
            BoxZoomTool(),
            LassoSelectTool(),
            PanTool(),
            WheelZoomTool(),
            ResizeTool(),
            UndoTool(),
            RedoTool(), "reset"
        ]

        axis_max = np.ceil(np.log10(expectedSynthProb).max())
        for i in np.sort(expectedSynthProb):
            if i > 0:
                break
        axis_min = np.floor(np.log10(i))
        s3 = figure(
            x_axis_label="log10(Expected synthesis probability)",
            y_axis_label="log10(Simulated synthesis probability)",
            plot_width=800,
            plot_height=500,
            x_range=(axis_min, axis_max),
            y_range=(axis_min, axis_max),
            tools=tools3,
        )
        s3.scatter("x", "y", source=source_all)
        callback = CustomJS(args=dict(source_all=source_all,
                                      source_tf=source_tf),
                            code="""
			var data_all = source_all.get('data');
			var data_tf = source_tf.get('data');
			data_all['x'] = data_tf['x' + cb_obj.get("name")];
			data_all['y'] = data_tf['y' + cb_obj.get("name")];
			source_all.trigger('change');
			""")

        toggle0 = Button(label="0CS", callback=callback, name="0")
        toggle1 = Button(label="1CS", callback=callback, name="1")
        toggle2 = Button(label="2CS", callback=callback, name="2")
        toggle3 = Button(label="0CS and 1CS", callback=callback, name="01")
        toggle4 = Button(label="0CS and 2CS", callback=callback, name="02")
        toggle5 = Button(label="1CS and 2CS", callback=callback, name="12")
        toggle6 = Button(label="All", callback=callback, name="123")
        layout = vplot(toggle0, toggle1, toggle2, toggle3, toggle4, toggle5,
                       toggle6, s3)
        bokeh.io.save(layout)
        bokeh.io.curstate().reset()
コード例 #48
0
ファイル: transform_jitter.py プロジェクト: rohanbapat/bokeh
p.circle(x='xu', y='y', color='navy', source=source, size=5, alpha=0.5)

label_data = ColumnDataSource(data=dict(
    x=[1, 2, 3], y=[10, 10, 10], t=['Original', 'Normal', 'Uniform']))
labels = Label(x='x',
               y='y',
               text='t',
               y_offset=2,
               source=label_data,
               render_mode='css',
               text_align='center')
p.add_annotation(labels)

callback = CustomJS(args=dict(source=source, normal=normal, uniform=uniform),
                    code="""
    data=source.get('data')
    for (i=0; i < data['y'].length; i++) {
        data['xn'][i] = normal.compute(data['x'][i]+1)
    }
    for (i=0; i < data['y'].length; i++) {
        data['xu'][i] = uniform.compute(data['x'][i]+2)
    }
    source.trigger('change')
""")

button = Button(label='Press to apply Jitter!', callback=callback)

output_file("transform_jitter.html", title="Example Jitter Transform")

show(vplot(button, p))
コード例 #49
0
s3.hbar(y = [1,2,3], height=0.5, left = 0, right = stats_deaths, color="#CAB2D6")"""
#vertical_plot = vplot(p,s3)
s3.xaxis.axis_label = 'Estimated Number of Cases (1000)'
#s3.yaxis.axis_label = 'Cancer Type'
s3.title.text_font_size = "25px"

label_opts = dict(
    x=230, y=0,
        x_units='screen', y_units='screen'
        )

msg1 = '(Based on Developed and under developed Region)'                                                   #Subtitle addition hack as it is not supported adding through label for plot: mortality and new cases for breast cancer plot.        
caption1 = Label(text =msg1, **label_opts)
s3.add_layout(caption1, "above")

p = hplot(s1,vplot(s2,s3))

"""p.legend.label_text_font = "times"
p.legend.label_text_font_style = "italic"
p.legend.label_text_color = "navy"""
#show(vertical_plot)
show(p)



#plots = {'Average': s1, "Stages": s2}

#script, div = components(plots)

#print script
#print div
コード例 #50
0
	def makeGraphs(self):

		# create a new plot with a title and axis labels
		heat = figure(title="#CapitalOne Caption Sentiment Heat Map",  
			y_axis_label='Sentiment Percentage (%)', 
			y_range=(-5,105), x_range=(-5,(MAX_COUNT/3)+5))
		heat.axis[0].major_label_text_color = None
		heat.axis[0].ticker.num_minor_ticks = 0

		positiveColor = "#003A6F" # Capital One woodmark color
		neutralColor = "#686868" # Grey neutral color
		negativeColor = "#A12830" # Capital One logo color

		# Create different colored circles based on sentiment
		heat.circle(self.positiveX, self.positiveY, radius=self.positiveRadius, fill_color=positiveColor, fill_alpha=0.5, line_color=None)
		heat.circle(self.neutralX, self.neutralY, radius=self.neutralRadius, fill_color=neutralColor, fill_alpha=0.5, line_color=None)
		heat.circle(self.negativeX, self.negativeY, radius=self.negativeRadius, fill_color=negativeColor, fill_alpha=0.5, line_color=None)

		# Adds sentiment n to n-1 to create a list from 0-1
		captionAvgTemp = {
			'positive': self.captionSentimentAverage['positive'],
			'neutral': self.captionSentimentAverage['neutral']+self.captionSentimentAverage['positive'],
			'negative': self.captionSentimentAverage['negative']+self.captionSentimentAverage['neutral']+self.captionSentimentAverage['positive']
		}
		# Creates slices for pie graphs
		startsCaption = [captionAvgTemp[p]*2*pi for p in captionAvgTemp]
		startsCaption.insert(0,0)
		del startsCaption[-1]
		endsCaption = [captionAvgTemp[p]*2*pi for p in captionAvgTemp]
		colors1 = [positiveColor,neutralColor,negativeColor]
		legend1 = ["Positive", "Neutral", "Negative"]

		#create plot
		captionPie = figure(title="#CapitalOne Caption Sentiment Pie Graph",x_range=(-1,1.5), y_range=(-1,1))

		#create pie chart and legend
		captionPie.wedge(x=.2, y=0, radius=1, start_angle=startsCaption, end_angle=endsCaption, color=colors1)
		captionPie.circle(0,0,radius=0,legend=legend1[0],color=colors1[0])
		captionPie.circle(0,0,radius=0,legend=legend1[1],color=colors1[1])
		captionPie.circle(0,0,radius=0,legend=legend1[2],color=colors1[2])

		# Turn off tick labels
		captionPie.axis.major_label_text_color = None
		# Turn off tick marks
		captionPie.axis.major_tick_line_color = None
		captionPie.axis[0].ticker.num_minor_ticks = 0
		captionPie.axis[1].ticker.num_minor_ticks = 0

		# Each average adds the average before it so the array will be a list containing floats from 0-1
		# This is necessary to make the pie graph
		imageAvgTemp = self.imageSentimentAverage
		prevAvg = ""
		for avg in imageAvgTemp:
			if prevAvg != "":
				imageAvgTemp[avg] += imageAvgTemp[prevAvg]
			prevAvg = avg
		# Create slices for pie graph
		startsImage = [imageAvgTemp[p]*2*pi for p in imageAvgTemp]
		startsImage.insert(0,0)
		del startsImage[-1]
		endsImage = [imageAvgTemp[p]*2*pi for p in imageAvgTemp]

		# a color for each pie piece
		colors2 = ["#A12830", "#FAA43A", "#5DA5DA", "#686868", "#DECF3F", "#003A6F"]
		legend2 = ["Fear", "Angry", "Sad", "Neutral", "Surprise", "Happy"]

		#create plot
		imagePie = figure(title="#CapitalOne Image Sentiment Pie Graph",x_range=(-1,1.5), y_range=(-1,1))

		#create pie chart and legend
		imagePie.wedge(x=.2, y=0, radius=1, start_angle=startsImage, end_angle=endsImage, color=colors2)
		imagePie.circle(0,0,radius=0,legend=legend2[0],color=colors2[0])
		imagePie.circle(0,0,radius=0,legend=legend2[1],color=colors2[1])
		imagePie.circle(0,0,radius=0,legend=legend2[2],color=colors2[2])
		imagePie.circle(0,0,radius=0,legend=legend2[3],color=colors2[3])
		imagePie.circle(0,0,radius=0,legend=legend2[4],color=colors2[4])
		imagePie.circle(0,0,radius=0,legend=legend2[5],color=colors2[5])

		# Turn off tick labels
		imagePie.axis.major_label_text_color = None  
		# Turn off tick marks 
		imagePie.axis.major_tick_line_color = None
		imagePie.axis[0].ticker.num_minor_ticks = 0
		imagePie.axis[1].ticker.num_minor_ticks = 0

		# output to static HTML file
		output_file("sentimentgraphs.html", title="#CapitalOne Trend")
		p = vplot(heat,captionPie,imagePie)
		# show the results
		show(p)
コード例 #51
0

## Plot with multiple ranges that are bounded
x = np.array(AAPL['date'], dtype=np.datetime64)
x = x[0:1000]
apple_y = AAPL['adj_close'][0:1000]
google_y = GOOG['adj_close'][0:1000]

###### -- ranges set here -- ########
x_range = Range1d(
    start=date(2000, 1, 1), end=date(2004, 12, 31),
    bounds=(date(2000, 1, 1), date(2006, 12, 31)),
    min_interval=timedelta(100),
)
y_range = Range1d(start=0, end=40, bounds=(0, 60))
y_range_extra = Range1d(start=300, end=700, bounds=(200, 1000))
###### -- end -- ########

plot_extra = figure(x_axis_type="datetime", x_range=x_range, y_range=y_range, title="Multiple ranges x:(2000/1/1, 2006/12/31), y1:(10, 60), y2:(200, 1000)")
plot_extra.line(x, apple_y, color='lightblue')
plot_extra.extra_y_ranges = {'goog': y_range_extra}
plot_extra.line(x, google_y, color='pink', y_range_name='goog')
plot_extra.add_layout(LinearAxis(y_range_name="goog", major_label_text_color='pink'), 'left')

# Tweak the formats to make it all readable
plots = [plot_default, plot_range, plot_range_un, plot_range_rev, plot_cat_autobounded, plot_cat_unbounded, plot_cat_bounded, plot_extra]
for plot in plots:
    plot.title_text_font_size = '12pt'

show(vplot(plot_default, hplot(plot_range, plot_range_un, plot_range_rev), hplot(plot_cat_unbounded, plot_cat_autobounded, plot_cat_bounded), plot_extra))
コード例 #52
0
    def plot_time_series(self, moving_avg=False):
        """
        Plots time series and moving average filter
        when moving_avg set to true. This plot is currently done for
        3 climate variables.
        """
        t_fig_dict = dict()

        # Parse individual time series
        n_dict = parse_time_series(self.html_tags, self.txt)

        series = list()

        cds_dict = dict()

        for k in list(sorted(n_dict.keys())):
            v = n_dict[k]
            # Creating fig inst in dict for plot k
            t_fig_dict[k] = figure(title=k.split(",")[-1].replace(".txt", "").replace("_", " "),
                                   height=290)

            # Sort by x-axis(dates) in order to ensure a
            # sound plot
            tmp = list(v.items())
            tmp.sort()

            np.array(tmp)

            date = np.array(tmp)[:, 0]
            vals = np.array(tmp)[:, 1]

            tooltips = OrderedDict([
                ("time", "@x"),
                ("value", "@y"),
            ])
            cds_dict[k+'1'] = ColumnDataSource(
                data=dict(
                    x=date,
                    y=vals,
                )
            )
            if moving_avg:
                # Moving averaged filter data
                vals_a = self.causal_avg_filter(vals)
                date_a = date[self.radius:]

                cds_dict[k+'2'] = ColumnDataSource(
                    data=dict(
                        x=date_a,
                        y=vals_a,
                    )
                )
                # Plot moving averaged filtered data
                # k + " avg data"
                line_a = Line(x="x", y="y",
                              line_color='blue', line_width=6)
                circle_renderer = t_fig_dict[k].add_glyph(cds_dict[k+'2'],
                                                          line_a)
                _update_legend(plot=t_fig_dict[k],
                               legend_name=k .replace(".txt", "").replace(
                    "_", " ") + " avg data", glyph_renderer=circle_renderer)
                t_fig_dict[k].add_tools(
                    HoverTool(tooltips=tooltips, renderers=[circle_renderer]))
            # Plot raw data
            line_r = Line(x="x", y="y",
                          line_color='red')
            circle_renderer2 = t_fig_dict[k].add_glyph(cds_dict[k+'1'], line_r)
            _update_legend(plot=t_fig_dict[k],
                           legend_name=k.replace(".txt", "").replace(
                "_", " ") + " raw data", glyph_renderer=circle_renderer2)
            t_fig_dict[k].add_tools(
                HoverTool(tooltips=tooltips, renderers=[circle_renderer2]))

        # Unpack the fig instances in dict plot as a vertical stack of
        # horizontal plots
        v = vplot(*list(t_fig_dict.values()))

        return v
コード例 #53
0
def update():
    global layout
    global energy_per_capita

    new_df = data_changed(energy_per_capita)
    if new_df is not None:
        energy_per_capita = new_df
        layout.children[0] = create_line(energy_per_capita)
        layout.children[1] = create_bar(energy_per_capita)


line = create_line(energy_per_capita)
bar = create_bar(energy_per_capita)
desc1 = Paragraph(text="""
This example shows live integration between bokeh server and Excel using
XLWings.""")
desc2 = Paragraph(text="""
*** YOU MUST HAVE EXCEL and XLWINGS INSTALLED ON YOUR MACHINE FOR IT TO WORK ***
""")
desc3 = Paragraph(text="""
It opens this plots window and an excel spreadsheet instance with the
values being plotted. When user changes the values on the excel spreadsheet
the plots will be updated accordingly. It's not required to save the spreadsheet for the plots to update.
""")
layout = vplot(desc1, desc2, desc3, hplot(line, bar))
curdoc().add_root(layout)
curdoc().add_periodic_callback(update, 500)

session.show()  # open the document in a browser
session.loop_until_closed()  # run forever
コード例 #54
0
ファイル: scratch.py プロジェクト: lobachevzky/database_nn
ConfusionMatrix = namedtuple("confusion_matrix", "f1 precision recall")


def metrics():
    return {metric: [random.random() for _ in range(10)]
            for metric in ConfusionMatrix._fields}


scores = {dataset_name: metrics() for dataset_name in Datasets._fields}

properties_per_dataset = {
    'train': {'line_color': 'firebrick'},
    'test': {'line_color': 'orange'},
    'valid': {'line_color': 'olive'}
}

plots = []
for metric in ConfusionMatrix._fields:
    plot = figure(width=500, plot_height=500, title=metric)
    for dataset_name in scores:
        metric_scores = scores[dataset_name][metric]
        plot.line(range(len(metric_scores)),
                  metric_scores,
                  legend=dataset_name,
                  **properties_per_dataset[dataset_name])
    plots.append(plot)

p = vplot(*plots)

show(p)
コード例 #55
0
ファイル: run_charts.py プロジェクト: zfy1989lee/bitpredict
p3.outline_line_color = None
p3.xgrid.grid_line_color = 'white'
p3.ygrid.grid_line_color = 'white'
p3.axis.axis_line_color = None
p3.axis.major_tick_line_color = None
p3.axis.minor_tick_line_color = None
p3.yaxis.axis_label = 'Basis Points'
p3.yaxis.axis_label_standoff = ylabel_standoff
p3.xaxis.formatter = xformatter
p3.yaxis.formatter = yformatter
p3.xaxis.axis_label_standoff = 12
p3.yaxis.major_label_text_font = 'courier'
p3.xaxis.major_label_text_font = 'courier'
p3.x_range = p1.x_range

vp = vplot(p1, p2, p3)
push()
ip = load(urlopen('http://jsonip.com'))['ip']
ssn = cursession()
ssn.publish()
tag = embed.autoload_server(vp, ssn, public=True).replace('localhost', ip)
html = """
{%% extends "layout.html" %%}
{%% block bokeh %%}
%s
{%% endblock %%}
""" % tag

with open('templates/index.html', 'w+') as f:
    f.write(html)
コード例 #56
0
ファイル: CrapsTestPlot.py プロジェクト: sigbikes/Craps_Test
'''
import pandas as pd
from bokeh.charts import Bar, output_file, show, defaults
import bokeh.plotting as bp 
from bokeh.models import FixedTicker, LinearAxis
from bokeh.io import output_file, show, vplot

crapsArray(100, 5, 300)  
csv=pd.read_csv('test.csv')

output_file("craps.html")

#Plot sizes for charts
defaults.width = 1200
defaults.height = 300

action = Bar(csv, 'roll', values = 'score', title = "Craps Outcomes", bar_width = 1, color = 'score')
money = Bar(csv, 'roll', values = 'bank', title = "Craps Bankroll", bar_width = 1, color = 'score')
winLose = Bar(csv, 'roll', values = 'value', title = "Craps Roll Win/Loss", bar_width = 1, color = 'score')

xaxis=action.select({'type' : LinearAxis})
xaxis.ticker=FixedTicker(ticks=[0,25,50,75,100])
yaxis=action.select({'type' : LinearAxis})
yaxis.ticker=FixedTicker(ticks=[2,3,4,5,6,7,8,9,10,11,12])


p = vplot(action, money,winLose)

show(p)
print("Cashing Out")
コード例 #57
0
###### -- end -- ########


## Plot with multiple ranges that are bounded
x = np.array(AAPL['date'], dtype=np.datetime64)
x = x[0:1000]
apple_y = AAPL['adj_close'][0:1000]
google_y = GOOG['adj_close'][0:1000]

###### -- ranges set here -- ########
x_range = Range1d(
    start=date(2000, 1, 1), end=date(2004, 12, 31),
    bounds=(date(2001, 1, 1), date(2006, 12, 31))
)
y_range = Range1d(start=00, end=40, bounds=(10, 60))
y_range_extra = Range1d(start=300, end=700, bounds=(200, 1000))
###### -- end -- ########

plot_extra = figure(x_axis_type="datetime", x_range=x_range, y_range=y_range, title="Multiple ranges x:(2001/1/1, 2006/12/31), y1:(10, 60), y2:(200, 1000)")
plot_extra.line(x, apple_y, color='lightblue')
plot_extra.extra_y_ranges = {'goog': y_range_extra}
plot_extra.line(x, google_y, color='pink', y_range_name='goog')
plot_extra.add_layout(LinearAxis(y_range_name="goog", major_label_text_color='pink'), 'left')

# Tweak the formats to make it all readable
plots = [plot_default, plot_range, plot_range_un, plot_range_rev, plot_cat_autobounded, plot_cat_unbounded, plot_cat_bounded, plot_extra]
for plot in plots:
    plot.title_text_font_size = '12pt'

show(vplot(plot_default, hplot(plot_range, plot_range_un, plot_range_rev), hplot(plot_cat_unbounded, plot_cat_autobounded, plot_cat_bounded), plot_extra))
コード例 #58
0
ファイル: fourier_animated.py プロジェクト: zlxs23/bokeh
for k, p in fourier.items():
    p['plot'], p['sources'] = create_plot(
        p['fs'],
        'Fourier (Sum of the first 4 Harmonic Circles)',
        r=p['f'](period),
        cfoos=p['cfs'])

for k, p in fourier.items():
    p['cplot'], p['csources'] = create_centric_plot(
        p['fs'],
        'Fourier First 4 Harmonics & Harmonic Circles',
        r=p['f'](period),
        cfoos=p['cfs'])

layout = vplot(*[f['plot'] for f in fourier.values()] +
               [f['cplot'] for f in fourier.values()])

# open a session to keep our local document in sync with server
session = push_session(curdoc())


@repeat(range(N))
def cb(gind):
    global newx
    oldx = np.delete(newx, 0)
    newx = np.hstack([oldx, [oldx[-1] + 2 * pi / N]])

    for k, p in fourier.items():
        update_sources(p['sources'], p['fs'], newx, gind, p['cfs'])
        update_centric_sources(p['csources'], p['fs'], newx, gind, p['cfs'])
コード例 #59
0
ファイル: data_tables.py プロジェクト: yihongfa/bokeh
                   line_alpha=0.5)
cty = plot.add_glyph(source, cty_glyph)
hwy = plot.add_glyph(source, hwy_glyph)

# Add the tools
tooltips = [
    ("Manufacturer", "@manufacturer"),
    ("Model", "@model"),
    ("Displacement", "@displ"),
    ("Year", "@year"),
    ("Cylinders", "@cyl"),
    ("Transmission", "@trans"),
    ("Drive", "@drv"),
    ("Class", "@class"),
]
cty_hover_tool = HoverTool(renderers=[cty],
                           tooltips=tooltips + [("City MPG", "@cty")])
hwy_hover_tool = HoverTool(renderers=[hwy],
                           tooltips=tooltips + [("Highway MPG", "@hwy")])
select_tool = BoxSelectTool(renderers=[cty, hwy], dimensions=['width'])
plot.add_tools(cty_hover_tool, hwy_hover_tool, select_tool)

layout = vplot(plot, data_table)

if __name__ == "__main__":
    filename = "data_tables.html"
    with open(filename, "w") as f:
        f.write(file_html(layout, INLINE, "Data Tables"))
    print("Wrote %s" % filename)
    view(filename)