Example #1
0
def plot1():
    # copy/pasted from Bokeh Getting Started Guide - used as an example
    grouped = autompg.groupby("yr")
    mpg = grouped.mpg
    avg, std = mpg.mean(), mpg.std()
    years = list(grouped.groups)
    american = autompg[autompg["origin"] == 1]
    japanese = autompg[autompg["origin"] == 3]

    p = Figure(title="MPG by Year (Japan and US)")

    p.vbar(x=years,
           bottom=avg - std,
           top=avg + std,
           width=0.8,
           fill_alpha=0.2,
           line_color=None,
           legend="MPG 1 stddev")

    p.circle(x=japanese["yr"],
             y=japanese["mpg"],
             size=10,
             alpha=0.5,
             color="red",
             legend="Japanese")

    p.triangle(x=american["yr"],
               y=american["mpg"],
               size=10,
               alpha=0.3,
               color="blue",
               legend="American")

    p.legend.location = "top_left"
    return json.dumps(json_item(p, "myplot"))
def make_plot(yscale='linear'):
    # configure the tools
    width_zoom={'dimensions':['width']}
    tools = [tool(**width_zoom) for tool in [BoxZoomTool, WheelZoomTool]]

    hover_pos = HoverTool(
            names=['buy','sell'],
            tooltips=[
              ('Position','@pos'),
              ('Date','@date'),
              ('Price','@price')
            ]
    )
    hover_pos.name = 'Postions'


    tools.extend([PanTool(), hover_pos, ResetTool(), CrosshairTool()])

    # prepare plot
    p = Figure(plot_height=600, plot_width=800, title="Moving Average Positions",
            x_axis_type='datetime', y_axis_type=yscale, tools=tools)

    p.line(x='date', y='price', alpha=0.3, color='Black', line_width=2, source=source, legend='Close', name='price')
    p.line(x='date', y='mav_short', color='DarkBlue', line_width=2, source=source, legend='Short MAV')
    p.line(x='date', y='mav_long', color='FireBrick', line_width=2, source=source, legend='Long MAV')
    p.inverted_triangle(x='x', y='y', color='Crimson', size=20, alpha=0.7, source=sell, legend='Sell', name='sell')
    p.triangle(x='x', y='y', color='ForestGreen', size=20, alpha=0.7, source=buy, legend='Buy', name='buy')

    return p
def add_direction_map(fig: Figure, mgrid, direction_map, freq=2, **kwargs):
    """Quiver plot of direction map
    
    http://bokeh.pydata.org/en/latest/docs/gallery/quiver.html
    
    Args:
        fig: 
        mgrid: 
        direction_map: 
        **kwargs: 
        
    """
    X, Y = mgrid.values
    U, V = direction_map

    x0 = X[::freq, ::freq].flatten()
    y0 = Y[::freq, ::freq].flatten()

    x1 = x0 + 0.9 * freq * mgrid.step * U[::freq, ::freq].flatten()
    y1 = y0 + 0.9 * freq * mgrid.step * V[::freq, ::freq].flatten()

    fig.segment(x0, y0, x1, y1, **kwargs)
    fig.triangle(x1,
                 y1,
                 size=4.0,
                 angle=np.arctan2(V[::freq, ::freq].flatten(),
                                  U[::freq, ::freq].flatten()) - np.pi / 2)
Example #4
0
def plot_crossover_signals(data, signals, ticker=None, notebook=False):
    # create a new plot with a title and axis labels
    p = Figure(title=ticker + ' Moving Crossover Strategy',
               x_axis_label='Date',
               x_axis_type='datetime',
               y_axis_label='Price in $',
               plot_height=500,
               plot_width=950,
               tools=['pan', 'wheel_zoom'],
               toolbar_location='below')

    # configure so that Bokeh chooses what (if any) scroll tool is active
    p.toolbar.active_scroll = "auto"

    # add a line renderer with legend and line thickness
    p.line(data.index,
           data['Close'],
           line_width=2,
           legend='Close',
           line_color='black')
    p.line(signals.index,
           signals['short_mavg'],
           line_width=2,
           legend='Slow MA',
           line_color='orange')
    p.line(signals.index,
           signals['long_mavg'],
           line_width=2,
           legend='Fast MA',
           line_color='blue')

    p.triangle(signals.loc[signals.positions == 1.0].index,
               signals.short_mavg[signals.positions == 1.0],
               size=15,
               fill_color='green',
               legend='Bullish Crossover')
    p.inverted_triangle(signals.loc[signals.positions == -1.0].index,
                        signals.short_mavg[signals.positions == -1.0],
                        size=15,
                        fill_color='red',
                        legend='Bearish Crossover')

    p.legend.location = "top_left"
    p.legend.click_policy = "hide"

    if notebook:
        # show the results
        show(p, notebook_handle=True)
        push_notebook()
    else:
        # output the results
        output_file('%s Moving Crossover Strategy.html' % ticker)
        save(p)
    def construct_best_odds_figure(self, x, y, z, t, trade_id, sticker):
        # workaround to format date in the hover tool at the moment bokeh does not supported in the tool tips
        source_back_odds = ColumnDataSource(data=dict(x=x, y=y, time=[e.strftime('%d-%m-%Y %H:%M:%S') for e in x]))

        hover = HoverTool(
            tooltips=[
                ("index", "$index"),
                ("x", "@time"),
                ("y", "@y"),
            ],
            active=False
        )

        # create a new plot with a a datetime axis type
        p2 = Figure(plot_width=1000, plot_height=600, title=sticker, toolbar_location="above", x_axis_type="datetime",
                    tools=[hover, 'box_zoom, box_select, crosshair, resize, reset, save,  wheel_zoom'])
        orders = self.map_trade_id_to_orders[trade_id, sticker]
        for order in orders:
            a = [order.placed_dt]
            b = [order.price]
            source_placed = ColumnDataSource(data=dict(a=a, b=b, time=[a[0].strftime('%d-%m-%Y %H:%M:%S')]))
            p2.square(a, b, legend="placed", fill_color="red", line_color="red", size=8, source=source_placed)

        p2.circle(x, y, size=8, color='navy', alpha=0.2, legend="best back odds", source=source_back_odds)
        p2.line(x, y, color='navy', legend="best back odds", source=source_back_odds)

        # lay odds
        source_lay_odds = ColumnDataSource(data=dict(z=z, t=t, time=[e.strftime('%d-%m-%Y %H:%M:%S') for e in z]))
        p2.triangle(z, t, size=8, color='green', alpha=0.2, legend="best lay odds", source=source_lay_odds)
        p2.line(z, t, color='green', legend="best lay odds", source=source_lay_odds)

        # NEW: customize by setting attributes
        # p2.title = sticker
        p2.legend.location = "top_left"
        p2.grid.grid_line_alpha = 0
        p2.xaxis.axis_label = 'Date'
        p2.yaxis.axis_label = "Best odds"
        p2.ygrid.band_fill_color = "olive"
        p2.ygrid.band_fill_alpha = 0.1

        return p2
Example #6
0
def plot_bollinger_signals(data, signals, ticker=None, notebook=False):
    # create a new plot with a title and axis labels
    p = Figure(title=ticker + ' Bollinger Bands Strategy',
               x_axis_label='Date',
               x_axis_type='datetime',
               y_axis_label='Price in $',
               plot_height=500,
               plot_width=950,
               tools=['pan', 'wheel_zoom'],
               toolbar_location='below')

    inc = data['Close'] > data['Open']
    dec = data['Open'] > data['Close']
    w = 12 * 60 * 60 * 1000  # half day in ms

    p.segment(data.index, data['High'], data.index, data['Low'], color="black")
    p.vbar(data.index[inc],
           w,
           data['Open'][inc],
           data['Close'][inc],
           fill_color="#D5E1DD",
           line_color="black")
    p.vbar(data.index[dec],
           w,
           data['Open'][dec],
           data['Close'][dec],
           fill_color="#F2583E",
           line_color="black")

    # configure so that Bokeh chooses what (if any) scroll tool is active
    p.toolbar.active_scroll = "auto"

    # add a line renderer with legend and line thickness
    p.line(signals.index,
           signals['mediumband'],
           line_width=2,
           legend='Mediumband',
           line_color='black')
    p.line(signals.index,
           signals['upperband'],
           line_width=2,
           legend='Upperband',
           line_color='orange')
    p.line(signals.index,
           signals['lowerband'],
           line_width=2,
           legend='Lowerband',
           line_color='blue')

    p.triangle(signals.loc[signals.positions == 1.0].index,
               signals.lowerband[signals.positions == 1.0],
               size=15,
               fill_color='green',
               legend='Buy')
    p.inverted_triangle(signals.loc[signals.positions == -1.0].index,
                        signals.upperband[signals.positions == -1.0],
                        size=15,
                        fill_color='red',
                        legend='Sell')

    p.legend.location = "top_left"
    p.legend.click_policy = "hide"

    if notebook:
        # show the results
        show(p, notebook_handle=True)
        push_notebook()
    else:
        # output the results
        output_file('%s Bollinger Bands Strategy.html' % ticker)
        save(p)
def plot_waveform_bokeh(filename,waveform_list,metadata_list,station_lat_list,\
                       station_lon_list, event_lat, event_lon, boundary_data, style_parameter):
    xlabel_fontsize = style_parameter['xlabel_fontsize']
    #
    map_station_location_bokeh = ColumnDataSource(data=dict(map_lat_list=station_lat_list,\
                                                            map_lon_list=station_lon_list))
    dot_default_index = 0
    selected_dot_on_map_bokeh = ColumnDataSource(data=dict(lat=[station_lat_list[dot_default_index]],\
                                                           lon=[station_lon_list[dot_default_index]],\
                                                           index=[dot_default_index]))
    map_view = Figure(plot_width=style_parameter['map_view_plot_width'], \
                      plot_height=style_parameter['map_view_plot_height'], \
                      y_range=[style_parameter['map_view_lat_min'],\
                    style_parameter['map_view_lat_max']], x_range=[style_parameter['map_view_lon_min'],\
                    style_parameter['map_view_lon_max']], tools=style_parameter['map_view_tools'],\
                    title=style_parameter['map_view_title'])
    # ------------------------------
    # add boundaries to map view
    # country boundaries
    map_view.multi_line(boundary_data['country']['longitude'],\
                        boundary_data['country']['latitude'],color='gray',\
                        line_width=2, level='underlay', nonselection_line_alpha=1.0,\
                        nonselection_line_color='gray')
    # marine boundaries
    map_view.multi_line(boundary_data['marine']['longitude'],\
                        boundary_data['marine']['latitude'],color='gray',\
                        level='underlay', nonselection_line_alpha=1.0,\
                        nonselection_line_color='gray')
    # shoreline boundaries
    map_view.multi_line(boundary_data['shoreline']['longitude'],\
                        boundary_data['shoreline']['latitude'],color='gray',\
                        line_width=2, nonselection_line_alpha=1.0, level='underlay',
                        nonselection_line_color='gray')
    # state boundaries
    map_view.multi_line(boundary_data['state']['longitude'],\
                        boundary_data['state']['latitude'],color='gray',\
                        level='underlay', nonselection_line_alpha=1.0,\
                        nonselection_line_color='gray')
    #
    map_view.triangle('map_lon_list', 'map_lat_list', source=map_station_location_bokeh, \
                      line_color='gray', size=style_parameter['marker_size'], fill_color='black',\
                      selection_color='black', selection_line_color='gray',\
                      selection_fill_alpha=1.0,\
                      nonselection_fill_alpha=1.0, nonselection_fill_color='black',\
                      nonselection_line_color='gray', nonselection_line_alpha=1.0)
    map_view.triangle('lon','lat', source=selected_dot_on_map_bokeh,\
                      size=style_parameter['selected_marker_size'], line_color='black',fill_color='red')
    map_view.asterisk([event_lon], [event_lat], size=style_parameter['event_marker_size'], line_width=3, line_color='red', \
                      fill_color='red')
    # change style
    map_view.title.text_font_size = style_parameter['title_font_size']
    map_view.title.align = 'center'
    map_view.title.text_font_style = 'normal'
    map_view.xaxis.axis_label = style_parameter['map_view_xlabel']
    map_view.xaxis.axis_label_text_font_style = 'normal'
    map_view.xaxis.axis_label_text_font_size = xlabel_fontsize
    map_view.xaxis.major_label_text_font_size = xlabel_fontsize
    map_view.yaxis.axis_label = style_parameter['map_view_ylabel']
    map_view.yaxis.axis_label_text_font_style = 'normal'
    map_view.yaxis.axis_label_text_font_size = xlabel_fontsize
    map_view.yaxis.major_label_text_font_size = xlabel_fontsize
    map_view.xgrid.grid_line_color = None
    map_view.ygrid.grid_line_color = None
    map_view.toolbar.logo = None
    map_view.toolbar_location = 'above'
    map_view.toolbar_sticky = False
    # --------------------------------------------------------
    max_waveform_length = 0
    max_waveform_amp = 0
    ncurve = len(waveform_list)
    for a_sta in waveform_list:
        for a_trace in a_sta:
            if len(a_trace) > max_waveform_length:
                max_waveform_length = len(a_trace)
            if np.max(np.abs(a_trace)) > max_waveform_amp:
                max_waveform_amp = np.max(np.abs(a_trace))
    #
    plotting_list = []
    for a_sta in waveform_list:
        temp = []
        for a_trace in a_sta:
            if len(a_trace) < max_waveform_length:
                a_trace = np.append(a_trace,np.zeros([(max_waveform_length-len(a_trace)),1]))
            temp.append(list(a_trace))
        plotting_list.append(temp)
    #
    time_list = []
    for ista in range(len(plotting_list)):
        a_sta = plotting_list[ista]
        temp = []
        for itr in range(len(a_sta)):
            a_trace = a_sta[itr]
            delta = metadata_list[ista][itr]['delta']
            time = list(np.arange(len(a_trace))*delta)
            temp.append(time)
        #
        time_list.append(temp)
    #
    reftime_label_list = []
    channel_label_list = []
    for ista in range(len(metadata_list)):
        temp_ref = []
        temp_channel = []
        a_sta = metadata_list[ista]
        for a_trace in a_sta:
            temp_ref.append('Starting from '+a_trace['starttime'])
            temp_channel.append(a_trace['network']+'_'+a_trace['station']+'_'+a_trace['channel'])
        reftime_label_list.append(temp_ref)
        channel_label_list.append(temp_channel)
    # --------------------------------------------------------
    curve_fig01 = Figure(plot_width=style_parameter['curve_plot_width'], plot_height=style_parameter['curve_plot_height'], \
                       y_range=(-max_waveform_amp*1.05,max_waveform_amp*1.05), \
                       x_range=(0,max_waveform_length),\
                    tools=['save','box_zoom','ywheel_zoom','xwheel_zoom','reset','crosshair','pan']) 
    #
    curve_index = 0
    select_curve_data = plotting_list[dot_default_index][curve_index]
    select_curve_time = time_list[dot_default_index][curve_index]
    
    selected_curve_data_bokeh01 = ColumnDataSource(data=dict(time=select_curve_time,amp=select_curve_data))
    select_reftime_label = reftime_label_list[dot_default_index][curve_index]
    selected_reftime_label_bokeh01 = ColumnDataSource(data=dict(x=[style_parameter['curve_reftime_label_x']],\
                                                                y=[style_parameter['curve_reftime_label_y']],\
                                                                label=[select_reftime_label]))
    select_channel_label = channel_label_list[dot_default_index][curve_index]
    selected_channel_label_bokeh01 = ColumnDataSource(data=dict(x=[style_parameter['curve_channel_label_x']],\
                                                                y=[style_parameter['curve_channel_label_y']],\
                                                                label=[select_channel_label]))
    all_curve_data_bokeh = ColumnDataSource(data=dict(t=time_list, amp=plotting_list))
    all_reftime_label_bokeh = ColumnDataSource(data=dict(label=reftime_label_list))
    all_channel_label_bokeh = ColumnDataSource(data=dict(label=channel_label_list))
    # plot waveform
    curve_fig01.line('time','amp', source=selected_curve_data_bokeh01,\
                   line_color='black')
    # add refference time as a label
    curve_fig01.text('x', 'y', 'label', source=selected_reftime_label_bokeh01)
    # add channel label
    curve_fig01.text('x', 'y', 'label', source=selected_channel_label_bokeh01)
    # change style
    curve_fig01.title.text_font_size = style_parameter['title_font_size']
    curve_fig01.title.align = 'center'
    curve_fig01.title.text_font_style = 'normal'
    curve_fig01.xaxis.axis_label = style_parameter['curve_xlabel']
    curve_fig01.xaxis.axis_label_text_font_style = 'normal'
    curve_fig01.xaxis.axis_label_text_font_size = xlabel_fontsize
    curve_fig01.xaxis.major_label_text_font_size = xlabel_fontsize
    curve_fig01.yaxis.axis_label = style_parameter['curve_ylabel']
    curve_fig01.yaxis.axis_label_text_font_style = 'normal'
    curve_fig01.yaxis.axis_label_text_font_size = xlabel_fontsize
    curve_fig01.yaxis.major_label_text_font_size = xlabel_fontsize
    curve_fig01.toolbar.logo = None
    curve_fig01.toolbar_location = 'above'
    curve_fig01.toolbar_sticky = False
    # --------------------------------------------------------
    curve_fig02 = Figure(plot_width=style_parameter['curve_plot_width'], plot_height=style_parameter['curve_plot_height'], \
                       y_range=(-max_waveform_amp*1.05,max_waveform_amp*1.05), \
                       x_range=(0,max_waveform_length),\
                    tools=['save','box_zoom','ywheel_zoom','xwheel_zoom','reset','crosshair','pan']) 
    #
    curve_index = 1
    select_curve_data = plotting_list[dot_default_index][curve_index]
    select_curve_time = time_list[dot_default_index][curve_index]
    selected_curve_data_bokeh02 = ColumnDataSource(data=dict(time=select_curve_time,amp=select_curve_data))
    select_channel_label = channel_label_list[dot_default_index][curve_index]
    selected_channel_label_bokeh02 = ColumnDataSource(data=dict(x=[style_parameter['curve_channel_label_x']],\
                                                                y=[style_parameter['curve_channel_label_y']],\
                                                                label=[select_channel_label]))
    # plot waveform
    curve_fig02.line('time','amp', source=selected_curve_data_bokeh02,\
                   line_color='black')
    # add channel label
    curve_fig02.text('x', 'y', 'label', source=selected_channel_label_bokeh02)
    # change style
    curve_fig02.title.text_font_size = style_parameter['title_font_size']
    curve_fig02.title.align = 'center'
    curve_fig02.title.text_font_style = 'normal'
    curve_fig02.xaxis.axis_label = style_parameter['curve_xlabel']
    curve_fig02.xaxis.axis_label_text_font_style = 'normal'
    curve_fig02.xaxis.axis_label_text_font_size = xlabel_fontsize
    curve_fig02.xaxis.major_label_text_font_size = xlabel_fontsize
    curve_fig02.yaxis.axis_label = style_parameter['curve_ylabel']
    curve_fig02.yaxis.axis_label_text_font_style = 'normal'
    curve_fig02.yaxis.axis_label_text_font_size = xlabel_fontsize
    curve_fig02.yaxis.major_label_text_font_size = xlabel_fontsize
    curve_fig02.toolbar.logo = None
    curve_fig02.toolbar_location = 'above'
    curve_fig02.toolbar_sticky = False
    # --------------------------------------------------------
    curve_fig03 = Figure(plot_width=style_parameter['curve_plot_width'], plot_height=style_parameter['curve_plot_height'], \
                       y_range=(-max_waveform_amp*1.05,max_waveform_amp*1.05), \
                       x_range=(0,max_waveform_length),\
                    tools=['save','box_zoom','ywheel_zoom','xwheel_zoom','reset','crosshair','pan']) 
    #
    curve_index = 2
    select_curve_data = plotting_list[dot_default_index][curve_index]
    select_curve_time = time_list[dot_default_index][curve_index]
    selected_curve_data_bokeh03 = ColumnDataSource(data=dict(time=select_curve_time,amp=select_curve_data))
    select_channel_label = channel_label_list[dot_default_index][curve_index]
    selected_channel_label_bokeh03 = ColumnDataSource(data=dict(x=[style_parameter['curve_channel_label_x']],\
                                                                y=[style_parameter['curve_channel_label_y']],\
                                                                label=[select_channel_label]))
    # plot waveform
    curve_fig03.line('time','amp', source=selected_curve_data_bokeh03,\
                   line_color='black')
    # add channel label
    curve_fig03.text('x', 'y', 'label', source=selected_channel_label_bokeh03)
    # change style
    curve_fig03.title.text_font_size = style_parameter['title_font_size']
    curve_fig03.title.align = 'center'
    curve_fig03.title.text_font_style = 'normal'
    curve_fig03.xaxis.axis_label = style_parameter['curve_xlabel']
    curve_fig03.xaxis.axis_label_text_font_style = 'normal'
    curve_fig03.xaxis.axis_label_text_font_size = xlabel_fontsize
    curve_fig03.xaxis.major_label_text_font_size = xlabel_fontsize
    curve_fig03.yaxis.axis_label = style_parameter['curve_ylabel']
    curve_fig03.yaxis.axis_label_text_font_style = 'normal'
    curve_fig03.yaxis.axis_label_text_font_size = xlabel_fontsize
    curve_fig03.yaxis.major_label_text_font_size = xlabel_fontsize
    curve_fig03.toolbar.logo = None
    curve_fig03.toolbar_location = 'above'
    curve_fig03.toolbar_sticky = False
    # --------------------------------------------------------
    map_station_location_js = CustomJS(args=dict(selected_dot_on_map_bokeh=selected_dot_on_map_bokeh,\
                                                            map_station_location_bokeh=map_station_location_bokeh,\
                                                            selected_curve_data_bokeh01=selected_curve_data_bokeh01,\
                                                            selected_curve_data_bokeh02=selected_curve_data_bokeh02,\
                                                            selected_curve_data_bokeh03=selected_curve_data_bokeh03,\
                                                            selected_channel_label_bokeh01=selected_channel_label_bokeh01,\
                                                            selected_channel_label_bokeh02=selected_channel_label_bokeh02,\
                                                            selected_channel_label_bokeh03=selected_channel_label_bokeh03,\
                                                            selected_reftime_label_bokeh01=selected_reftime_label_bokeh01,\
                                                            all_reftime_label_bokeh=all_reftime_label_bokeh,\
                                                            all_channel_label_bokeh=all_channel_label_bokeh,\
                                                            all_curve_data_bokeh=all_curve_data_bokeh), code="""
    var inds = cb_obj.indices
    
    selected_dot_on_map_bokeh.data['index'] = [inds]
    var new_loc = map_station_location_bokeh.data
    
    selected_dot_on_map_bokeh.data['lat'] = [new_loc['map_lat_list'][inds]]
    selected_dot_on_map_bokeh.data['lon'] = [new_loc['map_lon_list'][inds]]
    
    selected_dot_on_map_bokeh.change.emit()
    
    selected_curve_data_bokeh01.data['t'] = all_curve_data_bokeh.data['t'][inds][0]
    selected_curve_data_bokeh01.data['amp'] = all_curve_data_bokeh.data['amp'][inds][0]

    selected_curve_data_bokeh01.change.emit()
    
    selected_curve_data_bokeh02.data['t'] = all_curve_data_bokeh.data['t'][inds][1]
    selected_curve_data_bokeh02.data['amp'] = all_curve_data_bokeh.data['amp'][inds][1]

    selected_curve_data_bokeh02.change.emit()
    
    selected_curve_data_bokeh03.data['t'] = all_curve_data_bokeh.data['t'][inds][2]
    selected_curve_data_bokeh03.data['amp'] = all_curve_data_bokeh.data['amp'][inds][2]

    selected_curve_data_bokeh03.change.emit()
    
    selected_reftime_label_bokeh01.data['label'] = [all_reftime_label_bokeh.data['label'][inds][0]]
    
    selected_reftime_label_bokeh01.change.emit()
    
    selected_channel_label_bokeh01.data['label'] = [all_channel_label_bokeh.data['label'][inds][0]]
    
    selected_channel_label_bokeh01.change.emit()
    
    selected_channel_label_bokeh02.data['label'] = [all_channel_label_bokeh.data['label'][inds][1]]
    
    selected_channel_label_bokeh02.change.emit()
    
    selected_channel_label_bokeh03.data['label'] = [all_channel_label_bokeh.data['label'][inds][2]]
    
    selected_channel_label_bokeh03.change.emit()
    """)
    #
    map_station_location_bokeh.selected.js_on_change('indices', map_station_location_js)
    #
    curve_slider_callback = CustomJS(args=dict(selected_dot_on_map_bokeh=selected_dot_on_map_bokeh,\
                                                map_station_location_bokeh=map_station_location_bokeh,\
                                                selected_curve_data_bokeh01=selected_curve_data_bokeh01,\
                                                selected_curve_data_bokeh02=selected_curve_data_bokeh02,\
                                                selected_curve_data_bokeh03=selected_curve_data_bokeh03,\
                                                selected_channel_label_bokeh01=selected_channel_label_bokeh01,\
                                                selected_channel_label_bokeh02=selected_channel_label_bokeh02,\
                                                selected_channel_label_bokeh03=selected_channel_label_bokeh03,\
                                                selected_reftime_label_bokeh01=selected_reftime_label_bokeh01,\
                                                all_reftime_label_bokeh=all_reftime_label_bokeh,\
                                                all_channel_label_bokeh=all_channel_label_bokeh,\
                                                all_curve_data_bokeh=all_curve_data_bokeh),code="""
    var inds = Math.round(cb_obj.value)
    
    selected_dot_on_map_bokeh.data['index'] = [inds]
    var new_loc = map_station_location_bokeh.data
    
    selected_dot_on_map_bokeh.data['lat'] = [new_loc['map_lat_list'][inds]]
    selected_dot_on_map_bokeh.data['lon'] = [new_loc['map_lon_list'][inds]]
    
    selected_dot_on_map_bokeh.change.emit()
    
    selected_curve_data_bokeh01.data['t'] = all_curve_data_bokeh.data['t'][inds][0]
    selected_curve_data_bokeh01.data['amp'] = all_curve_data_bokeh.data['amp'][inds][0]

    selected_curve_data_bokeh01.change.emit()
    
    selected_curve_data_bokeh02.data['t'] = all_curve_data_bokeh.data['t'][inds][1]
    selected_curve_data_bokeh02.data['amp'] = all_curve_data_bokeh.data['amp'][inds][1]

    selected_curve_data_bokeh02.change.emit()
    
    selected_curve_data_bokeh03.data['t'] = all_curve_data_bokeh.data['t'][inds][2]
    selected_curve_data_bokeh03.data['amp'] = all_curve_data_bokeh.data['amp'][inds][2]

    selected_curve_data_bokeh03.change.emit()
    
    selected_reftime_label_bokeh01.data['label'] = [all_reftime_label_bokeh.data['label'][inds][0]]
    
    selected_reftime_label_bokeh01.change.emit()
    
    selected_channel_label_bokeh01.data['label'] = [all_channel_label_bokeh.data['label'][inds][0]]
    
    selected_channel_label_bokeh01.change.emit()
    
    selected_channel_label_bokeh02.data['label'] = [all_channel_label_bokeh.data['label'][inds][1]]
    
    selected_channel_label_bokeh02.change.emit()
    
    selected_channel_label_bokeh03.data['label'] = [all_channel_label_bokeh.data['label'][inds][2]]
    
    selected_channel_label_bokeh03.change.emit()
    """)
    curve_slider = Slider(start=0, end=ncurve-1, value=style_parameter['curve_default_index'], \
                          step=1, title=style_parameter['curve_slider_title'], width=style_parameter['map_view_plot_width'],\
                          height=50, callback=curve_slider_callback)
    
    # ==============================
    # annotating text
    annotating_fig01 = Div(text=style_parameter['annotating_html01'], \
        width=style_parameter['annotation_plot_width'], height=style_parameter['annotation_plot_height'])
    annotating_fig02 = Div(text=style_parameter['annotating_html02'],\
        width=style_parameter['annotation_plot_width'], height=style_parameter['annotation_plot_height'])
    # ==============================
    output_file(filename,title=style_parameter['html_title'],mode=style_parameter['library_source'])
    #
    left_fig = Column(curve_slider, map_view, annotating_fig01, width=style_parameter['left_column_width'] )
    
    right_fig = Column(curve_fig01, curve_fig02, curve_fig03, annotating_fig02, width=style_parameter['right_column_width'])
    layout = Row(left_fig, right_fig)
    save(layout)
    loc_slider.value = loc_val
    changer = 0
    f1.arrow_source.data = dict(xS=[], xE=[], yS=[], yE=[], lW = [])
    f2.arrow_source.data = dict(xS=[], xE=[], yS=[], yE=[], lW = [])

button.on_click(button_fun)
rbutton.on_click(init)
init()
create_orig(orig)
ps = 0.3
plot = Figure(tools = "",title="Maxwell",title_location = "above", x_range=(0.1-ps,0.8+ps), y_range=(0.0,1.0))
plot.line(x='x', y='y', source=orig.pts, color='Black',line_width=3)
plot.line(x='x', y='y', source=f1.pts, color="#808080",line_width=5)
plot.line(x='x', y='y', source=f2.pts, color="#E37222",line_width=5)
plot.line(x='x', y='y', source=t_line, color="Black",line_width=5)
plot.triangle(x='x', y='y', size = 'size', source= f1.tri,color="#808080", line_width=2)
plot.triangle(x='x', y='y', size = 'size', source= f2.tri,color="#E37222", line_width=2)
plot.axis.visible = False
plot.outline_line_width = 7
plot.outline_line_alpha = 0.3
plot.outline_line_color = "Black"
plot.title.text_color = "black"
plot.title.text_font_style = "bold"
plot.title.align = "center"


labels1 = LabelSet(x='x', y='y', text='name', level='glyph',
              x_offset=0, y_offset=0, source=f1.label, render_mode='canvas')
labels2 = LabelSet(x='x', y='y', text='name', level='glyph',
              x_offset=0, y_offset=0, source=f2.label, render_mode='canvas')
plot.line(x='x', y='y', source=col2.floor, color='black', line_width=6)
plot.line(x='x', y='y', source=col3.floor, color='black', line_width=6)
plot.line(x='x', y='y', source=col4.floor, color='black', line_width=6)
#Create walls for columns that require a wall:
plot.line(x='x', y='y', source=col2.wall, color='black', line_width=6)
plot.line(x='x', y='y', source=col3.wall, color='black', line_width=6)
plot.multi_line(xs='x', ys='y', source=col4.wall, color='black', line_width=6)
#Create circles for columns that have pins:
plot.circle(x='x', y='y', source=col2.cir1, color='#0065BD', size=10)
plot.circle(x='x', y='y', source=col2.cir2, color='#0065BD', size=10)
plot.circle(x='x', y='y', source=col3.cir2, color='#0065BD', size=10)
#Create the shapes of the ends of the columns:
plot.triangle(x='x',
              y='y',
              source=col2.tri1,
              color='black',
              angle=0.0,
              fill_alpha=0,
              size=20)
plot.triangle(x='x',
              y='y',
              source=col2.tri2,
              color='black',
              angle=np.pi / 2,
              fill_alpha=0,
              size=20)
plot.triangle(x='x',
              y='y',
              source=col3.tri2,
              color='black',
              angle=np.pi / 2,
Example #10
0
    'RV', 'Space Transits', 'Ground Transits', 'Microlensing', 'Direct Imaging'
]

checkbox_button_group = CheckboxGroup(
    labels=["RV", "Transits", "Microlensing", "Direct Imaging"],
    active=[0, 1, 2, 3])

# transits - ground
tground = Table.read(
    '/Users/tumlinson/Dropbox/LUVOIR_STDT/luvoir_simtools/planetspace/transit_ground.dat',
    format='ascii',
    names=['name', 'msini', 'semi', 'mstar'])
a_rad = 2.7 * tground['mstar']
tground_syms = p1.triangle(tground['semi'] / a_rad,
                           tground['msini'] * mjup,
                           color='lightblue',
                           fill_alpha=0.8,
                           line_alpha=1.,
                           size=8)

# transits - space
tspace = Table.read(
    '/Users/tumlinson/Dropbox/LUVOIR_STDT/luvoir_simtools/planetspace/transit_space.dat',
    format='ascii',
    names=['name', 'msini', 'semi', 'mstar'])
a_rad = 2.7 * tspace['mstar']
tground_syms = p1.diamond(tspace['semi'] / a_rad,
                          tspace['msini'] * mjup,
                          color='darkblue',
                          fill_alpha=0.4,
                          line_alpha=1.,
                          size=8)
#creation of the a and b scale reference things:
plot.multi_line(
    [[orig.x0, orig.xf], [orig.x0, orig.x0], [orig.xf, orig.xf]],
    [[0, 0], [0 - abshift, 0 + abshift], [0 - abshift, 0 + abshift]],
    color=["black", "black", "black"],
    line_width=1)
plot.multi_line(
    [[xb, xb], [xb - abshift, xb + abshift], [xb - abshift, xb + abshift]],
    [[orig.y0, orig.yf], [orig.y0, orig.y0], [orig.yf, orig.yf]],
    color=["black", "black", "black"],
    line_width=1)

#Frame bases
plot.triangle(x='x',
              y='y',
              size='size',
              source=default,
              color="grey",
              line_width=2)
plot.triangle(x='x',
              y='y',
              size='size',
              source=MBD.f1.tri,
              color=MBD.f1color,
              line_width=2)
plot.triangle(x='x',
              y='y',
              size='size',
              source=MBD.f2.tri,
              color=MBD.f2color,
              line_width=2)
Example #12
0
               # set visual properties for selected glyphs
               selection_color=c_ztfr,
               selection_alpha=a_ztfr,
               # set visual properties for non-selected glyphs
               nonselection_color=c_ztfr,
               nonselection_alpha=a_ztfr,
               legend = 'ZTF-r')


# Plot LCO g and r light curve data
f_lcog = fig_lc.triangle('x', 'y', source=source_lco_g, size=7, 
               # Set defaults
               fill_color=c_lcog, line_color=c_lcog,
               fill_alpha=a_lcog, line_alpha=a_lcog,
               # set visual properties for selected glyphs
               selection_color=c_lcog,
               selection_alpha=a_lcog,
               # set visual properties for non-selected glyphs
               nonselection_color=c_lcog,
               nonselection_alpha=a_lcog,
               legend = 'LCOGT-g')
f_lcor = fig_lc.diamond('x', 'y', source=source_lco_r, size=9,
               # Set defaults
               fill_color=c_lcor, line_color=c_lcor,
               fill_alpha=a_lcor, line_alpha=a_lcor,                    
               # set visual properties for selected glyphs
               selection_color=c_lcor,
               selection_alpha=a_lcor,
               # set visual properties for non-selected glyphs
               nonselection_color=c_lcor,
               nonselection_alpha=a_lcor,