background_fill_alpha=0.6, x_offset=8, #y_offset=5, source=mohr_sigma_label_data) mohr_plot.add_layout(mohr_sigma_labels) mohr_plot.legend.location = "top_left" ############################################################################## ### TABLE ### ############################################################################## columns = [ TableColumn(field='zw', title='Zw (m)', formatter=models.NumberFormatter(format='0.000')), TableColumn(field='zl', title='Zl (m)', formatter=models.NumberFormatter(format='0.000')), TableColumn(field='z', title='Z (m)', formatter=models.NumberFormatter(format='0.000')), TableColumn(field='Ja', title='J\u03B1', formatter=models.NumberFormatter(format='0.000')), TableColumn(field='a_a', title='\u03B1\u2090 (deg)', formatter=models.NumberFormatter(format='0.000')), TableColumn(field='Ka', title='K\u03B1', formatter=models.NumberFormatter(format='0.000')),
def create_panel(k): # Create plot p[k] = bpl.figure(tools=[TOOLS,hover],toolbar_location="right") p[k].circle(x=inp_xaxis.value, y=inp_yaxis.value, source = pdf_ts[k], size=12) p[k].xaxis.axis_label = "climate change signal {}".format(inp_xaxis.value) p[k].yaxis.axis_label = "climate change signal {}".format(inp_yaxis.value) # Horizontal line hline = bmo.Span(location=0, dimension='width', line_color='black', line_width=3) vline = bmo.Span(location=0, dimension='height', line_color='black', line_width=3) p[k].renderers.extend([vline, hline]) # Create table columns = [ bmo.widgets.TableColumn(field="index", title="model"), bmo.widgets.TableColumn(field="{}".format(inp_xaxis.value), title="{}".format(inp_xaxis.value.title()), width=65,formatter=bmo.NumberFormatter(format="0.000")), bmo.widgets.TableColumn(field="{}_percentiles".format(inp_xaxis.value), title="{} Perc.".format(inp_xaxis.value.title()), width=70,formatter=bmo.NumberFormatter(format="0.000")), bmo.widgets.TableColumn(field="{}".format(inp_yaxis.value), title="{}".format(inp_yaxis.value.title()), width=65,formatter=bmo.NumberFormatter(format="0.000")), bmo.widgets.TableColumn(field="{}_percentiles".format(inp_yaxis.value), title="{} Perc.".format(inp_yaxis.value.title()), width=70,formatter=bmo.NumberFormatter(format="0.000")), ] data_table = bmo.widgets.DataTable(source=pdf_ts[k], columns=columns, fit_columns=False, selectable='checkbox', height=p[k].plot_height-100, index_position=None) down_button = bmo.widgets.Button(label="Download CSV", button_type="primary") down_button.callback = bmo.CustomJS(args=dict(source=pdf_ts[k], filename="{}_{}_{}.csv".format(k, inp_time_mean.value, inp_exp.value)), code=open(join(dirname(__file__), "download.js")).read()) dct_buttons[k] = down_button l_panel = bo.layouts.row([ bo.layouts.column([p[k]]), bo.layouts.column([down_button, data_table]), ]) panel = bmo.widgets.Panel(child=l_panel, title=time_description[k]) return panel
def perform_slicing(s: pd.Series): """ Perform slicing of the packet IAT series `s` into following bins: '0 - 10', '10 - 100', '100 - 500', '500 - 1,000', '1,000 - 5,000', '5,000 - 10,000', '10,000 - 50,000', '50,000 - 100,000', '100,000 - 500,000', where each diapason is specified in microseconds (us). Attributes: s: ` pd.Series` of packet inter-arrival time in microseconds (us). Returns: `bokeh` bar chart figure and table with data. """ bins = [0, 10, 100, 500, 1000, 5000, 10000, 50000, 100000, 500000] hist, edges = np.histogram(s, bins=bins) bins_str = [ '0 - 10', '10 - 100', '100 - 500', '500 - 1,000', '1,000 - 5,000', '5,000 - 10,000', '10,000 - 50,000', '50,000 - 100,000', '100,000 - 500,000' ] d = {} d['edges.us'] = bins_str d['packets'] = hist df = pd.DataFrame(d) n = df['packets'].sum() df['packets_cumsum'] = df['packets'].cumsum() df['percentage'] = df['packets'] * 100 / n df['percentage_cumsum'] = round(df['percentage'].cumsum(), 4) df['percentage'] = round(df['percentage'], 4) # Figure fig = plotting.figure( plot_height=300, plot_width=1000, x_range=bins_str, tools=TOOLS ) fig.title.text = 'Inter-arrival packet time diapason vs Packets' fig.xaxis.axis_label = 'IAT, us' fig.yaxis.axis_label = 'Packets' fig.yaxis.formatter = models.NumeralTickFormatter(format='0,0') # fig.xaxis.major_label_orientation = math.pi/4 fig.vbar(x=bins_str, top=hist, width=0.9) # Table source = models.ColumnDataSource(df) columns = [ models.widgets.TableColumn(field='edges.us', title='IAT, us'), models.widgets.TableColumn(field='packets', title='Packets', formatter=models.NumberFormatter(format='0,0')), models.widgets.TableColumn(field='packets_cumsum', title='Packets cumsum', formatter=models.NumberFormatter(format='0,0')), models.widgets.TableColumn(field='percentage', title='Packets, %'), models.widgets.TableColumn(field='percentage_cumsum', title='Packets cumsum, %'), ] table = models.widgets.DataTable(columns=columns, source=source) return fig, table