Ejemplo n.º 1
0
def stock(ticker1, ticker2):
    pretext = PreText(text="", width=500)
    df = get_data(ticker1, ticker2)
    source = ColumnDataSource(data=df)
    source.tags = ['main_source']
    p = figure(
        title="%s vs %s" % (ticker1, ticker2),
        plot_width=400,
        plot_height=400,
        tools="pan,wheel_zoom,box_select,reset",
        title_text_font_size="10pt",
    )
    p.circle(ticker1 + "_returns",
             ticker2 + "_returns",
             size=2,
             nonselection_alpha=0.02,
             source=source)
    stats = df.describe()
    pretext.text = str(stats)
    row1 = HBox(children=[p, pretext])
    hist1 = hist_plot(df, ticker1)
    hist2 = hist_plot(df, ticker2)
    row2 = HBox(children=[hist1, hist2])
    line1 = line_plot(ticker1, source)
    line2 = line_plot(ticker2, source, line1.x_range)
    output = VBox(children=[row1, row2, line1, line2])
    return output
Ejemplo n.º 2
0
def groupSliders(sliders):
    hbox_q = HBox(children=[sliders[0], sliders[1]])
    hbox_t = HBox(children=[sliders[2], sliders[3]])
    hbox_tm = HBox(children=[sliders[4], sliders[5]])
    hbox_sd = HBox(children=[sliders[6], sliders[7]])
    hboxes = [hbox_q, hbox_t, hbox_tm, hbox_sd]
    return hboxes
Ejemplo n.º 3
0
    def create(cls):
        """
        This function is called once, and is responsible for
        creating all objects (plots, datasources, etc)
        """
        # create layout widgets
        obj = cls()
        obj.mainrow = HBox()
        obj.checkbox = VBox(height=50)
        obj.mapbox = VBox()
        #obj.bottomrow = HBox()
        obj.statsbox = VBox(width=500)
        obj.totalbox = VBox()
        obj.legendbox = HBox()

        labels = ["County Average Ratings", "Hotel Locations"]
        obj.make_inputs()
        obj.make_outputs()

        # outputs
        #obj.pretext = Paragraph(text="", width=500)
        obj.make_source()
        obj.make_county_source()
        lat = 39.8282
        lng = -98.5795
        zoom = 6
        xr = Range1d()
        yr = Range1d()
        #obj.make_plots(lat, lng, zoom, xr, yr)
        obj.make_plots()

        # layout
        obj.set_children()
        return obj
Ejemplo n.º 4
0
    def set_children(self):
        self.input_frame = VBoxForm(children=[
            self.min_excitation,
            self.max_excitation,
            self.min_emission,
            self.max_emission,
            self.chrom_class_select,
        ])

        self.plot_frame = HBox(children=[self.plot])
        self.top_frame = HBox(children=[self.plot_frame, self.input_frame])
        self.table_frame = HBox(children=[self.data_table])
        self.main_frame = VBox(children=[self.top_frame, self.table_frame])
        self.children = [self.main_frame]
Ejemplo n.º 5
0
def update_stats_and_histograms(data, t1, t2):
    stats.text = str(data[[t1, t2, t1+'_returns', t2+'_returns']].describe())

    global layout
    h1 = get_histogram(t1)
    h2 = get_histogram(t2)
    layout.children[1] = HBox(h1, h2)
Ejemplo n.º 6
0
    def get_app(self):
        # Set up layouts and add to document
        inputs = VBoxForm(children=[
            self.text, self.offset, self.amplitude, self.phase, self.freq
        ])

        hbox = HBox(children=[inputs, self.plot])

        return hbox
Ejemplo n.º 7
0
def create_layout():
    year_select = Select(title="Year:", value="2010", options=years)
    location_select = Select(title="Location:", value="World", options=locations)

    year_select.on_change('value', on_year_change)
    location_select.on_change('value', on_location_change)

    controls = HBox(children=[year_select, location_select])
    layout = VBox(children=[controls, pyramid(), population()])

    return layout
Ejemplo n.º 8
0
    def create(cls):
        """
        This function is called once, and is responsible for
        creating all objects (plots, datasources, etc)
        """
        # create layout widgets
        obj = cls()
        obj.bigbox = VBox(width=670)
        obj.totalbox = HBox()
        obj.brandbox = VBox()
        obj.selectrbox = HBox()

        obj.make_source()
        # outputs
        obj.make_better_plots()

        obj.make_inputs()

        # layout
        obj.set_children()
        return obj
Ejemplo n.º 9
0
    def create_layout(self):
        from bokeh.models.widgets import Select, HBox, VBox

        years = list(map(str, sorted(self.df.Year.unique())))
        locations = sorted(self.df.Location.unique())

        year_select = Select(title="Year:", value="2010", options=years)
        location_select = Select(title="Location:", value="World", options=locations)

        year_select.on_change('value', self.on_year_change)
        location_select.on_change('value', self.on_location_change)

        controls = HBox(year_select, location_select)
        self.layout = VBox(controls, self.plot)
Ejemplo n.º 10
0
    def create(cls):
        """
        This function is called once, and is responsible for
        creating all objects (plots, datasources, etc)
        """
        # create layout widgets
        obj = cls()
        obj.mainrow = HBox()
        obj.histrow = HBox()
        obj.statsbox = VBox()
        obj.input_box = VBoxForm()

        # create input widgets
        obj.make_inputs()

        # outputs
        obj.pretext = PreText(text="", width=500)
        obj.make_source()
        obj.make_plots()
        obj.make_stats()

        # layout
        obj.set_children()
        return obj
Ejemplo n.º 11
0
    plot.title = text.value


text.on_change('value', update_title)


def update_data(attrname, old, new):

    # Get the current slider values
    a = amplitude.value
    b = offset.value
    w = phase.value
    k = freq.value

    # Generate the new curve
    x = np.linspace(0, 4 * np.pi, N)
    y = a * np.sin(k * x + w) + b

    source.data = dict(x=x, y=y)


for w in [offset, amplitude, phase, freq]:
    w.on_change('value', update_data)

# Set up layouts and add to document
inputs = VBoxForm(children=[text, offset, amplitude, phase, freq])

hbox = HBox(children=[inputs, plot])

curdoc().add(hbox)
Ejemplo n.º 12
0
    stats.text = str(data[[t1, t2, t1+'_returns', t2+'_returns']].describe())

    global layout
    h1 = get_histogram(t1)
    h2 = get_histogram(t2)
    layout.children[1] = HBox(h1, h2)

ticker1.on_change('value', ticker1_change)
ticker2.on_change('value', ticker2_change)

def selection_change(attrname, old, new):
    t1, t2 = ticker1.value, ticker2.value
    data = get_data(t1, t2)
    selected = source.selected['1d']['indices']
    if selected:
        data = data.iloc[selected, :]
    update_stats_and_histograms(data, t1, t2)

source.on_change('selected', selection_change)

# set up layout
stats_box = VBox(stats)
input_box = VBox(ticker1, ticker2)
main_row = HBox(input_box, corr, stats_box)
layout = VBox(main_row, HBox(), ts1, ts2)

# initialize
update()

curdoc().add_root(layout)
Ejemplo n.º 13
0
    def __init__(self, X, y):
        """Initializes the data viewer

        args:
         - X: array of x,y data to plot
         - y: coloring data, length equal to number of (x,y) data pairs
        """

        # normalize dataset for easier parameter selection
        self.X = StandardScaler().fit_transform(X)

        # estimate bandwidth for mean shift
        self.bandwidth = cluster.estimate_bandwidth(X, quantile=0.3)

        for i in range(4):
            self.colors[i] = [Spectral6[f] for f in y]
            self.source[i] = ColumnDataSource(data=dict(
                x=self.X[:, 0], y=self.X[:, 1], colors=self.colors[i]))

        # SET UP PLOT
        algorithm = 'Select Algorithm'
        tools = 'pan,wheel_zoom,box_select,reset'

        widgets_to_check_for_updates = []

        #KMeans
        plot1 = Figure(plot_width=400,
                       plot_height=400,
                       title="KMeans",
                       title_text_font_size='10pt',
                       tools=tools)
        plot1.circle('x',
                     'y',
                     fill_color='colors',
                     line_color=None,
                     source=self.source[0])
        self.k_means_slider = Slider(start=1, end=20, value=2, step=1)
        widgets_to_check_for_updates.append(self.k_means_slider)

        plot2 = Figure(plot_width=400,
                       plot_height=400,
                       title="DBSCAN",
                       title_text_font_size='10pt',
                       tools=tools)
        plot2.circle('x',
                     'y',
                     fill_color='colors',
                     line_color=None,
                     source=self.source[1])
        self.DBSCAN_slider = Slider(start=0.01, end=1.0, step=0.01, value=0.2)
        widgets_to_check_for_updates.append(self.DBSCAN_slider)

        plot3 = Figure(plot_width=400,
                       plot_height=400,
                       title="Birch",
                       title_text_font_size='10pt',
                       tools=tools)
        plot3.circle('x',
                     'y',
                     fill_color='colors',
                     line_color=None,
                     source=self.source[2])
        self.birch_slider = Slider(start=1, end=20, value=2, step=1)
        widgets_to_check_for_updates.append(self.birch_slider)

        plot4 = Figure(plot_width=400,
                       plot_height=400,
                       title="Mean Shift",
                       title_text_font_size='10pt',
                       tools=tools)
        plot4.circle('x',
                     'y',
                     fill_color='colors',
                     line_color=None,
                     source=self.source[3])

        for widget in widgets_to_check_for_updates:
            widget.on_change('value', self.update_data)

        # SET UP LAYOUT
        self.plots = HBox(children=[
            VBox(children=[
                plot1, self.k_means_slider, plot3, self.birch_slider
            ]),
            VBox(children=[plot2, self.DBSCAN_slider, plot4])
        ])
        # add to document

        self.update_data('value', 0, 0)
Ejemplo n.º 14
0
# Set up callbacks
def update_title(attrname, old, new):
    plot.title = text.value


text.on_change('value', update_title)


def update_data(attrname, old, new):

    # Get the current slider values
    a = amplitude.value
    b = offset.value
    w = phase.value
    k = freq.value

    # Generate the new curve
    x = np.linspace(0, 4 * np.pi, N)
    y = a * np.sin(k * x + w) + b

    source.data = dict(x=x, y=y)


for w in [offset, amplitude, phase, freq]:
    w.on_change('value', update_data)

# Set up layouts and add to document
inputs = VBoxForm(children=[text, offset, amplitude, phase, freq])

curdoc().add_root(HBox(children=[inputs, plot]))
Ejemplo n.º 15
0
    elif algorithm == 'AgglomerativeClustering':
        model = cluster.AgglomerativeClustering(linkage="average",
                                                affinity="cityblock",
                                                n_clusters=2,
                                                connectivity=connectivity)
    elif algorithm == 'Birch':
        model = cluster.Birch(n_clusters=2)
    elif algorithm == 'DBSCAN':
        model = cluster.DBSCAN(eps=.2)
    else:
        print('No Algorithm selected')
    model.fit(X)

    if hasattr(model, 'labels_'):
        y_pred = model.labels_.astype(np.int)
    else:
        y_pred = model.predict(X)

    colors = [Spectral6[i] for i in y_pred]

    source.data['colors'] = colors
    plot.title = algorithm


dropdown.on_change('value', update_data)

# SET UP LAYOUT
inputs = HBox(children=[dropdown])
plots = HBox(children=[plot])
# add to document
curdoc().add_root(VBox(children=[inputs, plots]))
Ejemplo n.º 16
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)

        xdr = DataRange1d()
        ydr = DataRange1d()
        plot = Plot(title=None,
                    x_range=xdr,
                    y_range=ydr,
                    plot_width=800,
                    plot_height=300)
        xaxis = LinearAxis(plot=plot)
        plot.below.append(xaxis)
        yaxis = LinearAxis(plot=plot)
        ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker)
        plot.left.append(yaxis)
        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 = GlyphRenderer(data_source=self.source, glyph=cty_glyph)
        hwy = GlyphRenderer(data_source=self.source, glyph=hwy_glyph)
        tooltips = [
            ("Manufacturer", "@manufacturer"),
            ("Model", "@model"),
            ("Displacement", "@displ"),
            ("Year", "@year"),
            ("Cylinders", "@cyl"),
            ("Transmission", "@trans"),
            ("Drive", "@drv"),
            ("Class", "@class"),
        ]
        cty_hover_tool = HoverTool(plot=plot,
                                   renderers=[cty],
                                   tooltips=tooltips + [("City MPG", "@cty")])
        hwy_hover_tool = HoverTool(plot=plot,
                                   renderers=[hwy],
                                   tooltips=tooltips +
                                   [("Highway MPG", "@hwy")])
        select_tool = BoxSelectTool(plot=plot,
                                    renderers=[cty, hwy],
                                    dimensions=['width'])
        plot.tools.extend([cty_hover_tool, hwy_hover_tool, select_tool])
        plot.renderers.extend([cty, hwy, ygrid])

        controls = VBox(children=[
            manufacturer_select, model_select, transmission_select,
            drive_select, class_select
        ],
                        width=200)
        top_panel = HBox(children=[controls, plot])
        layout = VBox(children=[top_panel, data_table])

        return layout
Ejemplo n.º 17
0
    colors = [spectral[i] for i in y_pred]

    source.data['x'] = X[:, 0]
    source.data['y'] = X[:, 1]
    source.data['colors'] = colors

def update_clusters(attrname, old, new):
    algorithm = algorithm_select.value
    n_clusters = int(clusters_slider.value)
    n_samples = int(samples_slider.value)

    global X
    X, y_pred = clustering(X, algorithm, n_clusters)
    colors = [spectral[i] for i in y_pred]

    source.data['x'] = X[:, 0]
    source.data['y'] = X[:, 1]
    source.data['colors'] = colors

algorithm_select.on_change('value', update_algorithm)
dataset_select.on_change('value', update_dataset)
clusters_slider.on_change('value', update_clusters)
samples_slider.on_change('value', update_samples)

# SET UP LAYOUT
sliders = VBox(children=[samples_slider, clusters_slider])
selects = HBox(children=[dataset_select, algorithm_select])
inputs = VBox(children=[sliders, selects])
plots = HBox(children=[plot])
# add to document
curdoc().add_root(HBox(children=[inputs, plots]))
Ejemplo n.º 18
0
    corr.title = '%s returns vs. %s returns' % (t1, t2)
    ts1.title, ts2.title = t1, t2

def update_stats(data, t1, t2):
    stats.text = str(data[[t1, t2, t1+'_returns', t2+'_returns']].describe())

ticker1.on_change('value', ticker1_change)
ticker2.on_change('value', ticker2_change)

def selection_change(attrname, old, new):
    t1, t2 = ticker1.value, ticker2.value
    data = get_data(t1, t2)
    selected = source.selected['1d']['indices']
    if selected:
        data = data.iloc[selected, :]
    update_stats(data, t1, t2)

source.on_change('selected', selection_change)

# set up layout
stats_box = VBox(stats)
input_box = VBox(ticker1, ticker2)
main_row = HBox(input_box, corr, stats_box)
layout = VBox(main_row, GridPlot(children=[[ts1], [ts2]]))

# initialize
update()

curdoc().add_root(layout)
Ejemplo n.º 19
0
def make_spectrogram():

    plot_kw = dict(tools="",
                   min_border=1,
                   h_symmetry=False,
                   v_symmetry=False,
                   toolbar_location=None)

    freq = VBox(children=[
        Paragraph(text="Freq Range"),
        Slider(orientation="vertical",
               start=1,
               end=MAX_FREQ,
               value=MAX_FREQ,
               step=1,
               name="freq")
    ])

    gain = VBox(children=[
        Paragraph(text="Gain"),
        Slider(orientation="vertical",
               start=1,
               end=20,
               value=1,
               step=1,
               name="gain")
    ])

    spec_source = ColumnDataSource(data=dict(image=[], x=[]))
    spec = image_rgba(x='x',
                      y=0,
                      image='image',
                      dw=TILE_WIDTH,
                      dh=MAX_FREQ,
                      cols=TILE_WIDTH,
                      rows=SPECTROGRAM_LENGTH,
                      title=None,
                      source=spec_source,
                      plot_width=800,
                      plot_height=300,
                      x_range=[0, NGRAMS],
                      y_range=[0, MAX_FREQ],
                      dilate=True,
                      name="spectrogram",
                      **plot_kw)

    spectrum_source = ColumnDataSource(data=dict(x=[], y=[]))
    spectrum = line(x="x",
                    y="y",
                    line_color="darkblue",
                    title="Power Spectrum",
                    source=spectrum_source,
                    plot_width=800,
                    plot_height=250,
                    x_range=[0, MAX_FREQ],
                    y_range=[10**(-4), 10**3],
                    y_axis_type="log",
                    name="spectrum",
                    **plot_kw)

    signal_source = ColumnDataSource(data=dict(x=[], y=[]))
    signal = line(x="x",
                  y="y",
                  line_color="darkblue",
                  title="Signal",
                  source=signal_source,
                  plot_width=800,
                  plot_height=250,
                  x_range=[0, TIMESLICE * 1.01],
                  y_range=[-0.1, 0.1],
                  name="signal",
                  **plot_kw)

    radial_source = ColumnDataSource(data=dict(
        inner_radius=[],
        outer_radius=[],
        start_angle=[],
        end_angle=[],
        fill_alpha=[],
    ))
    eq = annular_wedge(x=0,
                       y=0,
                       fill_color="#688AB9",
                       fill_alpha="fill_alpha",
                       line_color=None,
                       inner_radius="inner_radius",
                       outer_radius="outer_radius",
                       start_angle="start_angle",
                       end_angle="end_angle",
                       title=None,
                       source=radial_source,
                       plot_width=500,
                       plot_height=520,
                       x_range=[-20, 20],
                       y_range=[-20, 20],
                       name="eq",
                       **plot_kw)
    grid().grid_line_color = None

    lines = VBox(children=[spectrum, signal])

    layout = VBox(children=[
        HBox(children=[freq, gain, spec]),
        HBox(children=[lines, eq])
    ])

    return layout
Ejemplo n.º 20
0
    barchart.outline_line_color = None

    barchart.toolbar_location = 'right'

    barchart.logo = None

    for renderer in barchart.select(GlyphRenderer):
        if renderer.data_source.data['height'] != [0]:
            year = renderer.data_source.data['year']
            num_dnf = data['dnfs'].loc[data['year'] == year]
            num_entries = data['entries'].loc[data['year'] == year]
            percent_dnf = data['percentage_dnf'].loc[data['year'] == year]
            hover = HoverTool(renderers=[renderer],
                              tooltips=[
                                  ("# DNFs", '%d' % num_dnf.values[0]),
                                  ("# Entries", '%d' % num_entries.values[0]),
                                  ("% DNF",
                                   '%.2f%%' % (100 * percent_dnf.values[0]))
                              ])
            barchart.add_tools(hover)

    return barchart


select_event.on_change('value', on_event_change)

layout = HBox(children=[select_event, generate_chart(selectable_events[2])])

curdoc().add_root(layout)
Ejemplo n.º 21
0
    current_topic = None
    mdssource.selected = []
    session.store_objects(mdssource)


btn_prev.on_click(on_btn_prev)
btn_next.on_click(on_btn_next)
btn_clear.on_click(on_btn_clear)

slider = Slider(title="Slide to adjust relevance metric",
                value=0.25,
                start=0.0,
                end=1.0,
                step=0.01)

topics = HBox(height=50, children=[btn_prev, btn_next, btn_clear])
metric = HBox(height=50, children=[slider])

left_panel = VBox(children=[topics, intertopic_distance_map])
right_panel = VBox(children=[metric, top_R_terms])

layout = HBox(children=[left_panel, right_panel])

document.add(layout)
session.store_document(document)

if __name__ == "__main__":
    link = session.object_link(document.context)
    print("Please visit %s to see the plots" % link)
    view(link)
    print("\npress ctrl-C to exit")
Ejemplo n.º 22
0
# Set up callbacks
def update_title(attrname, old, new):
    plot.title = text.value


text.on_change('value', update_title)


def update_data(attrname, old, new):

    # Get the current slider values
    a = amplitude.value
    b = offset.value
    w = phase.value
    k = freq.value

    # Generate the new curve
    x = np.linspace(0, 4 * np.pi, N)
    y = a * np.sin(k * x + w) + b

    source.data = dict(x=x, y=y)


for w in [offset, amplitude, phase, freq]:
    w.on_change('value', update_data)

# Set up layouts and add to document
inputs = VBoxForm(children=[text, offset, amplitude, phase, freq])

curdoc().add_root(HBox(children=[inputs, plot], width=800))
Ejemplo n.º 23
0
    data = update_data()
    hist_plot('stock1', ticker1, h1source, data, plot=hist1)
    hist_plot('stock2', ticker2, h2source, data, plot=hist2)

    plot.title = '%s vs %s' % (ticker1, ticker2)
    line_plot1.title = ticker1
    line_plot2.title = ticker2

def selection_change(attrname, old, new):
    df = get_data(ticker1, ticker2)
    if source.selected['1d']['indices']:
        selected_df = df.iloc[source.selected['1d']['indices'], :]
    else:
        selected_df = None

    hist_plot('stock1', ticker1, h1source, df, plot=hist1, selected_df=selected_df)
    hist_plot('stock2', ticker2, h2source, df, plot=hist2, selected_df=selected_df)

ticker1_select.on_change('value', input1_change)
ticker2_select.on_change('value', input2_change)
source.on_change('selected', selection_change)

# layout
statsbox = VBox(children=[pretext])
input_box = VBox(children=[ticker1_select, ticker2_select])
mainrow = HBox(children=[input_box, plot, statsbox])
histrow = HBox(children=[hist1, hist2])
vbox = VBox(children=[mainrow, histrow, line_plot1, line_plot2])

curdoc().add(vbox)
Ejemplo n.º 24
0
def update_stats(data, t1, t2):
    stats.text = str(data[[t1, t2, t1 + '_returns',
                           t2 + '_returns']].describe())


ticker1.on_change('value', ticker1_change)
ticker2.on_change('value', ticker2_change)


def selection_change(attrname, old, new):
    t1, t2 = ticker1.value, ticker2.value
    data = get_data(t1, t2)
    selected = source.selected['1d']['indices']
    if selected:
        data = data.iloc[selected, :]
    update_stats(data, t1, t2)


source.on_change('selected', selection_change)

# set up layout
stats_box = VBox(stats)
input_box = VBox(ticker1, ticker2)
main_row = HBox(input_box, corr, stats_box, width=1100)
layout = VBox(main_row, GridPlot(children=[[ts1], [ts2]]))

# initialize
update()

curdoc().add_root(layout)
Ejemplo n.º 25
0
        selected = selected[selected.Cast.str.contains(cast_val)==True]
    return selected

def update(attrname, old, new):
    df = select_movies()
    x_name = axis_map[x_axis.value]
    y_name = axis_map[y_axis.value]

    p.xaxis.axis_label = x_axis.value
    p.yaxis.axis_label = y_axis.value
    p.title = "%d movies selected" % len(df)
    source.data = dict(
        x=df[x_name],
        y=df[y_name],
        color=df["color"],
        title=df["Title"],
        year=df["Year"],
        revenue=df["revenue"],
        alpha=df["alpha"],
    )

controls = [reviews, boxoffice, genre, min_year, max_year, oscars, director, cast, x_axis, y_axis]
for control in controls:
    control.on_change('value', update)

inputs = HBox(VBoxForm(controls), width=300)

update(None, None, None) # initial load of the data

curdoc().add_root(HBox(inputs, p, width=1100))
Ejemplo n.º 26
0
    }


def on_year_change(attrname, old, new):
    # Set the value of the select widget forcefully to prevent race condition
    select_year.value = new
    update_data()


def on_event_change(attrname, old, new):
    # Set the value of the select widget forcefully to prevent race condition
    select_event.value = new
    update_data()


def update_data():
    update_histogram_data(select_year.value, select_event.value)
    plot.title = "FSAE Michigan - Histogram - " + select_event.value + " - " + select_year.value


select_year.on_change('value', on_year_change)
select_event.on_change('value', on_event_change)

# Bokeh plotting output
inputs = VBoxForm(children=[select_event, select_year])
layout = HBox(children=[inputs, plot])

update_data()

curdoc().add_root(layout)
Ejemplo n.º 27
0
    try:
        global expr
        expr = sy.sympify(new, dict(x=xs))
    except (sy.SympifyError, TypeError, ValueError) as exception:
        dialog.content = str(exception)
        dialog.visible = True
        session.store_objects(dialog)
    else:
        update_data()

dialog = Dialog(title="Invalid expression", buttons=["Close"])

slider = Slider(start=1, end=20, value=order, step=1, title="Order:")
slider.on_change('value', on_slider_value_change)

text = TextInput(value=str(expr), title="Expression:")
text.on_change('value', on_text_value_change)

inputs = HBox(children=[slider, text])
layout = VBox(children=[inputs, plot, dialog])

document.add(layout)
update_data()

if __name__ == "__main__":
    link = session.object_link(document.context)
    print("Please visit %s to see the plots" % link)
    view(link)
    print("\npress ctrl-C to exit")
    session.poll_document(document)
Ejemplo n.º 28
0
        year) + " Total Scores by Place"

    barchart._xaxis.axis_label = "Teams"
    barchart._xaxis.axis_line_color = None
    barchart._xaxis.major_tick_line_color = None
    barchart._xaxis.minor_tick_line_color = None
    barchart._xaxis.major_label_text_font_size = '0.6em'

    barchart._yaxis.axis_label = "Total Score"
    barchart._yaxis.axis_line_color = None
    barchart._yaxis.major_tick_line_color = None
    barchart._yaxis.minor_tick_line_color = None

    barchart.outline_line_color = None

    barchart.toolbar_location = 'right'

    barchart.logo = None

    return barchart


select_year.on_change('value', on_year_change)

# Bokeh plotting output
layout = HBox(
    children=[select_year,
              generate_chart(int(selectable_years[-1]))])

curdoc().add_root(layout)