def timeline_plot(self, DF): try: hover = HoverTool(tooltips="Task: @Item<br>\ Start: @start<br>\ End: @end") self.timeline_vars['G'].quad(left='Start', right='End', bottom='ID', top='ID1', source=timeline_source, color="Color") self.tools = [hover] + self.tools self.timeline_vars['G'].tools = self.tools self.timeline_vars['toolbar_box'] = ToolbarBox() self.timeline_vars['toolbar_box'].toolbar = Toolbar( tools=self.tools) self.timeline_vars['toolbar_box'].toolbar_location = "above" self.timeline_vars['G'].x_range.start = DF.Start.min( ) - timedelta(days=10) self.timeline_vars['G'].x_range.start = DF.End.max( ) + timedelta(days=10) return self.timeline_vars['G'] except Exception: logger.error('timeline', exc_info=True)
def _show_bofigure(axs, widgets, ncols=1, output='notebook', **kwargs): if output.lower() == 'notebook': boplt.output_notebook() notebook_handle = True elif output.lower() == 'file': import tempfile boplt.output_file(tempfile.mktemp('.html')) notebook_handle = False else: doc = boplt.curdoc() notebook_handle = False raw_tools = [] for ax in axs: raw_tools = raw_tools + ax.toolbar.tools ax.x_range = axs[0].x_range for ax in axs[:-1]: ax.xaxis.visible = False axs[-1].plot_height += 15 if kwargs.pop('RangeSelect', False): rs = make_RangeSelect(axs) else: rs = Spacer(width=1, height=1) if kwargs.pop('Cursor', False): button = make_cursors(axs, ) else: button = None toolbar = ToolbarBox(tools=raw_tools, logo=None, toolbar_location='right', merge_tools=True, sizing_mode='stretch_both') sizing_mode = None if button is None: if rs is None: col = column(*axs) #, sizing_mode='scale_width') else: col = column(*axs, rs) #, sizing_mode='scale_width') else: if rs is None: col = column(button, *axs) #, sizing_mode='scale_width') else: col = column(button, *axs, rs) #, sizing_mode='scale_width') #layout = row(col, Spacer(width=40, height=300),toolbar, sizing_mode='stretch_both') layout = row(col, Spacer(width=40, height=300), toolbar) if output.lower() in ('notebook', 'file'): return boplt.show(layout, notebook_handle=notebook_handle), layout, axs else: doc.add_root(layout) return None
def resource_profile_plot(sizing_mode='fixed', **kwargs): names = ['time', 'cpu', 'memory_percent', 'network-send', 'network-recv'] source = ColumnDataSource({k: [] for k in names}) plot_props = dict( tools='xpan,xwheel_zoom,box_zoom,reset', toolbar_location=None, # Because we're making a joint toolbar sizing_mode=sizing_mode, x_axis_type='datetime', x_range=DataRange1d(follow='end', follow_interval=30000, range_padding=0)) plot_props.update(kwargs) line_props = dict(x='time', line_width=2, line_alpha=0.8, source=source) y_range = Range1d(0, 1) p1 = figure(title=None, y_range=y_range, id='bk-resource-profile-plot', **plot_props) p1.line(y='memory_percent', color="#33a02c", legend='Memory', **line_props) p1.line(y='cpu', color="#1f78b4", legend='CPU', **line_props) p1 = _format_resource_profile_plot(p1) p1.yaxis.bounds = (0, 100) p1.yaxis.formatter = NumeralTickFormatter(format="0 %") p1.xaxis.visible = None p1.min_border_bottom = 10 y_range = DataRange1d(start=0) p2 = figure(title=None, y_range=y_range, id='bk-network-profile-plot', **plot_props) p2.line(y='network-send', color="#a6cee3", legend='Network Send', **line_props) p2.line(y='network-recv', color="#b2df8a", legend='Network Recv', **line_props) p2 = _format_resource_profile_plot(p2) p2.yaxis.axis_label = "MB/s" from bokeh.models import DatetimeAxis for r in list(p1.renderers): if isinstance(r, DatetimeAxis): p1.renderers.remove(r) all_tools = p1.toolbar.tools + p2.toolbar.tools combo_toolbar = ToolbarBox(tools=all_tools, sizing_mode=sizing_mode, logo=None, toolbar_location='right') return source, p1, p2, combo_toolbar
def plot_layoult(title, grid1, save_figs=False, show_figs=True, grid2=None): if title is None: title='NOME DA FIGURA NAO FORNECIDO' xwheel_zoom = WheelZoomTool(dimensions="width") pan_tool = PanTool() hover = HoverTool() crosshair = CrosshairTool() toolbar = Toolbar( tools=[xwheel_zoom, pan_tool, hover, crosshair], active_inspect=[crosshair], # active_drag = # here you can assign the defaults # active_scroll = # wheel_zoom sometimes is not working if it is set here # active_tap ) toolbar_box = ToolbarBox(toolbar=toolbar, toolbar_location="above") if grid2 is None: layout_2 = layout(children=[[ # toolbar_box, grid1 ]], # sizing_mode="stretch_both", # plot_width=400, plot_height=800, ) else: layout_2 = layout(children=[[ # toolbar_box, [[grid1], [grid2]] ]], # sizing_mode="stretch_both", # plot_width=3000, plot_height=1000, ) if save_figs is True: output_file(title + ".html") if show_figs is True: show(layout_2) else: save(layout_2) else: show(layout_2)
def __init__(self, table, cols=[]): KPI.__init__(self, table, name='project', cols=cols) self.table = table self.df = None self.df_pop = None self.checkboxgroup = {} self.period_to_date_cards = {} self.ptd_startdate = datetime(datetime.today().year, 1, 1, 0, 0, 0) self.timestamp_col = 'project_startdate_actual' self.pym = PythonMongo('aion') self.groupby_dict = { 'project': 'sum', 'project_duration': 'sum', 'project_start_delay': 'mean', 'project_end_delay': ' mean', 'milestone': 'sum', 'milestone_duration': 'sum', 'milestone_start_delay': 'mean', 'milestone_end_delay': ' mean', 'task': 'sum', 'task_duration': 'sum', 'task_start_delay': 'mean', 'task_end_delay': ' mean', } self.menus = { 'status': ['all', 'open', 'closed'], 'type': [ 'all', 'research', 'reconciliation', 'audit', 'innovation', 'construction', 'manufacturing', 'conference' ], 'gender': ['all', 'male', 'female'], 'variables': list(self.groupby_dict.keys()), 'history_periods': ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], } self.status = 'all' self.pm_gender = 'all' self.m_gender = 'all' self.t_gender = 'all' self.type = 'all' self.variables = sorted(list(self.groupby_dict.keys())) self.variable = self.variables[0] self.groupby_var = 'project' self.chord_data = { 'rename': { 'project_owner': 'source', 'milestone_owner': 'target', 'remuneration': 'value' }, 'percentile_threshold': .75, } self.percentile_threshold = 10 # ------- DIVS setup begin self.page_width = 1200 txt = """<hr/><div style="text-align:center;width:{}px;height:{}px; position:relative;background:black;margin-bottom:200px"> <h1 style="color:#fff;margin-bottom:300px">{}</h1> </div>""".format(self.page_width, 50, 'Welcome') self.notification_div = { 'top': Div(text=txt, width=self.page_width, height=20), 'bottom': Div(text=txt, width=self.page_width, height=10), } self.section_divider = '-----------------------------------' self.section_headers = { 'cards': self.section_header_div(text='Period to date:{}'.format( self.section_divider), width=1000, html_header='h2', margin_top=50, margin_bottom=5), 'pop': self.section_header_div(text='Period over period:{}'.format( self.section_divider), width=600, html_header='h2', margin_top=5, margin_bottom=-155), 'chord': self.section_header_div(text='Relationships:{}'.format( self.section_divider), width=600, html_header='h2', margin_top=5, margin_bottom=-155), 'timeline': self.section_header_div(text='Project timeline:{}'.format( self.section_divider), width=600, html_header='h2', margin_top=5, margin_bottom=-155), } self.KPI_card_div = self.initialize_cards(self.page_width, height=350) start = datetime(2014, 1, 1, 0, 0, 0) end = datetime(2019, 5, 15, 0, 0, 0) self.tools = [ BoxZoomTool(), ResetTool(), PanTool(), SaveTool(), WheelZoomTool() ] self.timeline_vars = { 'projects': '', 'project': '', 'types': ['all', 'milestone', 'task', 'project'], 'type': 'all', 'DF': None, 'G': figure(title=None, x_axis_type='datetime', width=1200, height=900, y_range=[], x_range=Range1d(start, end), toolbar_location=None), 'toolbar_box': ToolbarBox() }
def __init__(self, **kwargs): self.source = ColumnDataSource( data={ 'time': [], 'cpu': [], 'memory_percent': [], 'network-send': [], 'network-recv': [] }) x_range = DataRange1d(follow='end', follow_interval=30000, range_padding=0) resource_plot = Plot(x_range=x_range, y_range=Range1d(start=0, end=1), toolbar_location=None, min_border_bottom=10, **kwargs) line_opts = dict(line_width=2, line_alpha=0.8) g1 = resource_plot.add_glyph( self.source, Line(x='time', y='memory_percent', line_color="#33a02c", **line_opts)) g2 = resource_plot.add_glyph( self.source, Line(x='time', y='cpu', line_color="#1f78b4", **line_opts)) resource_plot.add_layout( LinearAxis(formatter=NumeralTickFormatter(format="0 %")), 'left') legend_opts = dict(location='top_left', orientation='horizontal', padding=5, margin=5, label_height=5) resource_plot.add_layout( Legend(items=[('Memory', [g1]), ('CPU', [g2])], **legend_opts)) network_plot = Plot(x_range=x_range, y_range=DataRange1d(start=0), toolbar_location=None, **kwargs) g1 = network_plot.add_glyph( self.source, Line(x='time', y='network-send', line_color="#a6cee3", **line_opts)) g2 = network_plot.add_glyph( self.source, Line(x='time', y='network-recv', line_color="#b2df8a", **line_opts)) network_plot.add_layout(DatetimeAxis(axis_label="Time"), "below") network_plot.add_layout(LinearAxis(axis_label="MB/s"), 'left') network_plot.add_layout( Legend(items=[('Network Send', [g1]), ('Network Recv', [g2])], **legend_opts)) tools = [ PanTool(dimensions='width'), WheelZoomTool(dimensions='width'), BoxZoomTool(), ResetTool() ] if 'sizing_mode' in kwargs: sizing_mode = {'sizing_mode': kwargs['sizing_mode']} else: sizing_mode = {} combo_toolbar = ToolbarBox(tools=tools, logo=None, toolbar_location='right', **sizing_mode) self.root = row(column(resource_plot, network_plot, **sizing_mode), column(combo_toolbar, **sizing_mode), id='bk-resource-profiles-plot', **sizing_mode) # Required for update callback self.resource_index = [0]
plsvg[i_series]=svg_canvas.add_glyph(peak_mzsvg[i_series], peak_lines[i_series], visible=False) peakmz_sele.js_link('active', plpc[i_series], 'visible') peakmz_sele.js_link('active', pl4k[i_series], 'visible') peakmz_sele.js_link('active', plsvg[i_series], 'visible') save4k_text= Button(label= " Create 4K PNG figure: ", width= 150, height=30, button_type='success') # save4k_text.js_link('active', highres_canvas, 'visible') savesvg_text= Button(label= " Create SVG figure: ", width= 150, height=30, button_type='success' ) # savesvg_text.js_link('active', svg_canvas, 'visible') linew_text= Div(text= " Line width ", width= 150, height=30 ) linew_inp = TextInput(value=str(sel_lines['Background'].line_width), disabled=False, width=100, height=30) save4k = ToolbarBox() save4k.toolbar = Toolbar(tools=highres_canvas.tools, logo=None) save4k.toolbar_location ='above' savesvg = ToolbarBox() savesvg.toolbar = Toolbar(tools=svg_canvas.tools, logo=None) savesvg.toolbar_location ='above' graph_text=Column(grid_text, labels_text, ticks_text, axes_text, peakmz_text, linew_text) graph_act=Column(grid_sele, labels_sele, ticks_sele, axes_sele, peakmz_sele, linew_inp) savesvg.visible=False save4k.visible=False posneg_text = Div(text= " Ion Charge", width= 150, height=30 ) data_header = Div(text= " <h2>Data Processing</h2>", height=45, width=400 ) posneg_header = Div(text= " <h2>Instrument Mode</h2>", height=45, width=400 ) # save4k.toolbar_options={'logo':None}
xwheel_zoom = WheelZoomTool(dimensions="width") pan_tool = PanTool() hover = HoverTool() crosshair = CrosshairTool() # tools = (xwheel_zoom, pan_tool, hover, crosshair) toolbar = Toolbar( tools=[xwheel_zoom, pan_tool, hover, crosshair], active_inspect=[crosshair], # active_drag = # here you can assign the defaults # active_scroll = # wheel_zoom sometimes is not working if it is set here # active_tap ) toolbar_box = ToolbarBox(toolbar=toolbar, toolbar_location="above") def generate_figures( metrics, best_epoch, y_train, # y_train_pred, y_test, # y_test_pred, X_train, X_test, seq_len, nome_rodada,
TOOLS = "hover,crosshair,pan,reset,box_select" def mkplot(): p = figure(width=300, height=300, tools=TOOLS, toolbar_location=None) p.scatter(x, y, radius=radii, fill_color=colors, fill_alpha=0.6, line_color=None) return p p_above = mkplot() tb_above = ToolbarBox(toolbar=p_above.toolbar, toolbar_location="above") p_below = mkplot() tb_below = ToolbarBox(toolbar=p_below.toolbar, toolbar_location="below") p_left = mkplot() tb_left = ToolbarBox(toolbar=p_left.toolbar, toolbar_location="left") p_right = mkplot() tb_right = ToolbarBox(toolbar=p_right.toolbar, toolbar_location="right") l_above = column(tb_above, p_above) l_below = column(p_below, tb_below) l_left = row(tb_left, p_left) l_right = row(p_right, tb_right)
def __init__(self, table, cols=[]): KPI.__init__(self, table, name='business', cols=cols) self.table = table self.df = None self.df1 = None self.df_pop = None self.checkboxgroup = {} self.period_to_date_cards = { } self.ptd_startdate = datetime(datetime.today().year, 1, 1, 0, 0, 0) self.timestamp_col = 'start_actual' self.pym = PythonMongo('aion') self.groupby_dict = { 'event': 'count', 'type':'count', 'rate':'sum', 'event_duration': 'sum', 'start_delay': 'mean', 'end_delay': ' mean', 'event_location':'count', 'patron':'count', 'patron_likes':'nunique', 'patron_gender':'count', 'patron_age':'mean', 'patron_friend':'nunique', 'patron_friend_gender':'count', 'patron_friend_age':'mean', 'patron_discovery':'nunique', 'manager':'count', 'manager_gender':'count', 'manager_age':'mean', 'manager_education':'count', 'manager_parish':'count', 'staff':'count', 'staff_gender':'count', 'staff_age':'mean', 'staff_education':'count', 'staff_parish':'count', 'remuneration':'sum', } self.menus = { 'company': [], 'type': [], 'patron':[], 'manager':[], 'gender': ['all', 'male', 'female','other'], 'variables': list(self.groupby_dict.keys()), 'history_periods': ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10'], } #self.variables = sorted(list(self.groupby_dict.keys())) self.variable = 'rate' # ######### SETUP FILTERS ######################### self.selects = { 'event': Select(title='Select event', value="all",options=['all']), 'company' : Select(title='Select company', value="all",options=['all']), 'patron_likes' : Select(title='Select patron likes/hobbies', value='all', options=['all']), 'patron' : Select(title='Select patron', value='all', options=['all']), 'manager_education' : Select(title="Select manager's education", value='all', options=['all']), 'staff_education' : Select(title="Select staff's education", value='all', options=['all']), 'manager_gender' : Select(title="Select manager's gender", value='all', options=self.menus['gender']), 'staff_gender' : Select(title="Select staff's gender", value='all', options=self.menus['gender']), 'patron_gender' : Select(title="Select patron's gender", value='all', options=self.menus['gender']), 'manager_parish' : Select(title="Select manager's parish", value='all', options=['all']), 'staff_parish' : Select(title="Select staff's parish", value='all', options=['all']), 'patron_parish' : Select(title="Select patron's parish", value='all', options=['all']), 'type': Select(title="Select event type", value='all', options=['all']), } self.vars = { 'event': 'all', 'company': 'all', 'patron_likes': 'all', 'patron': 'all', 'manager_education': 'all', 'staff_education': 'all', 'manager_gender': 'all', 'staff_gender': 'all', 'patron_gender': 'all', 'manager_parish':'all', 'patron_parish':'all', 'type':'all' } self.multiline_vars = { 'xs' : ['patron_likes','manager_education','staff_education', 'manager_gender','staff_gender','patron_gender','manager_parish', 'patron_parish','type'], 'ys': ['rate','remuneration','attendance'] } self.multiline_variable = { 'x':'manager_gender', 'y':'rate' } self.resample_period = { 'multiline' : 'D' } self.chord_data = { 'rename': { 'patron': 'source', 'company': 'target', 'rate': 'value' }, 'percentile_threshold': .75, } self.feature_list = self.multiline_vars['xs'] + ['rate','remuneration','start_delay','end_delay', 'staff_age','manager_age','patron_age'] self.percentile_threshold = 10 self.tsa_variable = 'event' self.forecast_days = 30 self.initial_date = datetime.strptime('2015-01-01 00:00:00',self.DATEFORMAT) self.datepicker_pop_start = DatePicker( title="Period start", min_date=self.initial_date, max_date=dashboard_config['dates']['last_date'], value=dashboard_config['dates']['last_date']) # ------- DIVS setup begin self.page_width = 1200 txt = """<hr/><div style="text-align:center;width:{}px;height:{}px; position:relative;background:black;margin-bottom:200px"> <h1 style="color:#fff;margin-bottom:300px">{}</h1> </div>""".format(self.page_width, 50, 'Welcome') self.notification_div = { 'top': Div(text=txt, width=self.page_width, height=20), 'bottom': Div(text=txt, width=self.page_width, height=10), } self.section_divider = '-----------------------------------' self.section_headers = { 'cards': self.section_header_div(text='Period to date:{}'.format(self.section_divider), width=1000, html_header='h2', margin_top=50, margin_bottom=5), 'pop': self.section_header_div(text='Period over period:{}'.format(self.section_divider), width=600, html_header='h2', margin_top=5, margin_bottom=-155), 'chord': self.section_header_div(text='Patron networks:{}'.format(self.section_divider), width=600, html_header='h3', margin_top=5, margin_bottom=-155), 'tsa': self.section_header_div(text='Forecasts (TSA):{}'.format(self.section_divider), width=600, html_header='h2', margin_top=5, margin_bottom=-155), 'multiline': self.section_header_div(text='Comparative graphs:{}'.format(self.section_divider), width=600, html_header='h2', margin_top=5, margin_bottom=-155), 'patron info': self.section_header_div(text='Patron info:{}'.format(self.section_divider), width=600, html_header='h2', margin_top=5, margin_bottom=-155), 'relationships': self.section_header_div(text='Statistically Significant Relationships:---', width=600, html_header='h2', margin_top=5, margin_bottom=-155), } self.KPI_card_div = self.initialize_cards(self.page_width, height=40) start = datetime(2014, 1, 1, 0, 0, 0) end = datetime(2019, 5, 15, 0, 0, 0) self.tools = [BoxZoomTool(), ResetTool(), PanTool(), SaveTool(), WheelZoomTool()] self.timeline_vars = { 'company': '', 'event': '', 'types': ['all'], 'type': 'all', 'DF': None, 'G': figure( title=None, x_axis_type='datetime', width=1200, height=900, y_range=[], x_range=Range1d(start, end), toolbar_location=None), 'toolbar_box': ToolbarBox() }