def test_patches_hover_still_works_when_a_seleciton_is_preselcted(output_file_url, selenium):
    # This tests an edge case interaction when Patches (specifically) is used
    # with a tool that requires hit testing e.g. HitTool AND a selection is
    # pre-made on the data source driving it.
    plot = Plot(
        x_range=Range1d(0, 100),
        y_range=Range1d(0, 100),
        min_border=0
    )
    source = ColumnDataSource(dict(
        xs=[[0, 50, 50, 0], [50, 100, 100, 50]],
        ys=[[0, 0, 100, 100], [0, 0, 100, 100]],
        color=['pink', 'blue']
    ))
    source.selected = {
        '0d': {'glyph': None, 'indices': []},
        '1d': {'indices': [1]},
        '2d': {}
    }
    plot.add_glyph(source, Patches(xs='xs', ys='ys', fill_color='color'))
    plot.add_tools(HoverTool())
    plot.add_layout(LinearAxis(), 'below')
    plot.add_layout(LinearAxis(), 'left')
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Hover plot and test no error
    canvas = selenium.find_element_by_tag_name('canvas')
    actions = ActionChains(selenium)
    actions.move_to_element_with_offset(canvas, 100, 100)
    actions.perform()

    # If this assertion fails then there were likely errors on hover
    assert has_no_console_errors(selenium)
示例#2
0
文件: charts.py 项目: aarora79/sitapt
def draw_heat_map(df, file_name, minimum_feature_contribution):
    # this is the colormap from the original plot
    colors = [
        "#75968f", "#a5bab7", "#c9d9d3", "#e2e2e2", "#dfccce",
        "#ddb7b1", "#cc7878", "#933b41", "#550b1d"
    ]

    # Set up the data for plotting. We will need to have values for every
    # pair of year/month names. Map the rate to a color.
    interval = []
    date = []
    color = []
    value = []
    for d in df['Date']:
        for i in df.columns[COLUMNS_TO_SKIP:]:
            interval.append(i)
            date.append(d)
            percentage = float(df[df['Date'] == d][i])
            value.append(percentage)
            color_value = colors[int(percentage / len(colors))]
            color.append(color_value)

    source = ColumnDataSource(
        #data=dict(month=month, year=year, color=color, rate=rate)
        data=dict(interval=interval, date=date, color=color, value=value)
    )

    feature_name = file_name[:-4]
    #chart_file_name = feature_name + '_hm.html'
    file_name_wo_extn = file_name[:-4]
    chart_file_name = os.path.join(os.path.sep, os.getcwd(), OUTPUT_DIR_NAME, file_name_wo_extn + '_hm.html')
    #output_file(chart_file_name)
    
    output_file(chart_file_name)

    TOOLS = "resize,hover,save,pan,box_zoom,wheel_zoom"
    title = feature_name.upper() + ' distribution from ' + str(df['Date'][0]) + ' to ' + str(df['Date'][len(df) - 1])
    
    p = figure(title=title,
        x_range= list(df['Date']), y_range=list(df.columns[COLUMNS_TO_SKIP:]),
        x_axis_location="above", plot_width=1300, plot_height=500,
        toolbar_location="left", tools=TOOLS)

    p.rect("date", "interval", 1, 1, source=source,
        color="color", 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 = "5pt"
    p.axis.major_label_standoff = 0
    p.xaxis.major_label_orientation = np.pi/3

    hover = p.select(dict(type=HoverTool))
    hover.tooltips = OrderedDict([
        ('date', '@date @interval'),
        ('percentage', '@value'),
    ])

    save(p)      # save the plt
示例#3
0
def test_the_default_titles_settings_and_ensure_outside_any_axes(output_file_url, selenium, screenshot):
    # Testing title rendering of background and border is covered in the
    # label test. The title added to plot as the primary title
    #  should always be outside axes and other side renderers.

    source = ColumnDataSource(data=dict(x=[1, 2], y=[1, 2]))

    def make_plot(location, title_align, two_axes=True):
        plot = Plot(
            plot_width=400, plot_height=200,
            x_range=Range1d(0, 2), y_range=Range1d(0, 2),
            toolbar_location=None,
            title="Title %s - %s" % (location, title_align),
            title_location=location,
        )
        plot.title.title_align = title_align
        plot.add_glyph(source, Circle(x='x', y='y', radius=0.4))
        plot.add_layout(LinearAxis(), location)
        if two_axes:
            plot.add_layout(LinearAxis(), location)
        return plot

    layout = Column(
        make_plot('above', 'left', two_axes=False),  # This is a workaround top doesn't like two axes
        make_plot('right', 'right'),
        make_plot('below', 'center'),
        make_plot('left', 'left')
    )

    # Save the plot and start the test
    save(layout)
    selenium.get(output_file_url)

    # Take screenshot
    assert screenshot.is_valid()
示例#4
0
文件: tsa.py 项目: aarora79/sitapt
def _create_grid_plot_of_trends(df, X, col_list, filename):

    width  = 600
    height = 400
        
    color_palette = [ 'Black', 'Red', 'Purple', 'Green', 'Brown', 'Yellow', 'Cyan', 'Blue', 'Orange', 'Pink']
    i = 0
    #2 columns, so number of rows is total /2 
    row_index = 0
    row_list = []
    row = []
    for col in col_list[1:]: #skip the date column
        # create a new plot
        s1 = figure(x_axis_type = 'datetime', width=width, plot_height=height, title=col + ' trend')
        #seasonal decompae to extract seasonal trends
        decomposition = seasonal_decompose(np.array(df[col]), model='additive', freq=15)  
        s1.line(X, decomposition.trend, color=color_palette[i % len(color_palette)], alpha=0.5, line_width=2)

        row.append(s1)
        if len(row) == 2:
            row_copy = copy.deepcopy(row)
            row_list.append(row_copy)
            row = []
            i = 0
        i += 1
        

    # put all the plots in a grid layout
    p = gridplot(row_list)

    save(vplot(p), filename=filename, title='trends')  
def test_color_bar_placement_and_render(output_file_url, selenium, screenshot):
    plot = Plot(height=HEIGHT, width=WIDTH,
                x_range=Range1d(0,10), y_range=Range1d(0,10),
                toolbar_location=None)

    bar_vertical_right_panel = create_vertical_color_bar_with_log_cmap()
    bar_vertical_right_panel.location = (0, 0)

    bar_vertical_in_frame = create_vertical_color_bar_with_log_cmap()
    bar_vertical_in_frame.location = "top_right"
    bar_vertical_in_frame.title = "Dummy Title"
    bar_vertical_in_frame.title_standoff = 7

    bar_horizontal_below_panel = create_horizontal_color_bar_with_linear_cmap()
    bar_horizontal_below_panel.location = (0, 0)

    bar_horizontal_in_frame = create_horizontal_color_bar_with_linear_cmap()
    bar_horizontal_in_frame.location = "bottom_left"
    bar_horizontal_in_frame.title = "Dummy Title"

    plot.add_layout(bar_vertical_right_panel, 'right')
    plot.add_layout(bar_vertical_in_frame)
    plot.add_layout(bar_horizontal_below_panel, 'below')
    plot.add_layout(bar_horizontal_in_frame)

    # Save the plot and start the test
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Take screenshot
    screenshot.assert_is_valid()
示例#6
0
文件: tsa.py 项目: aarora79/sitapt
def _draw_multiple_line_plot(filename, title, X, y, colors, legend, line_dash, line_width, x_axis_type, x_axis_label, y_axis_label, y_start=0, y_end=10, width=800, height=400):
    
    #output_file(filename, title=title)
    p1 = figure(x_axis_type = x_axis_type, plot_width=width, plot_height=height, y_range=(y_start, y_end))   

    for i in range(len(y)):
        p1.line(X[i], y[i], color=colors[i], legend=legend[i], line_dash=line_dash[i], line_width=line_width[i])
    #p1.multi_line(X, y, color=colors, legend=legend, line_dash=line_dash, line_width=line_width)
    # p1.multi_line(xs=X,
    #             ys=y,
    #             line_color=colors,
    #             line_width=5)
    p1.title = title
    #p1.grid.grid_line_color='Black'
    #p.ygrid[0].grid_line_alpha=0.5
    p1.legend.orientation = "bottom_left"
    p1.grid.grid_line_alpha=0.75
    p1.xaxis.axis_label = x_axis_label
    p1.yaxis.axis_label = y_axis_label
    p1.ygrid.band_fill_color="olive"
    p1.ygrid.band_fill_alpha = 0.25
    p1.ygrid.minor_grid_line_color = 'navy'
    p1.ygrid.minor_grid_line_alpha = 0.1

    save(vplot(p1), filename=filename, title=title)  
示例#7
0
def test_arrow(output_file_url, selenium, screenshot):

    # Have to specify x/y range as labels aren't included in the plot area solver
    plot = figure(height=HEIGHT, width=WIDTH, x_range=(0,10), y_range=(0,10), tools='', toolbar_location="above")

    arrow1 = Arrow(x_start=1, y_start=3, x_end=6, y_end=8,
                   line_color='green', line_alpha=0.7,
                   line_dash='8 4', line_width=5, end=OpenHead()
                   )
    arrow1.end.line_width=8

    arrow2 = Arrow(x_start=2, y_start=2, x_end=7, y_end=7,
                   start=NormalHead(), end=VeeHead()
                   )
    arrow2.start.fill_color = 'indigo'
    arrow2.end.fill_color = 'orange'
    arrow2.end.size = 50

    plot.add_layout(arrow1)
    plot.add_layout(arrow2)

    # Save the plot and start the test
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Take screenshot
    assert screenshot.is_valid()
示例#8
0
def test_label(output_file_url, selenium, screenshot):

    # Have to specify x/y range as labels aren't included in the plot area solver
    plot = Plot(plot_height=HEIGHT, plot_width=WIDTH,
                x_range=Range1d(0, 10), y_range=Range1d(0, 10),
                toolbar_location=None)

    label1 = Label(x=1, y=6, x_offset=25, y_offset=25,
                   text="Demo Label",
                   text_font_size='38pt', text_color='red', text_alpha=0.9,
                   text_baseline='bottom', text_align='left',
                   background_fill_color='green', background_fill_alpha=0.2,
                   angle=15, angle_units='deg',
                   render_mode='canvas')

    label2 = Label(x=3, y=5.5, text="(I'm Canvas)", text_font_size='20pt',
                   border_line_color='black', border_line_width=2, border_line_dash='8 4',
                   render_mode='canvas')

    label3 = Label(x=1, y=2, x_offset=25, y_offset=25,
                   text="Demo Label",
                   text_font_size='38pt', text_color='red', text_alpha=0.9,
                   text_baseline='bottom', text_align='left',
                   background_fill_color='green', background_fill_alpha=0.2,
                   angle=0.261, angle_units='rad',
                   render_mode='css')

    label4 = Label(x=3, y=1.0, text="(I'm CSS)", text_font_size='20pt',
                   border_line_color='black', border_line_width=2, border_line_dash='8 4',
                   render_mode='css')

    label_above = Label(
        x=0, y=0, text="Label in above panel", x_units='screen', y_units='screen',
        text_font_size='38pt', text_color='firebrick', text_alpha=0.9,
    )

    label_left = Label(
        x=0, y=0, text="Label in left panel",
        x_units='screen', y_units='screen', angle=90, angle_units='deg',
        text_font_size='18pt', text_color='firebrick', text_alpha=0.9,
        background_fill_color='aliceblue', text_baseline='top',
    )

    plot.add_layout(LinearAxis(), 'below')
    plot.add_layout(LinearAxis(), 'left')

    plot.add_layout(label1)
    plot.add_layout(label2)
    plot.add_layout(label3)
    plot.add_layout(label4)
    plot.add_layout(label_above, 'above')
    plot.add_layout(label_left, 'left')

    # Save the plot and start the test
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Take screenshot
    screenshot.assert_is_valid()
示例#9
0
def test_lasso_select(output_file_url, selenium):
    plot = generate_plot()

    #limit to one callback on click release
    plot.add_tools(LassoSelectTool(select_every_mousemove=False))

    # Save the plot and start the test
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Drag a lasso selection area around middle point
    canvas = selenium.find_element_by_tag_name('canvas')

    actions = ActionChains(selenium)
    actions.move_to_element_with_offset(canvas, PLOT_DIM * 0.25, PLOT_DIM * 0.25)
    actions.click_and_hold()
    actions.move_by_offset(0, PLOT_DIM * 0.5)
    actions.move_by_offset(PLOT_DIM * 0.5, 0)
    actions.move_by_offset(0, PLOT_DIM * -0.5)
    actions.release()
    actions.perform()

    # Get the alert from box select and assert that the middle item is selected
    alert = selenium.switch_to_alert()
    assert alert.text == 'middle'
示例#10
0
文件: charts.py 项目: aarora79/sitapt
def draw_stacked_chart(df, file_name, minimum_feature_contribution):
    logger.info('drawing stacked chart for ' + file_name)

    
    col_list, remaining_features, remaining_features_values = va_utils.get_significant_features(df, minimum_feature_contribution)   

    X = list(df['Date'])
    data = OrderedDict()
    for col in col_list:
        data[col] = df[col]
    #finally add the remaining features as a combined single column
    data['everything-else'] = remaining_features_values

    feature_name = file_name[:-4]
    #chart_file_name = feature_name + '.html'
    #output_file(chart_file_name)
    file_name_wo_extn = file_name[:-4]
    chart_file_name = os.path.join(os.path.sep, os.getcwd(), OUTPUT_DIR_NAME, file_name_wo_extn + '_stacked_chart.html')
    output_file(chart_file_name)


    title = feature_name.upper() + ' distribution from ' + str(df['Date'][0]) + ' to ' + str(df['Date'][len(df) - 1])
    bar = Bar(data, X, title= title, stacked=True, legend='bottom_left', tools='hover,pan,wheel_zoom,box_zoom,reset,resize', width=1300, height=500)
    # glyph_renderers = bar.select(dict(type=GlyphRenderer))
    # bar_source = glyph_renderers[0].data_source

    # hover = bar.select(dict(type=HoverTool))
    # hover.tooltips = [
    #   ('name',' @cat'),
    #   ('number', '$y'),  
    # ]
    save(bar)
    logger.info('saved the chart in ' + chart_file_name)
示例#11
0
 def save(self, title='Training Results'):
     if len(self.figures) > 0:
         if os.path.isfile(self.plot_path):
             os.remove(self.plot_path)
         output_file(self.plot_path, title=title)
         plot = column(*self.figures)
         save(plot)
         self.clear()
     self.results.to_csv(self.path, index=False, index_label=False)
示例#12
0
文件: bokeh.py 项目: jakirkham/bokeh
    def __init__(self, model, driver, output_file_url, has_no_console_errors):
        self._driver = driver
        self._model = model
        self._has_no_console_errors = has_no_console_errors

        save(self._model)

        self._driver.get(output_file_url)

        self.init_results()
示例#13
0
def test_y_range_does_not_pan_above_y_max(output_file_url, selenium):
    y_range_max = 4
    plot = make_pan_plot_with_callback(yr=Range1d(0, 3, bounds=(None, y_range_max)))
    save(plot)
    selenium.get(output_file_url)

    # Pan plot and test for new range value
    pan_plot(selenium, pan_x=50, pan_y=150)
    new_range_end = float(selenium.execute_script("""alert(window.get_y_range_end())"""))
    selenium.switch_to_alert().dismiss()  # This is not necessary but assists debugging
    assert round(new_range_end) == y_range_max
示例#14
0
def test_reversed_x_range_does_not_pan_left_of_x_max(output_file_url, selenium):
    x_range_max = 4
    plot = make_pan_plot_with_callback(xr=Range1d(3, 0, bounds=(None, x_range_max)))
    save(plot)
    selenium.get(output_file_url)

    # Pan plot and test for new range value
    pan_plot(selenium, pan_x=200, pan_y=0)
    new_range_end = float(selenium.execute_script("""alert(window.get_x_range_start())"""))
    selenium.switch_to_alert().dismiss()  # This is not necessary but assists debugging
    assert round(new_range_end) == x_range_max
示例#15
0
def test_reversed_y_range_does_not_pan_below_y_max(output_file_url, selenium):
    y_range_max = 4
    plot = make_pan_plot_with_callback(yr=Range1d(3, 0, bounds=(None, y_range_max)))
    save(plot)
    selenium.get(output_file_url)

    # Pan plot and test for new range value
    pan_plot(selenium, pan_x=50, pan_y=-150)
    new_range_end = float(selenium.execute_script("""alert(window.get_y_range_start())"""))
    selenium.switch_to_alert().dismiss()
    assert round(new_range_end) == y_range_max
示例#16
0
def test_x_range_does_not_pan_left_of_x_min(output_file_url, selenium):
    x_range_min = -1
    plot = make_pan_plot_with_callback(xr=Range1d(0, 3, bounds=(x_range_min, None)))
    save(plot)
    selenium.get(output_file_url)

    # Pan plot and test for new range value
    pan_plot(selenium, pan_x=200, pan_y=0)
    new_range_start = float(selenium.execute_script("""alert(window.get_x_range_start())"""))
    selenium.switch_to_alert().dismiss()
    assert round(new_range_start) == x_range_min
示例#17
0
def test_reversed_y_range_does_not_pan_below_y_max(output_file_url, selenium):
    y_range_max = 4
    plot = make_plot(yr=Range1d(3, 0, bounds=(None, y_range_max)))
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Pan plot and test for new range value
    pan_plot(selenium, pan_x=50, pan_y=-150)
    new_range_end = float(selenium.execute_script("""alert(Bokeh.index['plot-id'].model.y_range.max)"""))
    selenium.switch_to_alert().dismiss()
    assert round(new_range_end) == y_range_max
示例#18
0
	def output_charts(self,name,period, bot,top,fast_k,fast_d):
		candlestick = self.candlestick(name)
		rsi = self.rsi(candlestick,period,bot,top)
		stoch_rsi = self.stoch_rsi(candlestick,period,fast_k,fast_d)
		macd = self.macd(candlestick)

		self.plot_results(candlestick,rsi,stoch_rsi,macd)

		l=layout([[candlestick], [rsi],[stoch_rsi],[macd]])
		output_file("charts/"+name.replace("/","")+".html",title="Crypto chart for "+name)
		#show(l)
		save(l)
示例#19
0
def test_x_range_does_not_pan_left_of_x_min(output_file_url, selenium):
    x_range_min = -1
    plot = make_plot(xr=Range1d(0, 3, bounds=(x_range_min, None)))
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Pan plot and test for new range value
    pan_plot(selenium, pan_x=150, pan_y=0)
    new_range_start = float(selenium.execute_script("""alert(Bokeh.index['plot-id'].model.x_range.start)"""))
    selenium.switch_to_alert().dismiss()
    assert round(new_range_start) == x_range_min
示例#20
0
def test_x_range_does_not_pan_right_of_x_max(output_file_url, selenium):
    x_range_max = 4
    plot = make_plot(xr=Range1d(0, 3, bounds=(None, x_range_max)))
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Pan plot and test for new range value
    pan_plot(selenium, pan_x=-150, pan_y=0)
    new_range_end = float(selenium.execute_script("""alert(Bokeh.index['plot-id'].model.x_range.end)"""))
    selenium.switch_to_alert().dismiss()  # This is not necessary but assists debugging
    assert round(new_range_end) == x_range_max
示例#21
0
def test_selection_tool_make_selection(output_file_url, selenium):
    plot = make_plot()

    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    perform_box_selection(selenium, (50, 200), (450, 400))

    code = "return Bokeh.index['plot-id'].model.select_one('rect-glyph').data_source.selected['1d'].indices"
    selected = selenium.execute_script(code)
    assert selected == [0, 1]
示例#22
0
def test_y_range_does_not_pan_below_y_min(output_file_url, selenium):
    y_range_min = -1
    plot = make_pan_plot_with_callback(yr=Range1d(0, 3, bounds=(y_range_min, None)))
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Pan plot and test for new range value
    pan_plot(selenium, pan_x=50, pan_y=-150)
    new_range_start = float(selenium.execute_script("""alert(window.get_y_range_start())"""))
    selenium.switch_to_alert().dismiss()  # This is not necessary but assists debugging
    assert round(new_range_start) == y_range_min
示例#23
0
def test_wheel_zoom_is_deselected_by_default(output_file_url, selenium):

    # Make plot and add a taptool callback that generates an alert
    plot = make_plot()

    # Save the plot and start the test
    save(plot)
    selenium.get(output_file_url)

    # Tap the plot and test for alert
    scroll_button = get_non_stale_scroll_button(selenium)
    scroll_classes = scroll_button.get_attribute('class')
    assert 'active' not in scroll_classes
示例#24
0
def test_selection_tool_selection_ending_outside_frame_makes_selection(output_file_url, selenium):
    plot = make_plot()

    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # make selection ending outside of frame
    perform_box_selection(selenium, (50, 50), (1000, 1000))

    code = "return Bokeh.index['plot-id'].model.select_one('rect-glyph').data_source.selected['1d'].indices"
    selected = selenium.execute_script(code)
    assert selected == [0,1,2]
示例#25
0
def test_responsive_chart_starts_at_correct_size(output_file_url, selenium):
    hist = Histogram(df['mpg'], title="MPG Distribution", responsive=True)
    save(hist)

    selenium.set_window_size(width=1000, height=600)
    selenium.get(output_file_url)

    canvas = selenium.find_element_by_tag_name('canvas')
    wait_for_canvas_resize(canvas, selenium)

    # Canvas width should be just under 1000
    assert canvas.size['width'] > 900
    assert canvas.size['width'] < 1000
示例#26
0
def test_reversed_y_range_does_not_pan_above_y_min(output_file_url, selenium):
    y_range_min = -1
    plot = make_pan_plot_with_callback(yr=Range1d(3, 0, bounds=(y_range_min, None)))
    save(plot)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)

    # Pan plot and test for new range value
    pan_plot(selenium, pan_x=50, pan_y=150)

    new_range_start = float(selenium.execute_script("""alert(window.get_y_range_end())"""))
    selenium.switch_to_alert().dismiss()
    assert round(new_range_start) == y_range_min
示例#27
0
def test_wheel_zoom_can_be_selected(output_file_url, selenium):

    # Make plot and add a taptool callback that generates an alert
    plot = make_plot()

    # Save the plot and start the test
    save(plot)
    selenium.get(output_file_url)

    # Tap the plot and test for alert
    scroll_button = get_non_stale_scroll_button(selenium)
    scroll_button.click()
    scroll_classes = scroll_button.get_attribute("class")
    assert "active" in scroll_classes
示例#28
0
def test_responsive_plot_starts_at_correct_size(output_file_url, selenium):
    plot = figure(responsive=True, title="Test Me")
    plot.scatter([1, 2, 3], [3, 2, 3])
    save(plot)

    selenium.set_window_size(width=1000, height=600)
    selenium.get(output_file_url)

    canvas = selenium.find_element_by_tag_name('canvas')
    wait_for_canvas_resize(canvas, selenium)

    # Canvas width should be just under 1000
    assert canvas.size['width'] > 900
    assert canvas.size['width'] < 1000
示例#29
0
def test_range_with_callback_triggers_alert(output_file_url, selenium):
    # Simple test to ensure range callbacks are working
    # Rest of tests in this file depend on range callback.

    plot = make_pan_plot_with_callback()
    initial_start = plot.x_range.start
    save(plot)
    selenium.get(output_file_url)

    # Pan plot and test for new range value
    pan_plot(selenium, pan_x=100, pan_y=100)
    new_range_start = float(selenium.execute_script("""alert(window.get_x_range_start())"""))
    selenium.switch_to_alert().dismiss()
    assert new_range_start < initial_start
示例#30
0
def test_scale_width_maintains_a_minimum_height(output_file_url, selenium):
    # The aspect ratio is landscape but should not allow a height less than 100
    plot = make_sizing_mode_plot(1200, 600, sizing_mode='scale_width')
    save(plot)

    # Open the browser with the plot and resize the window small
    selenium.set_window_size(width=100, height=600)
    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)
    canvas = selenium.find_element_by_tag_name('canvas')
    wait_for_canvas_resize(canvas, selenium)

    # Plot should have been shrunk somewhat
    assert canvas.size['height'] < 600
    assert canvas.size['height'] >= 100
示例#31
0
      {% for root in roots %}
        {{ embed(root) }}
      {% endfor %}
    </div>
    {{ plot_script }}
  </body>
</html>
""")

axes = [
    "a",
    "b",
    "l",
    "r",
    "al",
    "ar",
    "bl",
    "br",
    "alr",
    "blr",
    "lab",
    "rab",
    "ab",
    "lr",
    "ablr",
    "",
]

figures = list(map(make_figure, axes))
save(figures, template=template)
示例#32
0
    color_bar = ColorBar(color_mapper=color_mapper,
                         ticker=LogTicker(),
                         border_line_color=None,
                         location=(0, 0),
                         label_standoff=12)

    #p.add_layout(color_bar, 'left')

    p.grid.grid_line_color = 'red'

    p.patches('x',
              'y',
              source=source,
              fill_color={
                  'field': 'rate',
                  'transform': color_mapper
              },
              fill_alpha=0.7,
              line_color="black",
              line_width=0.5)

    hover = p.select_one(HoverTool)
    hover.point_policy = "follow_mouse"
    hover.tooltips = [
        ("Provinsi", "@name"),
        #("Harga(Rp/100 Kg)", "@rate"),
        ("(Long, Lat)", "($x, $y)"),
    ]
    print(save(p, filename='good' + '.html'))
def plot_spike_psth(spike_times, stim_data, channel_name,
                    unsorted_save_folder):

    ################################ get the TRIAL TIMES  ###################################
    #########################################################################################

    trials = range(len(stim_data))
    stim_orientation, idx, inv = np.unique(stim_data.orientations,
                                           return_index=True,
                                           return_inverse=True)
    stim_dict = dict()
    for ori in stim_orientation:
        stim_dict[str(ori)] = stim_data.orientations[
            stim_data.orientations ==
            ori].index.values  ### put indices of stim_data that correspond to this orientation, from inv
        #### ^ stim_dict gives indices of stim_data for given orientations.

    trial_range = 1.0  # 0.5
    #trial_time_vector = np.linspace(-trial_range,trial_range,300) ## 300=trial length, in LFP sample (LFP fs=300 samples/sec)

    ###### Gather spike data from behavior trials:
    spikes = []

    for i in trials:
        print 'i = ', i

        trial_time = stim_data.times[i]

        print 'trial_time = ', trial_time

        temp_idx = (spike_times < trial_time + trial_range) & (
            spike_times > trial_time - trial_range)

        #print 'temp_idx = ', temp_idx
        temp_trial = spike_times[temp_idx] - trial_time

        spikes.append(temp_trial)

    stim_data['spikes'] = spikes

    stim_data.to_csv(unsorted_save_folder + '/stim_data_spikes.csv')

    print 'STIM_DATA = ', stim_data

    tuning_dict = dict()

    for ori in stim_dict:

        print stim_data.spikes[stim_dict[ori]]

        raster = figure(width=1000,
                        height=400,
                        y_axis_label='Trial Number',
                        title='Raster')
        all_spike_times = []

        num_trials = len(stim_data.spikes[stim_dict[ori]])  #  len(trials)
        trials_by_ori = range(num_trials)
        bin_time = 0.025  # 25 ms bins
        num_bins = np.int(trial_range * 2 / bin_time)
        time_vec = np.linspace(-trial_range, trial_range, num_bins)
        tuning_time = 0.1  # sec. window in which to look for response modulation, before and after stim onset.
        alltrials_modulation = []

        for trial in trials_by_ori:

            trial_time = stim_data.spikes[
                stim_dict[ori][trial]]  ## spike times on this trial
            num_spikes_ontrial = len(trial_time)

            print 'trial %d has %d spikes' % (trial, num_spikes_ontrial)

            all_spike_times.append(trial_time)

            ####### MAKE RASTER
            raster.segment(x0=trial_time,
                           y0=np.repeat(trial, num_spikes_ontrial),
                           x1=trial_time,
                           y1=np.repeat(trial + 1, num_spikes_ontrial),
                           color="black",
                           line_width=0.5)

            #### get histogram for each trial:
            temp_hist, edges = np.histogram(trial_time,
                                            bins=num_bins,
                                            range=[-trial_range, trial_range])

            spikes_after_stim = temp_hist[(edges < tuning_time) & (edges >= 0)]
            spikes_before_stim = temp_hist[(edges < 0)
                                           & (edges > -tuning_time)]

            print 'spikes_after_stim = ', spikes_after_stim
            print 'spikes_before_stim = ', spikes_before_stim

            trial_modulation = np.sum(spikes_after_stim) - np.sum(
                spikes_before_stim
            )  ## total spikes in 100ms after - total spikes in 100ms before stim.
            alltrials_modulation.append(
                trial_modulation /
                tuning_time)  ## divide by 0.1 to get #spikes/second

            if trial == 0:
                raw_hist = temp_hist
            else:
                raw_hist = np.vstack([raw_hist, temp_hist])

        np.savez(unsorted_save_folder + '/raw_histogram_%s.npz' % str(ori),
                 raw_hist=raw_hist)

        print 'length of all_spike_times = ', len(all_spike_times)
        print 'shape of overall histo = ', raw_hist.shape

        histo_fig = figure(width=1000,
                           plot_height=500,
                           y_axis_label='Firing Rate (Hz)',
                           x_axis_label='Time (sec)',
                           x_range=raster.x_range)

        all_spike_times = np.concatenate(
            all_spike_times).ravel()  ## make one long vector of spike times.

        #hist, edges = np.histogram(all_spike_times, bins=num_bins)

        hist = np.mean(raw_hist, axis=0)
        hist_std = np.std(raw_hist, axis=0)
        print 'shape of averaged hist = ', hist.shape

        bin_width = np.diff(edges)[0]  # in seconds.

        print 'hist, edges: ', hist, edges

        print 'bin_width = ', bin_width

        print 'num_trials = ', num_trials

        print 'shape of hist, edges = ', hist.shape, edges.shape

        histo_fig.quad(
            top=hist / bin_width,
            bottom=0,
            left=edges[:-1],
            right=edges[1:],  ## hist/bin_width = firing rate in Hz
            fill_color="#036564",
            line_color="#036564")  #033649

        #histo_fig.line(edges[:-1]+bin_width/2, hist/bin_width)
        ### get the number of spikes in the 100ms before and after stim presentation:

        tuning_dict[ori] = (
            np.mean(alltrials_modulation), stats.sem(alltrials_modulation)
        )  ## (np.mean(hist[20:24])/np.mean(hist[16:20]))/bin_width/num_trials

        print 'tuning dict = ', tuning_dict

        print 'np.mean(alltrials_modulation) = ', np.mean(alltrials_modulation)
        print 'np.std(alltrials_modulation) = ', np.std(alltrials_modulation)

        #################################### instead of histogram, plot mean+std of numbers of spikes on each trial (binned).
        firingrate_line = figure(width=1000,
                                 plot_height=500,
                                 y_axis_label='Firing Rate (Hz)',
                                 x_axis_label='Time (sec)',
                                 x_range=raster.x_range)

        hist_smooth = ndimage.filters.gaussian_filter1d(hist / bin_width,
                                                        sigma=0.5)

        firingrate_line.line(edges[:-1] + bin_width / 2, hist_smooth)
        std_x = (edges[:-1] + bin_width / 2).tolist()
        std_y1 = (-hist_std + hist / bin_width).tolist()
        std_y2 = (hist_std + hist / bin_width).tolist()

        print 'std_x = ', std_x
        print 'std_y1 ', std_y1
        print 'std_y2 = ', std_y2

        std_x.extend(np.flipud(std_x).tolist())
        std_y1.extend(np.flipud(std_y2).tolist())

        print 'std_plot_x = ', std_x
        print 'std_plot_y = ', std_y1

        firingrate_line.patch(std_x, std_y1, color="#99d8c9")
        #firingrate_line.patch(edges[:-1]+bin_width/2,hist_std+hist/bin_width)
        #firingrate_line.patch(edges[:-1]+bin_width/2,hist/bin_width+hist_std)

        all_spike_times = None

        #histo_fig.line(win_x,[w/win_size/len(stim_dict[ori]) for w in windowd_spike_vec],color='magenta')

        output_file(unsorted_save_folder + '/spike_histogram_' + str(ori) +
                    '.html')
        grid = gridplot([[raster], [histo_fig],
                         [firingrate_line]])  #,[firingrate_line]

        save(grid)

    #stim_name = 'orientation_' + ori
    #output_file(save_folder + '/psth_'+str(stim_name)+'.html')
    #save(raster)

        #fig.savefig((unsorted_save_folder + str(channel_name) + '.pdf'))

    ## plot tuning curve:

    tuning_fig = figure(width=1000,
                        plot_height=500,
                        y_axis_label='Spikes/Sec After - Before Stim',
                        x_axis_label='Orientations (deg)')

    #### plot means:
    tuning_fig.scatter(tuning_dict.keys(),
                       [means[0] for means in tuning_dict.values()])
    #### plot stds:
    ## get x and y coordinates for the lines:
    err_xs = []
    err_ys = []

    for x, y, yerr in zip(tuning_dict.keys(),
                          [means[0] for means in tuning_dict.values()],
                          [stds[1] for stds in tuning_dict.values()]):
        err_xs.append((x, x))
        err_ys.append((y - yerr, y + yerr))
    tuning_fig.multi_line(err_xs, err_ys)

    output_file(unsorted_save_folder + '/tuning.html')
    save(tuning_fig)
示例#34
0
def status_rect(data,direction,kp_fc,name='traffic map',origin_column='origin_ststus',
                predict_column='predict_status',datetime_column='datetime',time_unit=5):
    #the input dataframe must contain a 'datetime' type column for y axis
    #if no prediction, predict=False
    #check the categories of colormapper and hover tooltips
    
    lane= origin_column.split('_')[0]
    
    data['date'] = data[datetime_column].dt.date.astype(str)
    
    kplist = list(sorted(set(data['kp'])))
    ws={}
    fkp={}
    kpac=0
    for ind, kp in enumerate(kplist):
        if ind ==0:
            ws[kp]=kp+((kplist[ind+1]-kp)/2)
        elif kp == kplist[-1]:
            ws[kp]=((kp-kplist[ind-1])/2)*2
        else:
            ws[kp]=((kp-kplist[ind-1])/2)+((kplist[ind+1]-kp)/2)
        fkp[kp]=kpac+(ws[kp]/2)
        kpac+=ws[kp]
            
    data['width']=data.kp.replace(ws)
    data['f_kp']=data.kp.replace(fkp)
    
    source = ColumnDataSource(data)
    
    toolbar = 'hover,save,pan,box_zoom,reset,wheel_zoom'
    
    
    #the base-plot setting
    p= figure(title=name,
              x_range= Range1d(end = max(kplist)+ws[max(kplist)],start =0),
              y_range=Range1d(start = max(data[datetime_column]),end =min(data[datetime_column])),
              y_axis_type='datetime', plot_height = (len(data[datetime_column].unique())*3)+100,
              x_axis_location='above',tools=toolbar,
              plot_width = 20*len(kplist))
    
    p.xaxis.axis_label= 'KP(km)'
    p.yaxis.axis_label= 'Time'
    p.yaxis.formatter = DatetimeTickFormatter(minutes=['%Y-%m-%d %H:%M'], days=['%Y-%m-%d %H:%M'],hours =['%Y-%m-%d %H:%M'],
                                              months=['%Y-%m-%d %H:%M'],years=['%Y-%m-%d %H:%M'])
    p.ygrid[0].ticker.desired_num_ticks = int(len(data[datetime_column].unique())/12)
    p.toolbar.logo = None
    p.xaxis.major_label_orientation = 45
    p.xaxis.ticker = kplist
    
    #set axis for facility
    p.extra_x_ranges={'facility':Range1d(end = max(kplist)+ws[max(kplist)],start =0)}
    p.add_layout(LinearAxis(x_range_name='facility',axis_label='facility',
                            ticker=list(kp_fc.keys()),major_label_orientation = 45,
                            formatter=FuncTickFormatter(code="""var kpfc_dict = %s;return kpfc_dict[tick];""" %kp_fc)),
                 'below')
                 
    hover = p.select_one(HoverTool)

    #draw rectangles for original status
    mapper = CategoricalColorMapper(palette=['#cc7878','#c9d9d3','#550b1d','#933b41'],
                                    factors=['congestion','free_flow','traffic_jam','conditional'])
    p.rect('f_kp',datetime_column,
           width='width',height=1000*60*time_unit,source=source,
           fill_color={'field':origin_column,'transform':mapper},fill_alpha = 0.3,
           line_color=None,legend=origin_column)
    
    if predict_column!=None:
    #draw rectangles for predict status
        mapper2 = CategoricalColorMapper(palette=['#c9d9d3','yellow'],
                                         factors=['p_free_flow','p_traffic_jam'])
        p.rect('f_kp','dtime',
               width='width',height=1000*60*time_unit,source=source,
               fill_color={'field':predict_column,'transform':mapper2},fill_alpha = 0.2,
               line_color=None,legend=predict_column)
        
        hover.tooltips = [('kp','@kp'),("date","@date"),("time","@time"),('lane',lane),('speed',"@{}_speed".format(lane)),
                          ('car_vol','@{}_carvol'.format(lane)),('occ','@{}_occ'.format(lane)),
                          ('status','@{}'.format(origin_column)),('p_status','@{}'.format(predict_column))]
    else:
        hover.tooltips = [('kp','@kp'),("date","@date"),("time","@time"),('lane',lane),('speed',"@{}_speed".format(lane)),
                          ('car_vol','@{}_carvol'.format(lane)),('occ','@{}_occ'.format(lane)),
                          ('status','@{}'.format(origin_column))]
      
    output_file('/data/projects/Highway/NEXCO_2017/2_visualization/traffic_per_kp_map/{}.html'.format(name))
    #show(p)
    save(p)
示例#35
0
        case = label_alleles(case, allelic_case, ch_ss_num=5)

    for case in cases.values():
        plot_dict = plot_PTE_case(case, plot_dict, w=1050, h=500)

    # sort the plots. SCL first, channel + repeat after, followed by their
    # size standards.
    plot_keys = sorted([key for key in plot_dict.keys() if 'SCL' not in key])
    scl_keys = sorted([key for key in plot_dict.keys() if 'SCL' in key])
    plot_keys = [*scl_keys, *plot_keys]
    plots = column([plot_dict[ch] for ch in plot_keys], sizing_mode='fixed')

    case_html = case.name + '.html'
    output_file(case_html)
    show(plots)
    save(plots)
    print('Saved {}'.format(case_html))


"""	Next steps
	1. Correctly label regions and peaks on the allelic ladder.
	2. Use allelic ladder to annotate sample peaks.
		a. May need to deal with stutter vs. true allelic peak
	3. Get area under each peak.
		a. Given a list of peaks, get their bases.
		b. Include stutter in area calculation or not? Won't matter so long as we are consistent. Easier to exclude stutter.
"""

alleles = {
    'channel_1': {
        'D8S1179': {
示例#36
0
        [
            selectors_map + map_range_widgets + [radioGroup_level_select] +
            [button_continental_us_only]
            #+[Spacer(background='black',height=2)]
            + [Div(text="<center><i> Time History Animation </i></center>")]
            #+[Spacer(background='black',height=2)]
            + [[spinner_minStepTime, radioGroup_play_controls],
               date_range_slider],
            p_map
        ],
        [selectors_graph + [data_notes], p_graph],
        footer
    ])
    lout.margin = (4, 20, 4, 20)  # top, right, bottom, left
    lout.sizing_mode = 'scale_width'
    save(lout, template=template_ext_js(['jquary', 'pako']))
    # view(output_filename+'.html')
    # view('http://localhost:7800/'+localhost_path+this_filename+'.html')

elif sys.argv[1] == 'mobile':
    print('Making mobile output version')
    lout_mobile = layout([
        heading, [selectors_map] + map_range_widgets,
        [radioGroup_level_select, button_continental_us_only], p_map,
        [spinner_minStepTime, radioGroup_play_controls, date_range_slider],
        p_graph, [[[selectors_graph]], data_notes], footer
    ])
    lout_mobile.margin = (4, 20, 4, 20)  # top, right, bottom, left
    lout_mobile.sizing_mode = 'scale_width'
    save(lout_mobile,
         filename=output_filename + '_mobile.html',
示例#37
0
def test_scale_both_resizes_width_and_height_with_fixed_aspect_ratio(
        output_file_url, selenium):
    # Test that a Bokeh plot embedded in a desktop-ish setting (e.g.
    # a Phosphor widget) behaves well w.r.t. resizing.

    # We want the aspect ratio of the initial plot to be maintained, but we
    # can't measure it perfectly so we test against bounds.
    aspect_ratio = 2
    plot_width = 400 * aspect_ratio
    plot_height = 400
    lower_bound = aspect_ratio * 0.95
    upper_bound = aspect_ratio * 1.05

    plot = make_sizing_mode_plot(plot_width,
                                 plot_height,
                                 sizing_mode='scale_both')
    save(plot)

    # Open the browser with the plot and resize the window to get an initial measure
    selenium.set_window_size(width=1200, height=600)

    selenium.get(output_file_url)
    assert has_no_console_errors(selenium)
    canvas = selenium.find_element_by_tag_name('canvas')

    # Check initial size
    wait_for_canvas_resize(canvas, selenium)
    #
    height1 = canvas.size['height']
    width1 = canvas.size['width']
    aspect_ratio1 = width1 / height1
    assert aspect_ratio1 > lower_bound
    assert aspect_ratio1 < upper_bound

    # Now resize to a smaller width and check again
    selenium.set_window_size(width=800, height=600)
    wait_for_canvas_resize(canvas, selenium)
    #
    height2 = canvas.size['height']
    width2 = canvas.size['width']
    aspect_ratio2 = width2 / height2
    assert aspect_ratio2 > lower_bound
    assert aspect_ratio2 < upper_bound
    assert width2 < width1 - 20
    assert height2 < height1 - 20

    # Now resize back and check again
    selenium.set_window_size(width=1200, height=600)
    wait_for_canvas_resize(canvas, selenium)
    #
    height3 = canvas.size['height']
    width3 = canvas.size['width']
    assert width3 == width1
    assert height3 == height1

    # Now resize to a smaller height and check again
    selenium.set_window_size(width=1200, height=400)
    wait_for_canvas_resize(canvas, selenium)
    #
    height4 = canvas.size['height']
    width4 = canvas.size['width']
    aspect_ratio4 = width4 / height4
    assert aspect_ratio4 > lower_bound
    assert aspect_ratio4 < upper_bound
    assert width4 < width1
    assert height4 < height1

    # Now resize back and check again
    selenium.set_window_size(width=1200, height=600)
    wait_for_canvas_resize(canvas, selenium)
    #
    height5 = canvas.size['height']
    width5 = canvas.size['width']
    assert width5 == width1
    assert height5 == height1
示例#38
0
def make_char():
    states = []
    predictions = []
    with open('predictions.csv') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        line_count = 0
        for row in csv_reader:
            if line_count == 0:
                for state in row:
                    if state == '' or state == 'predicted_cases':
                        continue
                    state = state.replace('state_', "")
                    states.append(state)
                line_count += 1
            else:
                predictions.append(row[-1])
                line_count += 1

    state_resources = []
    beds_total = []
    beds_aval = []
    ven_total = []
    ven_aval = []
    with open('PPE_Datasheet.csv') as csv_file:
        csv_reader = csv.reader(csv_file, delimiter=',')
        line_count = 0
        for row in csv_reader:
            if line_count > 1:
                state_resources.append(row[0])
                beds_total.append(row[1])
                beds_aval.append(row[2])
                ven_total.append(row[3])
                ven_aval.append(row[4])
            else:
                line_count += 1

    resources = [
        'Total Beds', 'Available Beds', 'Total Ventilators',
        'Available Ventilators'
    ]

    data_r = {
        'states': state_resources,
        'Total Beds': beds_total,
        'Available Beds': beds_aval,
        'Total Ventilators': ven_total,
        'Available Ventilators': ven_aval
    }

    # this creates [ ("Apples", "2015"), ("Apples", "2016"), ("Apples", "2017"), ("Pears", "2015), ... ]
    x_r = [(s, r) for s in state_resources for r in resources]
    counts = sum(
        zip(data_r['Total Beds'], data_r['Available Beds'],
            data_r['Total Ventilators'], data_r['Available Ventilators']),
        ())  # like an hstack

    source = ColumnDataSource(
        data=dict(states=states, predictions=predictions, all=predictions))
    source_rr = ColumnDataSource(
        data=dict(x_r=x_r, counts=counts, all_counts=counts))

    p_rr = figure(x_range=FactorRange(*x_r),
                  plot_height=500,
                  plot_width=1200,
                  title="State Resources - June 10th",
                  toolbar_location=None,
                  tools="")

    p_rr.vbar(x='x_r', top='counts', width=0.9, source=source_rr)

    p_rr.y_range.start = 0
    p_rr.x_range.range_padding = 0.1
    p_rr.xaxis.major_label_orientation = 1
    p_rr.xgrid.grid_line_color = None

    p_rr.add_tools(HoverTool(tooltips=[('Number of Resources', '@counts')]))

    p = figure(x_range=source.data['states'],
               plot_height=500,
               plot_width=1200,
               title='Predictions by State - June 10th',
               toolbar_location=None,
               tools="")
    p.vbar(x='states', top='predictions', width=0.5, source=source)
    p.xaxis.major_label_orientation = math.pi / 2
    p.yaxis[0].formatter = NumeralTickFormatter(format='0')
    p.add_tools(
        HoverTool(
            tooltips=[('State',
                       '@states'), ('Predicted Number of Cases',
                                    '@predictions')]))

    callback = CustomJS(args=dict(source=source, source_rr=source_rr),
                        code="""
        var data = source.data;
        var selection = cb_obj.value
        var states = data['states']
        var predictions = data['predictions']
        var all = data['all']
        for (var i = 0; i < states.length; i++) {
            if (selection == 'All States'){
                predictions[i] = all[i]
            }
            else if (selection != states[i]) {
                predictions[i] = 0
            }
            else {
                predictions[i] = all[i]
            }
        }


        var data_rr = source_rr.data;
        var states_rr = data_rr['x_r']
        var resources_rr = data_rr['counts']
        var resources_rr_all = data_rr['all_counts']
        var start = -1

        for (var i = 0; i < states_rr.length; i++) {

            if (selection == 'All States'){
                resources_rr[i] = resources_rr_all[i]
            }
            else if(selection == states_rr[i][0]){
                if(start == -1){
                    start = i
                }
            }
        }

        for (var i = 0; i < states_rr.length; i++){
            if (start != -1){
                if (i >= start && i < (start + 4)){
                    resources_rr[i] = resources_rr_all[i]
                }
                else {
                    resources_rr[i] = 0
                }
            }
            else{
                resources_rr[i] = resources_rr_all[i]
            }
        }

        source_rr.change.emit();
        source.change.emit();
    """)

    menu = Select(options=['All States'] + source.data['states'],
                  value='All States',
                  title='Select State')
    menu.js_on_change('value', callback)

    output_file('Templates/bar_chart.html')
    #output_file('bar_chart.html')

    title = Div(
        text=
        """<h1>Prediction of Covid-19 Cases and Availability of Resources</h1>""",
        width=1200,
        height=50)

    div1 = Div(text="""<h3>Overview</h3>
        In 2020, the coronavirus became a global pandemic, affecting millions of people around the world. As a result, many hospitals have been collecting data as new patients come in to aid research into its spread and overall trajectory.  Our model takes in data from various datasets and resources and compiles it to make a prediction about the number of cases in each state for a given day, depending on outbreak data from previous days. Furthermore, visualization of hospital data for each state such as number of beds and ventilators for selected states will allow us to better predict when shortages of personal protective equipment (PPE) and resources in hospitals may occur.
        <h3> Additional Resources</h3>
        <a href = "https://www.cdc.gov/coronavirus/2019-ncov/covid-data/covidview/index.html" target="_blank"> CDC Website</a> with information about treatment and symptoms <br>
        <a href = "https://covid19.healthdata.org/united-states-of-america" target="_blank"> University of Washington Model</a> with prediction on Covid-19 Cases<br>
        <a href = "https://docs.google.com/spreadsheets/d/1ir6MK_WFQwnuboa5sKVWtliHktkKOWDw3rUH7aiYTXU/edit?usp=sharing" target="_blank"> Google Sheets</a> with more information on state resources<br>
        """,
               width=300,
               height=100)

    side = column(menu, div1)

    layout = gridplot([title, None, p, side, p_rr, None], ncols=2)

    curdoc().add_root(layout)
    save(layout,
         filename='Templates/bar_chart.html',
         title='Covid-19 Outbreak Prediction')
    #save(layout, filename = 'bar_chart.html', title = 'Covid-19 Outbreak Prediction')


#make_char()
示例#39
0
 def save(self, filename: str) -> None:
     """
     save function
     """
     save(self.to_render, filename=filename, resources=CDN, title="Report")
示例#40
0
plot.add_layout(
    Arrow(start=TeeHead(line_width=1),
          x_start=6,
          y_start=5,
          x_end=8,
          y_end=6,
          line_width=10))
plot.add_layout(
    Arrow(start=VeeHead(line_width=1, fill_color="white"),
          x_start=6,
          y_start=4,
          x_end=8,
          y_end=5,
          line_width=10))
plot.add_layout(
    Arrow(start=NormalHead(line_width=1, fill_color="white"),
          x_start=6,
          y_start=3,
          x_end=8,
          y_end=4,
          line_width=10))
plot.add_layout(
    Arrow(start=OpenHead(line_width=1),
          x_start=6,
          y_start=2,
          x_end=8,
          y_end=3,
          line_width=10))

save(plot)
template = """
{% block preamble %}
<style>
    body { background-color: lightblue; }
</style>
{% endblock %}
"""

plot = Plot(plot_width=600,
            plot_height=600,
            x_range=Range1d(0, 10),
            y_range=Range1d(0, 10),
            toolbar_location=None)

# This is the no-fill that we're testing
plot.background_fill_color = None
plot.border_fill_color = None

plot.add_glyph(Circle(x=3, y=3, size=50, fill_color='#ffffff'))
plot.add_glyph(Circle(x=6, y=6, size=50, fill_color='#ffffff'))

yaxis = LinearAxis(major_label_text_color='#ffffff',
                   major_label_text_font_size="30pt")
plot.add_layout(yaxis, 'left')

xaxis = LinearAxis(major_label_text_color='#ffffff',
                   major_label_text_font_size="30pt")
plot.add_layout(xaxis, 'below')

save(plot, template=template)
示例#42
0
def plot_bars(df, perc, outfile, total):
    """
    input: dataframe with ranks and number of concordantly classified contigs,
        name for an output file, total number of contigs (as input for analysis),
        number of contigs classified by both/all methods, and whether or not
        to create a plot of percentages
    output: bar graph as html file (saved as 'outfile' -> see input)
    """
    output_file(outfile)

    def find_suitable_y(n):
        """
        Find a proper upper limit for the y-axis, based on the maximum value to plot.
        """
        if n > 20000:
            return (
                n
            )  #just use the maximum value in case the numbers get really big
        elif n > 10000:
            return (20000)
        elif n > 5000:
            return (10000)
        elif n > 2000:
            return (5000)
        elif n > 1000:
            return (2000)
        elif n > 500:
            return (1000)
        elif n > 200:
            return (500)
        elif n > 100:
            return (200)
        else:
            return (100)  #100 will probably do as lower limit

    nr_source = ColumnDataSource(
        data=dict(ranks=df["Rank"],
                  classified_contigs=df["classified_contigs"],
                  consistently_classified=df["consistently_classified"],
                  inconsistently_classified=df["inconsistently_classified"],
                  consistently_unclassified=df["consistently_unclassified"],
                  only_jovian=df["only_jovian"],
                  only_cat=df["only_cat"]))

    title = "Classified contigs comparison (Jovian-CAT)"
    ymax = find_suitable_y(total)

    colors = ["#0000A6", "#63FFAC", "#B79762", "#004D43", "#FFDBE5"]
    parts = [
        "consistently_classified", "inconsistently_classified", "only_jovian",
        "only_cat", "consistently_unclassified"
    ]

    nr_fig = figure(x_range=df["Rank"],
                    plot_height=600,
                    plot_width=1000,
                    title=title,
                    toolbar_location=None,
                    tools="hover, pan",
                    tooltips="@ranks $name: @$name")

    nr_fig.vbar_stack(parts,
                      x='ranks',
                      width=0.9,
                      color=colors,
                      source=nr_source,
                      legend=[value(x) for x in parts])

    nr_fig.xgrid.grid_line_color = None
    nr_fig.legend.orientation = "horizontal"
    nr_fig.legend.location = "top_center"

    nr_panel = Panel(child=nr_fig, title="Absolute numbers of contigs")

    perc_source = ColumnDataSource(
        data=dict(ranks=perc["Rank"],
                  classified_contigs=perc["classified_contigs"],
                  consistently_classified=perc["consistently_classified"],
                  inconsistently_classified=perc["inconsistently_classified"],
                  consistently_unclassified=perc["consistently_unclassified"],
                  only_jovian=perc["only_jovian"],
                  only_cat=perc["only_cat"]))

    perc_fig = figure(x_range=perc["Rank"],
                      plot_height=600,
                      plot_width=1000,
                      title=title,
                      toolbar_location=None,
                      tools="hover, pan",
                      tooltips="@ranks $name: @$name %")

    perc_fig.vbar_stack(parts,
                        x='ranks',
                        width=0.9,
                        color=colors,
                        source=perc_source,
                        legend=[value(x) for x in parts])

    perc_fig.xgrid.grid_line_color = None
    perc_fig.legend.orientation = "horizontal"
    perc_fig.legend.location = "top_center"

    perc_panel = Panel(child=perc_fig, title="Percentages of contigs")

    tabs = Tabs(tabs=[nr_panel, perc_panel])

    save(tabs)

    return (None)
示例#43
0
def player_plots(df, base_path, gw_cnt):
    players = df["full_name_id"].values.tolist()
    players3 = df["full_name_code"].values.tolist()
    players4 = df["full_name_id"].values.tolist()
    tools = "hover"
    tooltips = """<table style="padding: 5px; color: #888;">
            <tr style="line-height: 0.8; font-size: 17px; font-weight: bold; padding:10; margin: 0">
                <td colspan=3" style="padding:5px;">@name</td>
            </tr>
            <tr style="line-height: 0.8; font-size: 12px; padding:5px !important; margin: 5px;">
                <td style="font-weight: bold; padding:5px;">Gameweek</td>
                <td style="padding:5px;">@x</td>
            </tr>
            <tr style="line-height: 0.8; font-size: 12px; padding:5px !important; margin: 5px;">
                <td style="font-weight: bold; padding:5px;">Price</td>
                <td style="padding:5px;">@y_value £</td>
            </tr>
            <tr style="line-height: 0.8; font-size: 12px; padding:5px !important; margin: 5px;">
                <td style="font-weight: bold; padding:5px;">Points</td>
                <td style="padding:5px;">@y_pts</td>
            </tr>
            <tr style="line-height: 0.8; font-size: 12px; padding:5px !important; margin: 5px;">
                <td style="font-weight: bold; padding:5px;">Minutes</td>
                <td style="padding:5px;">@y_mins</td>
            </tr>
            <tr style="line-height: 0.8; font-size: 12px; padding:5px !important; margin: 5px;">
                <td style="font-weight: bold; padding:5px;">ICT</td>
                <td style="padding:5px;">@y_ict</td>
            </tr>
        </table>
        """

    for i in range(0, len(players)):
        player3 = players3[i]
        player4 = players4[i]

        # get plots data
        val = functions.get_player_data(base_path=base_path+"scraper/", player=player4)
        source = ColumnDataSource(
            data=dict(name=([player3[:player3.index('_')]] * len(val['gw'])),
                      x=val['gw'],
                      y_value=val['value'] / 10,
                      y_pts=val['total_points'],
                      y_mins=val['minutes'],
                      y_ict=val['ict_index']))

        # plots
        p_price = figure(y_axis_label='£', tools=tools, x_range=(1, gw_cnt))
        p_price.line('x', 'y_value', source=source, line_width=2)
        p_price.hover.tooltips = tooltips

        p_pts = figure(y_axis_label='Points', tools=tools, x_range=(1, gw_cnt))
        p_pts.line('x', 'y_pts', source=source, line_width=2)
        p_pts.hover.tooltips = tooltips

        p_mins = figure(y_axis_label='Minutes', tools=tools, x_range=(1, gw_cnt), y_range=(0, 100))
        p_mins.line('x', 'y_mins', source=source, line_width=2)
        p_mins.hover.tooltips = tooltips

        p_ict = figure(x_axis_label='GW', y_axis_label='ICT', tools=tools, x_range=(1, gw_cnt))
        p_ict.line('x', 'y_ict', source=source, line_width=2)
        p_ict.hover.tooltips = tooltips

        p = gridplot([p_price, p_pts, p_mins, p_ict],
                     ncols=1,
                     plot_width=300,
                     plot_height=120,
                     toolbox=None,
                     toolbar_options={'logo': None})

        fig = row(p)

        md_file = base_path + 'web/static/assets/bokeh/player_stats/' + player3 + '.html'
        print("Generating " + md_file + "...")
        output_file(md_file)
        save(fig)
示例#44
0
x = [ (cat, year) for cat in categories for year in years ]
counts = sum(zip(data[years[0]], data[years[1]], data[years[2]]), ()) # like an hstack

source = ColumnDataSource(data=dict(x=x, counts=counts))

p = figure(x_range=FactorRange(*x), plot_height=250, title=None, toolbar_location=None, tools="")

p.vbar(x='x', top='counts', width=0.9, source=source, line_color="white",

       # use the palette to colormap based on the the x[1:2] values
       fill_color=factor_cmap('x', palette=Colorblind[3], factors=years, start=1, end=2))

p.y_range.start = 0
p.x_range.range_padding = 0.1
p.xaxis.major_label_orientation = 1
p.xgrid.grid_line_color = None

file_name="MSD_Growth"
output_file(file_name+".html")
save(p)

p.toolbar.logo = None
p.toolbar_location = None

p.background_fill_color = None
p.border_fill_color = None

export_png(p,filename=file_name+".png")
p.output_backend="svg"
export_svgs(p,filename=file_name+".svg")
示例#45
0
{% block contents %}
<div class="grid">
  {% for root in roots %}
    {{ embed(root) }}
  {% endfor %}
</div>
{% endblock %}
"""

axes = [
    "a",
    "b",
    "l",
    "r",
    "al",
    "ar",
    "bl",
    "br",
    "alr",
    "blr",
    "lab",
    "rab",
    "ab",
    "lr",
    "ablr",
    "",
]

figures = list(map(make_figure, axes))
save(figures, template=template, title="CSS grid with an extended template")
示例#46
0
def make_chart(client, numDays):

	x = list(range(1, numDays+1))
	x.reverse()
	# info placeholder getting the mfp data
	info = {}
	today = date.today()
	calorieList = {}
	goals = client.get_date(today).goals
	for day in x:
		# it really is this easy
		# for a month need to be smarter
		# start at the earliest day
		dayToEval = today - timedelta(days=day)
		info[day] = client.get_date(dayToEval.year, dayToEval.month, dayToEval.day)
		print(info[day])
		# just check the calories to make sure information is present
		data['days'].append(day)
		if 'calories' in info[day].totals:
			data['macros']['carbs'].append(info[day].totals['carbohydrates'])
			data['macros']['protein'].append(info[day].totals['protein'])
			data['macros']['fat'].append(info[day].totals['fat'])
		else:
			# error case handling to keep the x and y sizes equal
			data['carbs'].append(math.nan)
			data['protein'].append(math.nan)
			data['fat'].append(math.nan)

		# look for calories per item
		for meal in info[day].meals:
			for food in meal.entries:
				calorieList[food.name] = food.totals['calories']

	# sort the foods by calories
	sortedCalList = [(k, calorieList[k]) for k in sorted(calorieList, key=calorieList.get, reverse=True)]
	for i in range(1, 15):
		print(sortedCalList[i])

	# set up the bokeh plot, stacked bar graph for now
	#source = ColumnDataSource(data=data)
	p = figure(title='Macros Per Day')
	
	p.border_fill_color = "whitesmoke"
	p.min_border_left = 80
	p.min_border_top = 40
	p.min_border_bottom = 80
	# just add all the lines, no multi line bull
	for macro, color in zip(data['macros'], colors):
		p.line(data['days'], data['macros'][macro], line_width=4, color=color, alpha=0.8, legend=macro)

	#p.multi_line([data['days'], data['days'], data['days']], [data['carbs'], data['protein'], data['fat']], 
	#	line_color=colors, line_width=4)
	carbGoal = Span(location=goals['carbohydrates'], dimension='width', line_color=colors[0], line_dash='dashed', line_width=3)
	proteinGoal = Span(location=goals['protein'], dimension='width', line_color=colors[1], line_dash='dashed', line_width=3)
	fatGoal = Span(location=goals['fat'], dimension='width', line_color=colors[2], line_dash='dashed', line_width=3)
	p.add_layout(carbGoal)
	p.add_layout(proteinGoal)
	p.add_layout(fatGoal)
	p.legend.location = "top_left"
	p.legend.click_policy = "hide"
	output_file("calories.html")
	save(p)
示例#47
0
def create_table(status_dict):
    """Create interactive ``bokeh`` table containing the logfile status
    results.

    Parameters
    ----------
    status_dict : dict
        Nested dictionary with status results from all logfiles
    """
    # Rearrange the nested dictionary into a non-nested dict for the table
    filenames = []
    dates = []
    missings = []
    results = []
    for key in status_dict:
        filenames.append(status_dict[key]['logname'])
        dates.append(datetime.fromtimestamp(status_dict[key]['latest_time']))
        missings.append(str(status_dict[key]['missing_file']))
        results.append(status_dict[key]['status'])

    # div to color the boxes in the status column
    success_template = """
    <div style="background:<%=
        (function colorfromstr(){
            if(value == "success"){
                return("green")}
            else{return("red")}
            }()) %>;
        color: white">
    <%= value %></div>
    """

    # div to color the boxes in the column for possibly late logfiles
    missing_template = """
    <div style="background:<%=
        (function colorfrombool(){
            if(value == "True"){
                return("orange")}
            else{return("green")}
            }()) %>;
        color: white">
    <%= value %></div>
    """
    success_formatter = HTMLTemplateFormatter(template=success_template)
    missing_formatter = HTMLTemplateFormatter(template=missing_template)

    data = dict(name=list(status_dict.keys()),
                filename=filenames,
                date=dates,
                missing=missings,
                result=results)
    source = ColumnDataSource(data)

    datefmt = DateFormatter(format="RFC-2822")
    columns = [
        TableColumn(field="name", title="Monitor Name", width=200),
        TableColumn(field="filename", title="Most Recent File", width=350),
        TableColumn(field="date",
                    title="Most Recent Time",
                    width=200,
                    formatter=datefmt),
        TableColumn(field="missing",
                    title="Possible Missing File",
                    width=200,
                    formatter=missing_formatter),
        TableColumn(field="result",
                    title="Status",
                    width=100,
                    formatter=success_formatter),
    ]
    data_table = DataTable(source=source,
                           columns=columns,
                           width=800,
                           height=280,
                           index_position=None)

    # Get output directory for saving the table files
    output_dir = SETTINGS['outputs']
    output_filename = 'cron_status_table'

    # verify/create output sub-directory
    output_dir = os.path.join(output_dir, 'monitor_cron_jobs')
    ensure_dir_exists(output_dir)

    # Save full html
    html_outfile = os.path.join(output_dir, '{}.html'.format(output_filename))
    output_file(html_outfile)
    save(data_table)
    try:
        set_permissions(html_outfile)
    except PermissionError:
        logging.warning(
            'Unable to set permissions for {}'.format(html_outfile))
    logging.info('Saved Bokeh full HTML file: {}'.format(html_outfile))
示例#48
0
elements['name_lower'] = elements['name'].str.lower()
source = ColumnDataSource(elements)

html_font_template = '<font color="<%= CPK %>"><%= value %></font>'
html_image_template = """
<a href="http://images-of-elements.com/<%= value %>.php" target="_blank">
  <img src="http://images-of-elements.com/<%= value %>.jpg" style="width:40px;height:40px;border:0">
</a>
"""
columns = [
    TableColumn(field='atomic number',
                title='Atomic Number',
                formatter=NumberFormatter(text_align="right")),
    TableColumn(field='symbol',
                title='Symbol',
                formatter=StringFormatter(text_align="center")),
    TableColumn(field='name',
                title='Name',
                formatter=HTMLTemplateFormatter(template=html_font_template)),
    TableColumn(field='name_lower',
                title='Image',
                formatter=HTMLTemplateFormatter(template=html_image_template))
]
data_table = DataTable(source=source,
                       columns=columns,
                       editable=False,
                       row_height=45)

save(data_table)
示例#49
0
def generate_cluster_report(report: ClusterReport, output: Path):
    page = create_page(report)

    ensure_directory(output.parent)
    logging.info(f"Generating monitoring report into {output}")
    save(page, output, title="Cluster monitor", resources=CDN)
示例#50
0
from __future__ import absolute_import

from bokeh.io import save
from bokeh.models.widgets import MultiSelect, Panel, Tabs

select = MultiSelect(options=["First option", "Second option"])
panel = Panel(title="A tab", child=select)
tabs = Tabs(tabs=[panel], width=300)

save(tabs)
示例#51
0
 def test_missing_filename(self):
     io._state.file = None
     with self.assertRaises(RuntimeError):
         io.save("obj", None, "resources", "title")
ottawaIntl = pd.read_csv(path+"/Data/50430-2016_base_10_GDD.csv", header=None)
calgaryIntl = pd.read_csv(path+"/Data/49568-2016_base_10_GDD.csv", header=None)

gddOttawa =ottawaIntl.iloc[:][1].tolist()
gddCalgary =calgaryIntl.iloc[:][1].tolist()
gddHalifax =halifaxIntl.iloc[:][1].tolist()

days = list(range(0,len(calgaryIntl)))

halifaxIntlPlot = figure(plot_width=800, plot_height=450, title="GDD for Halifax for the year 2016", tools='hover, pan, box_zoom')
halifaxIntlPlot.grid.grid_line_alpha=0.3
halifaxIntlPlot.xaxis.axis_label = "Days"
halifaxIntlPlot.yaxis.axis_label = "GDD"
halifaxIntlPlot.line(days, gddHalifax, color='#000080')

ottawaIntlPlot = figure(plot_width=800, plot_height=450, title="GDD for Ottawa for the year 2016", tools='hover, pan, box_zoom')
ottawaIntlPlot.grid.grid_line_alpha=0.3
ottawaIntlPlot.xaxis.axis_label =  "Days"
ottawaIntlPlot.yaxis.axis_label = "GDD"
ottawaIntlPlot.line(days, gddOttawa, color='red')

calgaryIntlPlot = figure(plot_width=800, plot_height=450, title="GDD for Calgary for the year 2016", tools='hover, pan, box_zoom')
calgaryIntlPlot.grid.grid_line_alpha=0.3
calgaryIntlPlot.xaxis.axis_label = "Days"
calgaryIntlPlot.yaxis.axis_label = "GDD"
calgaryIntlPlot.line(days, gddCalgary, color='Green')

output_file('docs/bokehplot.html')

save(column(halifaxIntlPlot, ottawaIntlPlot, calgaryIntlPlot))
示例#53
0
def jwst_inventory(instruments=JWST_INSTRUMENT_NAMES,
                   dataproducts=['image', 'spectrum', 'cube'],
                   caom=False, plot=False):
    """Gather a full inventory of all JWST data in each instrument
    service by instrument/dtype

    Parameters
    ----------
    instruments: sequence
        The list of instruments to count
    dataproducts: sequence
        The types of dataproducts to count
    caom: bool
        Query CAOM service
    plot: bool
        Return a pie chart of the data

    Returns
    -------
    astropy.table.table.Table
        The table of record counts for each instrument and mode
    """
    logging.info('Searching database...')
    # Iterate through instruments
    inventory, keywords = [], {}
    for instrument in instruments:
        ins = [instrument]
        for dp in dataproducts:
            count = instrument_inventory(instrument, dataproduct=dp, caom=caom)
            ins.append(count)

        # Get the total
        ins.append(sum(ins[-3:]))

        # Add it to the list
        inventory.append(ins)

        # Add the keywords to the dict
        keywords[instrument] = instrument_keywords(instrument, caom=caom)

    logging.info('Completed database search for {} instruments and {} data products.'.
                 format(instruments, dataproducts))

    # Make the table
    all_cols = ['instrument'] + dataproducts + ['total']
    table = pd.DataFrame(inventory, columns=all_cols)

    # Plot it
    if plot:
        # Determine plot location and names
        output_dir = get_config()['outputs']

        if caom:
            output_filename = 'database_monitor_caom'
        else:
            output_filename = 'database_monitor_jwst'

        # Make the plot
        plt = bar_chart(table, 'instrument', dataproducts,
                        title="JWST Inventory")

        # Save the plot as full html
        html_filename = output_filename + '.html'
        outfile = os.path.join(output_dir, 'monitor_mast', html_filename)
        output_file(outfile)
        save(plt)
        set_permissions(outfile)

        logging.info('Saved Bokeh plots as HTML file: {}'.format(html_filename))

        # Save the plot as components
        plt.sizing_mode = 'stretch_both'
        script, div = components(plt)

        div_outfile = os.path.join(output_dir, 'monitor_mast', output_filename + "_component.html")
        with open(div_outfile, 'w') as f:
            f.write(div)
            f.close()
        set_permissions(div_outfile)

        script_outfile = os.path.join(output_dir, 'monitor_mast', output_filename + "_component.js")
        with open(script_outfile, 'w') as f:
            f.write(script)
            f.close()
        set_permissions(script_outfile)

        logging.info('Saved Bokeh components files: {}_component.html and {}_component.js'.format(
            output_filename, output_filename))

    # Melt the table
    table = pd.melt(table, id_vars=['instrument'],
                    value_vars=dataproducts,
                    value_name='files', var_name='dataproduct')

    return table, keywords
示例#54
0
def plot(data, x_axis, y_axis, group_by):
    cats = list("abcdef")
    yy = np.random.randn(2000)
    g = np.random.choice(cats, 2000)
    for i, l in enumerate(cats):
        yy[g == l] += i // 2
    df = pd.DataFrame(dict(score=yy, group=g))

    # find the quartiles and IQR for each category
    groups = df.groupby('group')
    q1 = groups.quantile(q=0.25)
    q2 = groups.quantile(q=0.5)
    q3 = groups.quantile(q=0.75)
    iqr = q3 - q1
    upper = q3 + 1.5 * iqr
    lower = q1 - 1.5 * iqr

    # find the outliers for each category
    def outliers(group):
        cat = group.name
        return group[(group.score > upper.loc[cat]['score']) |
                     (group.score < lower.loc[cat]['score'])]['score']

    out = groups.apply(outliers).dropna()

    # prepare outlier data for plotting, we need coordinates for every outlier.
    if not out.empty:
        outx = []
        outy = []
        for cat in cats:
            # only add outliers if they exist
            if not out.loc[cat].empty:
                for value in out[cat]:
                    outx.append(cat)
                    outy.append(value)

        p = plotting.figure(tools="save",
                            background_fill_color="#EFE8E2",
                            title="",
                            x_range=cats)

# if no outliers, shrink lengths of stems to be no longer than the minimums or maximums
    qmin = groups.quantile(q=0.00)
    qmax = groups.quantile(q=1.00)
    upper.score = [
        min([x, y]) for (x, y) in zip(list(qmax.loc[:, 'score']), upper.score)
    ]
    lower.score = [
        max([x, y]) for (x, y) in zip(list(qmin.loc[:, 'score']), lower.score)
    ]

    # stems
    p.segment(cats, upper.score, cats, q3.score, line_color="black")
    p.segment(cats, lower.score, cats, q1.score, line_color="black")

    # boxes
    p.vbar(cats,
           0.7,
           q2.score,
           q3.score,
           fill_color="#E08E79",
           line_color="black")
    p.vbar(cats,
           0.7,
           q1.score,
           q2.score,
           fill_color="#3B8686",
           line_color="black")

    # whiskers (almost-0 height rects simpler than segments)
    p.rect(cats, lower.score, 0.2, 0.01, line_color="black")
    p.rect(cats, upper.score, 0.2, 0.01, line_color="black")

    # outliers
    if not out.empty:
        p.circle(outx, outy, size=6, color="#F38630", fill_alpha=0.6)

    p.xgrid.grid_line_color = None
    p.ygrid.grid_line_color = "white"
    p.grid.grid_line_width = 2
    p.xaxis.major_label_text_font_size = "12pt"
    name = '{}_{}_{}_{}'.format(filename, __name__, x_axis, y_axis)
    name = name.replace(':', '')
    plotting.output_file(join_path('static', name + '.html'),
                         title=name,
                         mode='cdn',
                         root_dir=None)
    save(p)
    js, div = components(p, wrap_script=False, wrap_plot_info=True)
    return {'div': div, 'js': js}
示例#55
0
def save_static(data: pd.DataFrame, filename: str, title: str):

    data['y'] = np.log10(data.y.values)

    diff = data.y.max() - data.y.min()
    scale = abs(data.y.min())
    data['y'] += scale
    data['y'] /= diff
    #kui p väärtus on
    # p = 0.5
    #siis graafikul peab see olema
    # print((np.log10(-np.log10(p))+scale)/diff)

    hover = HoverTool(
        tooltips=[("value",
                   "@text"), ("count_first",
                              "@count_first"), ("count_second",
                                                "@count_second")])
    plot = figure(
        tools=[hover,
               WheelZoomTool(),
               BoxZoomTool(),
               PanTool(),
               ResetTool()],
        webgl=True,
        plot_width=800,
        plot_height=700,
    )

    source = ColumnDataSource(data)
    scatter = plot.scatter(source=source,
                           line_width=0,
                           line_alpha=0,
                           size=10,
                           x="x",
                           y="y",
                           alpha=0.5)
    loc = ((np.log10(-np.log10(0.5)) + scale) / diff)
    p_line = Span(location=loc,
                  dimension='width',
                  line_color='red',
                  line_width=3)
    plot.renderers.append(p_line)

    p_value_text = bokeh.models.Paragraph()

    p_value = TextInput(title='p value',
                        value='0.5',
                        callback=CustomJS(args=dict(source=source,
                                                    line=p_line,
                                                    p_text=p_value_text),
                                          code='''
    val = parseFloat(cb_obj.value);

    if (val < 0|| val > 1){{
        alert('p must be between 0 and 1')
    }}

    line.location = (Math.log10(-Math.log10(val)) + {scale})/{diff};
    p_text.text = "p =" + (val).toString()
    p_text.trigger('change')
    line.trigger('change')
    '''.format(scale=float(scale), diff=float(diff))))

    left = Span(location=-0.5, dimension='height', line_color='maroon')
    plot.renderers.append(left)
    right = Span(location=0.5, dimension='height', line_color='maroon')
    plot.renderers.append(right)

    left_limit = Slider(title='left_limit',
                        value=-0.5,
                        start=-1,
                        end=0,
                        step=0.001,
                        orientation='horizontal',
                        callback=CustomJS(args=dict(source=source, line=left),
                                          code='''
    line.location = cb_obj.value;
    line.trigger('change')
    '''))
    right_limit = Slider(title='right_limit',
                         value=0.5,
                         start=0,
                         end=1,
                         step=0.001,
                         orientation='horizontal',
                         callback=CustomJS(args=dict(source=source,
                                                     line=right),
                                           code='''
    line.location = cb_obj.value;
    line.trigger('change')
    '''))

    ###################################################
    ##   Data table      ##############################
    ###################################################

    aux_source = bokeh.models.ColumnDataSource(column_names=['index', 'text'])
    table = bokeh.models.DataTable(
        source=aux_source,
        columns=[bokeh.models.TableColumn(field='text', title='text')],
        fit_columns=True,
        width=300)

    ###################################################
    ##    Buttons        ##############################
    ###################################################

    button_width = 40
    buttons = [
        bokeh.models.Button(label='1', width=button_width),
        bokeh.models.Button(label='2', width=button_width),
        bokeh.models.Button(label='3', width=button_width),
        bokeh.models.Button(label='4', width=button_width),
        bokeh.models.Button(label='5', width=button_width),
        bokeh.models.Button(label='6', width=button_width)
    ]

    def make_button_callback(label):
        if label in '123':
            v_pred = 'source.data.y[i] > (Math.log10(-Math.log10(parseFloat(p_value.value))) + {scale})/{diff}'.format(
                scale=float(scale), diff=float(diff))
        elif label in '456':
            v_pred = 'source.data.y[i] <= (Math.log10(-Math.log10(parseFloat(p_value.value))) + {scale})/{diff}'.format(
                scale=float(scale), diff=float(diff))

        if label in '14':
            h_pred = 'source.data.x[i] <= left_limit.value'
        elif label in '25':
            h_pred = 'source.data.x[i] > left_limit.value && source.data.x[i] < right_limit.value'

        elif label in '36':
            h_pred = 'source.data.x[i] >= right_limit.value'

        condition = '({h_pred} && {v_pred})'.format(h_pred=h_pred,
                                                    v_pred=v_pred)
        return CustomJS(args=dict(source=source,
                                  left_limit=left_limit,
                                  right_limit=right_limit,
                                  p_value=p_value,
                                  table=table),
                        code='''


        table.source.data.index = []
        table.source.data.text = []

        for (var i = 0; i < source.data.x.length; i++){{
            if {condition}{{
                        table.source.data.index.push(source.data.index[i])
                        table.source.data.text.push(source.data.text[i])
                   }}
            }}

        table.trigger('change')

        '''.format(condition=condition))

    for button in buttons:
        button.callback = make_button_callback(button.label)

    # plot.renderers.extend(
    #     [
    #         Span(location=-math.log10(0.05), dimension='width', line_color='blue'),
    #         Span(location=-math.log10(0.05 / len(source.data['index'])), dimension='width',
    #              line_color='darkblue')
    #     ]
    # )

    ## Siin on y-koordinaatide jooned
    # labels = np.arange(10, 100, 10) / 100
    # labels = np.append([0.001, 0.01, 0.05], labels)
    # coords = -np.log10(labels)

    # y_ticker = bokeh.models.tickers.FixedTicker(ticks=coords)
    plot.ygrid[0].ticker = bokeh.models.tickers.FixedTicker(ticks=[])
    plot.yaxis[0].formatter = bokeh.models.formatters.PrintfTickFormatter()
    plot.yaxis[0].formatter.format = ''

    plot.set(x_range=Range1d(-1.1, 1.1), y_range=Range1d(-0.05, 1.05))

    sliders = VBox(p_value_text, p_value, left_limit, right_limit)

    save_filename = bokeh.models.TextInput(value='filename')
    save_button = bokeh.models.Button(label='Save')

    save_button.callback = CustomJS(args=dict(
        table=table,
        filename=save_filename,
    ),
                                    code='''

    if (table.source.data.text == undefined){
    alert('No elements selected! Press 1-6');
    }

    var text = table.source.data.text.join('\\n');
    var name = filename.value



    if (name === ''){
    alert('Filename is empty!')
    }

    console.log(name)

    var a = document.createElement("a");
    document.body.appendChild(a);
    a.style = "display: none";
    func = function (data, fileName) {
    console.log('doing')
        blob = new Blob([data], {type: "text/plain"}),
        url = window.URL.createObjectURL(blob);
        a.href = url;
        a.download = fileName;
        a.click();
        window.URL.revokeObjectURL(url);
    }
    func(text, name)
    console.log('done')



     ''')

    input_box = widgetbox(save_filename, save_button)

    app = row(
        column(plot),
        column(row(sliders),
               row(*buttons[:3]),
               row(*buttons[3:]),
               row(input_box),
               row(table),
               responsive=False))

    curdoc().add_root(app)
    save(curdoc(),
         filename=filename,
         title=title,
         resources=bokeh.resources.INLINE)
示例#56
0
def accelplotter(j):
    #print('Generating spectrogram for earthquake ' + str(quakecounter) + '/' + str(len(quakelist)) + ':')
    #print('    ' + str(round(j[2])) + 'M ' + j[0])

    quaketime = j[3]
    quaketime = datetime.utcfromtimestamp(quaketime)
    quaketime = quaketime.strftime("%Y-%m-%d %H:%M:%S UTC")

    windowstart = (j[5]) - 60  #start spectrogram 1min before arrival
    windowend = windowstart + 240  #end spectrogram after 4min
    if windowstart < starttime_s:
        windowstart = starttime_s  #if window starts before data, cut window to data
    if windowend > endtime_s:
        windowend = endtime_s  #if window ends before data, cut window to data

    windowindices = []
    for kindex, k in enumerate(time_s):  #find indices of times in window for
        if k <= windowstart:
            continue
        if k >= windowend:
            continue
            #print(windowend)
        windowindices.append(kindex)

    window_accelx = accelx[
        windowindices]  #cut down arrays to times in the window
    window_accely = accely[windowindices]
    window_accelz = accelz[windowindices]
    window_time_s = []
    for row in windowindices:
        window_time_s.append(time_s[row])

    def interpolateaccel(axis):
        f = interpolate.interp1d(window_time_s, axis,
                                 kind='cubic')  #make interpolation function
        timelength = int((windowend - windowstart) * 1000)  #max(window_time_s)
        timenew = np.linspace(window_time_s[0], window_time_s[-1],
                              timelength)  #generate even time values
        accelaxisnew = f(timenew)  #actually use interpolation function
        return accelaxisnew

    accelxnew = interpolateaccel(window_accelx)
    accelynew = interpolateaccel(window_accely)
    accelznew = interpolateaccel(window_accelz)

    timenew = np.linspace(-60000, 180000, 240000)

    windowname = j[0]  #set name of window to location of quake
    windowname = windowname.replace(
        " ", "")  #strip whitespace to make a valid filename
    #windowname = windowname + '_' + j[3] + '_'
    windowfilename = str(round(
        j[2])) + 'M_' + windowname + '.html'  #generate filename

    def accelplot(colortheme):
        if colortheme == 'default':
            colortheme = ['white', 'steelblue', 'steelblue', 'steelblue']
        if colortheme == 'tcolor':
            colortheme = ['dimgray', 'lightskyblue', 'pink', 'white']

        #set output file name
        output_file(
            str(round(j[2])) + 'M_' + windowname + '_acceleration.html')

        #create three plots
        pwidth = 1800
        pheight = 250

        pxaccel = figure(plot_width=pwidth,
                         plot_height=pheight,
                         title='x axis acceleration',
                         background_fill_color=colortheme[0],
                         toolbar_location=None,
                         tooltips=[("x", "$x"), ("y", "$y")])
        pxaccel.line(timenew,
                     accelxnew,
                     legend='x',
                     line_width=1,
                     line_color=colortheme[1])
        pxaccel.x_range = Range1d(-6000, 180000)

        pyaccel = figure(plot_width=pwidth,
                         plot_height=pheight,
                         title='y axis acceleration',
                         background_fill_color=colortheme[0],
                         toolbar_location=None,
                         tooltips=[("x", "$x"), ("y", "$y")])
        pyaccel.line(timenew,
                     accelynew,
                     legend='y',
                     line_width=1,
                     line_color=colortheme[2])
        pyaccel.x_range = Range1d(-6000, 180000)

        pzaccel = figure(plot_width=pwidth,
                         plot_height=pheight,
                         title='z axis acceleration',
                         background_fill_color=colortheme[0],
                         toolbar_location=None,
                         tooltips=[("x", "$x"), ("y", "$y")])
        pzaccel.line(timenew,
                     accelznew,
                     legend='z',
                     line_width=1,
                     line_color=colortheme[3])
        pzaccel.x_range = Range1d(-6000, 180000)

        #show(grid)
        return pxaccel, pyaccel, pzaccel

    accelgrid = accelplot('default')

    #pxaccel,pyaccel,pzaccel = accelgrid
    pxaccel = accelgrid[0]
    pyaccel = accelgrid[1]
    pzaccel = accelgrid[2]

    #pxaccel = pxaccel[0]
    #return pxaccel

    def fftaccel3(axis, axisname):
        sampling_rate = 1000  # Hz
        #N = windowend - windowstart # array size
        N = 240000
        #accelxshort = accelxnew[(start_time*sampling_rate):(end_time*sampling_rate)]

        # Nyquist Sampling Criteria (for interpolated data)
        T = 1 / sampling_rate
        xfft = np.linspace(0.0, 1.0 / (2.0 * T), int(N / 2))

        # FFT algorithm
        yr = fft(axis)  # "raw" FFT with both + and - frequencies
        yfft = 2 / N * np.abs(yr[0:np.int(N / 2)])  # positive freqs only

        p1 = figure(
            tooltips=[("x", "$x"), ("y", "$y")],
            y_axis_type='log',
            plot_width=500,
            plot_height=500,
            toolbar_location="left",
            title=axisname + ' axis fast fourier transform',
        )
        p1.x_range = Range1d(0, 200)
        p1.line(
            xfft,
            yfft,
        )
        #show(p1)

        f, t2, Sxx = signal.spectrogram(axis, fs=1000, nperseg=1000)

        p = figure(title=axisname + ' axis spectrogram',
                   tooltips=[("time", "$t2"), ("freq.", "$f"),
                             ("value", "@Sxx")],
                   plot_width=1800,
                   plot_height=250,
                   toolbar_location='left')
        p.x_range.range_padding = p.y_range.range_padding = 0

        #original palette: spectral11
        p.image(image=[np.log(Sxx)],
                x=0,
                y=0,
                dw=10,
                dh=10,
                palette="Plasma256")
        #mapper = linear_cmap(field_name=Sxx,low=min(Sxx),high=max(Sxx))
        #color_bar = ColorBar(color_mapper=mapper['transform'],width=8,location=(0,0))
        #p.add_layout(color_bar,'right')

        output_file(
            str(round(j[2])) + 'M_' + windowname + axisname + '_fft.html')

        #show(grid)
        return p1, p

    fftx = fftaccel3(accelxnew, 'x')
    ffty = fftaccel3(accelynew, 'y')
    fftz = fftaccel3(accelznew, 'z')

    fftxtop = fftx[0]
    fftxspec = fftx[1]
    fftytop = ffty[0]
    fftyspec = ffty[1]
    fftztop = fftz[0]
    fftzspec = fftz[1]

    gridx = gridplot([pxaccel, fftxspec], ncols=1)
    smallgridx = gridplot([fftxtop, gridx], ncols=2)

    gridy = gridplot([pyaccel, fftyspec], ncols=1)
    smallgridy = gridplot([fftytop, gridy], ncols=2)

    gridz = gridplot([pzaccel, fftzspec], ncols=1)
    smallgridz = gridplot([fftztop, gridz], ncols=2)

    biggrid = gridplot([smallgridx, smallgridy, smallgridz], ncols=1)
    output_file(windowfilename)
    save(biggrid)
示例#57
0
def createMap():
    #pd.options.display.float_format = '{:,.0f}'.format
    shapefile = '/Users/Aditya/Desktop/project/geoData/ne_110m_admin_0_countries.shp'
    datafile = '/Users/Aditya/Desktop/project/output.csv'

    #Read shapefile using Geopandas
    gdf = gpd.read_file(shapefile)[['ADMIN', 'ADM0_A3', 'geometry']]
    #Rename columns.
    gdf.columns = ['country', 'country_code', 'geometry']
    #Drop row corresponding to 'Antarctica'
    #gdf.at[43, 'country'] = "French Guiana"
    #drop antartica, takes too much space
    gdf = gdf.drop(gdf.index[159])

    #Read csv file using pandas

    df = pd.read_csv(datafile,
                     names=[
                         'Country', 'Deaths', 'Deaths /1M pop', 'New Deaths',
                         'Tests', 'Confirmed Cases',
                         'Confirmed Case/Fatality Rate',
                         'Confirmed Cases/1M pop', 'EstimatedCases',
                         'Seasonal Flu Deaths1(CDC/WHO 2017)'
                     ],
                     skiprows=2)
    merged = gdf.merge(df, left_on='country', right_on='Country', how='left')
    merged['Deaths /1M pop'].fillna("No Data", inplace=True)
    merged.round({'Deaths /1M pop': 2})
    #print(merged.head(merged['Deaths /1M pop']))

    #Read data to json.
    merged_json = json.loads(merged.to_json())
    #Convert to String like object.

    json_data = json.dumps(merged_json)

    #Input GeoJSON source that contains features for plotting.
    geosource = GeoJSONDataSource(geojson=json_data)

    #Define a sequential multi-hue color palette.
    palette = brewer['YlOrRd'][7]

    #Reverse color order so that dark blue is highest obesity.
    palette = palette[::-1]

    #Instantiate LinearColorMapper that linearly maps numbers in a range, into a sequence of colors.
    color_mapper = LinearColorMapper(palette=palette,
                                     low=0,
                                     high=350,
                                     nan_color='#d9d9d9')

    #Define custom tick labels for color bar.
    tick_labels = {
        '0': '0',
        '50': '50',
        '100': '100',
        '150': '150',
        '200': '200',
        '250': '250',
        '300': '300',
        '350': '>350'
    }

    #Add hover tool

    TOOLTIPS = """
    <div>
        <div>
            <span style="font-size: 14px; color: black;"> Country: @country </span>
        </div>
        <div>
            <span style="font-size: 14px; color: black;"> Deaths /1M: @{Deaths /1M pop}{0.00 a} </span>
            
        </div>
    </div>

"""

    hover = HoverTool(tooltips=TOOLTIPS)
    #Create color bar.
    color_bar = ColorBar(color_mapper=color_mapper,
                         label_standoff=9,
                         width=20,
                         height=555,
                         border_line_color=None,
                         location=(0, -10),
                         orientation='vertical',
                         major_label_overrides=tick_labels,
                         background_fill_color="#1e1e2f",
                         major_label_text_color="white")

    #Create figure object.
    p = figure(title='Deaths per Million',
               plot_height=610,
               plot_width=1100,
               toolbar_location=None,
               tools=[hover])
    p.title.text_color = "white"
    p.xgrid.grid_line_color = None
    p.ygrid.grid_line_color = None
    p.background_fill_color = "#3690c0"
    p.border_fill_color = "#1e1e2f"
    p.axis.visible = False
    today = date.today()

    d2 = today.strftime("%B %d, %Y")
    title = "Data is from https://www.realclearpolitics.com/coronavirus. Last updated %s" % d2

    p.add_layout(Title(text=title, align="left", text_color="white"), "below")

    #Add patch renderer to figure.
    p.patches('xs',
              'ys',
              source=geosource,
              fill_color={
                  'field': 'Deaths /1M pop',
                  'transform': color_mapper
              },
              line_color='black',
              line_width=0.25,
              fill_alpha=1)

    #Specify figure layout.
    p.add_layout(color_bar, 'right')

    script, div = components(p)

    #Display figure.
    save(p)
    return p
示例#58
0
def plot_raw_traces(traces, time, stim_name, ch, save_folder):
    print 'shape traces[:,0] = ', traces[:, 0].shape
    print 'time shape = ', time.shape

    #################### BOKEH FIGURE #########################
    fig = plt.figure(figsize=(20, 10))
    num_trials = traces.shape[1]
    gs = gridspec.GridSpec(num_trials, 1,
                           width_ratios=[1, 1])  ## a subplot for every trial
    ax = range(num_trials)
    all_spike_times = []
    raster = figure(width=1000,
                    height=400,
                    y_axis_label='Trial Number',
                    title='Raster + Histogram Channel %d, Orientation %d' %
                    (ch + 1, stim_name))
    spike_vec = np.zeros([len(time), 1])

    time_vec = np.linspace(0, len(time), len(time))

    for trial in range(num_trials):
        print 'trial # ', trial
        peaks, times, ifr_vec = run_spike_detect(traces[:, trial])
        all_spike_times.append(times)
        spike_vec[times] += 1
        trial_time = [t / 30e3 - 0.5 for t in times]
        #ax = plt.subplot(gs[trial])
        #sns.tsplot(downsample(traces[:,trial],10),time=time,value='Voltage (uV)',color='black',linewidth=0.1)
        ax[trial] = figure(width=1000, plot_height=500)
        #s1 = figure(width=1000, plot_height=500, title='Spikes')
        ax[trial].line(time, traces[:,
                                    trial])  ## (time is already downsampled)
        ax[trial].circle(
            trial_time, peaks, color='red'
        )  ## convert to seconds and subtract 0.5 b/c plotting data on time from -0.5 to +0.5 seconds

        #ax.set_ylim([-1000,1000])
        #ax.set(y_range=Range1d(-1000, 1000))
        #axes.append[ax]

        raster.segment(x0=trial_time,
                       y0=np.repeat(trial, len(times)),
                       x1=trial_time,
                       y1=np.repeat(trial + 1, len(times)),
                       color="black",
                       line_width=0.5)

    p = gridplot([[s1] for s1 in ax])  #gridplot([[s1] for s1 in axes])

    #fig.savefig(save_folder + '/raw_psth_'+str(stim_name)+'.pdf')

    output_file(save_folder + '/raw_psth_' + str(stim_name) + '.html')
    # show the results
    save(p)
    ############## SPIKE HISTOGRAM FIGURE ############################
    histo_fig = figure(width=1000,
                       plot_height=500,
                       y_axis_label='Firing Rate (Hz)',
                       x_axis_label='Time (sec)',
                       x_range=raster.x_range)
    print 'len all_spike_times = ', len(all_spike_times)
    num_bins = 50
    hist, edges = np.histogram(flatten(all_spike_times), bins=num_bins)
    bin_width = np.diff(edges)[0] / fs  # in seconds.
    edges = edges / fs - 0.5  ## plot x-axis in seconds.
    histo_fig.quad(
        top=hist / bin_width / num_trials,
        bottom=0,
        left=edges[:-1],
        right=edges[1:],  ## hist/bin_width = firing rate in Hz
        fill_color="#036564",
        line_color="#033649")

    #time
    # pass this to the sliding window - get sum of spikes in each 100ms window.
    win_size = 2**8
    win_step = 2**2
    win_x, windowd_spike_vec = windowed_histogram(spike_vec, time_vec,
                                                  win_size, win_step)

    histo_fig.line([t / fs - 0.5 for t in win_x],
                   [w / win_size * fs / num_trials for w in windowd_spike_vec],
                   color='magenta')

    output_file(save_folder + '/spike_histogram_' + str(stim_name) + '.html')
    grid = gridplot([[raster], [histo_fig]])

    save(grid)
示例#59
0
def test_label(output_file_url, selenium, screenshot):

    # Have to specify x/y range as labels aren't included in the plot area solver
    plot = Plot(plot_height=HEIGHT,
                plot_width=WIDTH,
                x_range=Range1d(0, 10),
                y_range=Range1d(0, 10),
                toolbar_location=None)

    label1 = Label(x=1,
                   y=6,
                   x_offset=25,
                   y_offset=25,
                   text=["Demo Label"],
                   text_font_size='38pt',
                   text_color='red',
                   text_alpha=0.9,
                   text_baseline='bottom',
                   text_align='left',
                   background_fill_color='green',
                   background_fill_alpha=0.2,
                   angle=15,
                   angle_units='deg',
                   render_mode='canvas')

    label2 = Label(x=3,
                   y=5.5,
                   text=["(I'm Canvas)"],
                   text_font_size='20pt',
                   border_line_color='black',
                   border_line_width=2,
                   border_line_dash='8 4',
                   render_mode='canvas')

    label3 = Label(x=1,
                   y=2,
                   x_offset=25,
                   y_offset=25,
                   text=["Demo Label"],
                   text_font_size='38pt',
                   text_color='red',
                   text_alpha=0.9,
                   text_baseline='bottom',
                   text_align='left',
                   background_fill_color='green',
                   background_fill_alpha=0.2,
                   angle=0.261,
                   angle_units='rad',
                   render_mode='css')

    label4 = Label(x=3,
                   y=1.0,
                   text=["(I'm CSS)"],
                   text_font_size='20pt',
                   border_line_color='black',
                   border_line_width=2,
                   border_line_dash='8 4',
                   render_mode='css')

    label_above = Label(
        x=0,
        y=0,
        text=["Label in above panel"],
        x_units='screen',
        y_units='screen',
        text_font_size='38pt',
        text_color='firebrick',
        text_alpha=0.9,
    )

    label_left = Label(
        x=0,
        y=0,
        text=["Label in left panel"],
        x_units='screen',
        y_units='screen',
        angle=90,
        angle_units='deg',
        text_font_size='18pt',
        text_color='firebrick',
        text_alpha=0.9,
        background_fill_color='aliceblue',
        text_baseline='top',
    )

    plot.add_layout(LinearAxis(), 'below')
    plot.add_layout(LinearAxis(), 'left')

    plot.add_layout(label1)
    plot.add_layout(label2)
    plot.add_layout(label3)
    plot.add_layout(label4)
    plot.add_layout(label_above, 'above')
    plot.add_layout(label_left, 'left')

    # Save the plot and start the test
    save(plot)
    selenium.get(output_file_url)

    # Take screenshot
    assert screenshot.is_valid()
示例#60
0
def tplot(name, 
          var_label = None, 
          auto_color=True, 
          interactive=False, 
          combine_axes=True, 
          nb=False, 
          save_file=None,
          gui=False, 
          qt=True,
          pyqtgraph=False):
    
    """
    This is the function used to display the tplot variables stored in memory.
    The default output is to show the plots stacked on top of one another inside a GUI window.  
    The GUI window has the option to export the plots in either PNG or HTML formats.
    
    .. note::
        This plotting routine uses the python Bokeh library, which creates plots using HTML and Javascript.  
        Bokeh is technically still in beta, so future patches to Bokeh may require updates to this function.  
    
    Parameters:
        name : str / list
            List of tplot variables that will be plotted
        var_label : str, optional
            The name of the tplot variable you would like as
            a second x axis. 
        auto_color : bool, optional
            Automatically color the plot lines.
        interactive : bool, optional
            If True, a secondary interactive plot will be generated next to spectrogram plots.  
            Mousing over the spectrogram will display a slice of data from that time on the 
            interactive chart.
        combine_axis : bool, optional
            If True, the axes are combined so that they all display the same x range.  This also enables
            scrolling/zooming/panning on one plot to affect all of the other plots simultaneously.  
        nb : bool, optional
            If True, the plot will be displayed inside of a current Jupyter notebook session.  
        save_file : str, optional
            A full file name and path.  
            If this option is set, the plot will be automatically saved to the file name provided in an HTML format.
            The plots can then be opened and viewed on any browser without any requirements. 
        gui : bool, optional
            If True, then this function will output the 2 HTML components of the generated plots as string variables.
            This is useful if you are embedded the plots in your own GUI.  For more information, see 
            http://bokeh.pydata.org/en/latest/docs/user_guide/embed.html  
        qt : bool, optional
            If True, then this function will display the plot inside of the Qt window.  From this window, you
            can choose to export the plots as either an HTML file, or as a PNG.   
        
    Returns:
        None
        
    Examples:
        >>> #Plot a single line
        >>> import pytplot
        >>> x_data = [2,3,4,5,6]
        >>> y_data = [1,2,3,4,5]
        >>> pytplot.store_data("Variable1", data={'x':x_data, 'y':y_data})
        >>> pytplot.tplot("Variable1")
        
        >>> #Display two plots
        >>> x_data = [1,2,3,4,5]
        >>> y_data = [[1,5],[2,4],[3,3],[4,2],[5,1]]
        >>> pytplot.store_data("Variable2", data={'x':x_data, 'y':y_data})
        >>> pytplot.tplot(["Variable1", "Variable2"])
        
        >>> #Display 2 plots, using Variable1 as another x axis
        >>> x_data = [1,2,3]
        >>> y_data = [ [1,2,3] , [4,5,6], [7,8,9] ]
        >>> v_data = [1,2,3]
        >>> pytplot.store_data("Variable3", data={'x':x_data, 'y':y_data, 'v':v_data})
        >>> pytplot.options("Variable3", 'spec', 1)
        >>> pytplot.tplot(["Variable2", "Variable3"], var_label='Variable1')
        
        >>> #Plot all 3 tplot variables, sending the output to an HTML file
        >>> pytplot.tplot(["Variable1", "Variable2", "Variable3"], save_file='C:/temp/pytplot_example.html')
        
        >>> #Plot all 3 tplot variables, sending the HTML output to a pair of strings
        >>> div, component = pytplot.tplot(["Variable1", "Variable2", "Variable3"], gui=True)
    """
    
    #Check a bunch of things
    if(not isinstance(name, list)):
        name=[name]
        num_plots = 1
    else:
        num_plots = len(name)
    
    for i in range(num_plots):
        if isinstance(name[i], int):
            name[i] = list(pytplot.data_quants.keys())[name[i]]
        if name[i] not in pytplot.data_quants.keys():
            print(str(i) + " is currently not in pytplot")
            return
    
    if isinstance(var_label, int):
        var_label = list(pytplot.data_quants.keys())[var_label]
    
    if pyqtgraph:
        layout = QtPlotter.generate_stack(name, var_label=var_label, auto_color=auto_color, combine_axes=combine_axes, mouse_moved_event=pytplot.hover_time.change_hover_time)
        pytplot.pytplotWindow.newlayout(layout)
        pytplot.pytplotWindow.resize(pytplot.tplot_opt_glob['window_size'][0], pytplot.tplot_opt_glob['window_size'][1])
        pytplot.pytplotWindow.show()
        pytplot.pytplotWindow.activateWindow()
        if not (hasattr(sys, 'ps1')) or not hasattr(QtCore, 'PYQT_VERSION'):
            QtGui.QApplication.instance().exec_()
        return
    else:
        layout = HTMLPlotter.generate_stack(name, var_label=var_label, auto_color=auto_color, combine_axes=combine_axes, interactive=interactive)
        #Output types
        if gui:
            script, div = components(layout)
            return script, div
        elif nb:
            output_notebook()
            show(layout)
            return
        elif save_file != None:
            output_file(save_file, mode='inline')
            save(layout)    
            return
        elif qt:        
            dir_path = os.path.dirname(os.path.realpath(__file__))
            output_file(os.path.join(dir_path, "temp.html"), mode='inline')
            save(layout)
            new_layout = WebView()
            pytplot.pytplotWindow.resize(pytplot.tplot_opt_glob['window_size'][0]+100,pytplot.tplot_opt_glob['window_size'][1]+100)
            new_layout.resize(pytplot.tplot_opt_glob['window_size'][0],pytplot.tplot_opt_glob['window_size'][1])
            dir_path = os.path.dirname(os.path.realpath(__file__))
            new_layout.setUrl(QtCore.QUrl.fromLocalFile(os.path.join(dir_path, "temp.html")))
            pytplot.pytplotWindow.newlayout(new_layout)
            pytplot.pytplotWindow.show()
            pytplot.pytplotWindow.activateWindow()
            if not (hasattr(sys, 'ps1')) or not hasattr(QtCore, 'PYQT_VERSION'):
                QtGui.QApplication.instance().exec_()
            return
        else:      
            dir_path = os.path.dirname(os.path.realpath(__file__))
            output_file(os.path.join(dir_path, "temp.html"), mode='inline')
            show(layout)
            return