def pyramid_plot(self): from bokeh.models import (Plot, DataRange1d, LinearAxis, Grid, Legend, SingleIntervalTicker) from bokeh.models.glyphs import Quad xdr = DataRange1d(sources=[self.source_pyramid.columns("male"), self.source_pyramid.columns("female")]) ydr = DataRange1d(sources=[self.source_pyramid.columns("groups")]) self.plot = Plot(title="Widgets", x_range=xdr, y_range=ydr, plot_width=600, plot_height=600) xaxis = LinearAxis() self.plot.add_layout(xaxis, 'below') yaxis = LinearAxis(ticker=SingleIntervalTicker(interval=5)) self.plot.add_layout(yaxis, 'left') self.plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) self.plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) male_quad = Quad(left="male", right=0, bottom="groups", top="shifted", fill_color="#3B8686") male_quad_glyph = self.plot.add_glyph(self.source_pyramid, male_quad) female_quad = Quad(left=0, right="female", bottom="groups", top="shifted", fill_color="#CFF09E") female_quad_glyph = self.plot.add_glyph(self.source_pyramid, female_quad) self.plot.add_layout(Legend(legends=dict(Male=[male_quad_glyph], Female=[female_quad_glyph])))
def create_quads(df, x, top, bottom, bar_width=.5, hover_tool=None): ''' vertical quads (rectangles) at x positions from bottom to top ''' tools = [] if hover_tool: tools = [hover_tool,] source = ColumnDataSource(dict( left=(df[x]+timedelta(days=bar_width/2.)).values, top=df[top], right=(df[x]-timedelta(days=bar_width/2.)).values, bottom=df[bottom], ) ) plot = figure(plot_width=320, plot_height=200, x_axis_type='datetime', y_axis_type='datetime', tools=tools, #responsive=True, toolbar_location="above", ) glyph = Quad(left="left", right="right", top="top", bottom="bottom", fill_color="#0b5789") plot.add_glyph(source, glyph) return plot
def test_Quad(): glyph = Quad() assert glyph.left == "left" assert glyph.right == "right" assert glyph.bottom == "bottom" assert glyph.top == "top" yield check_fill, glyph yield check_line, glyph yield check_props, glyph, ["left", "right", "bottom", "top"], FILL, LINE
def generate_plots(self, doc): self.hist_plot = {} get_score_by_simulation(self.total_pandas_df, self.sq_err_names) self.hist_plot['plotting_data'] = np.array( self.total_pandas_df['score']) self.hist_plot['plot_width'] = 1000 self.hist_plot['plot_height'] = 500 self.hist_plot['title'] = 'Simulation Score Histogram' self.hist_plot['object_figure'] = figure( width=self.hist_plot['plot_width'], height=self.hist_plot['plot_height'], title=self.hist_plot['title']) self.hist_plot['source'] = ColumnDataSource( data=dict(hist=[], left_edge=[], right_edge=[])) self.hist_plot['pdf_source'] = ColumnDataSource( data=dict(x=[], y_pdf=[])) # get stats and gaus fit gauss_dict = gaussian_fit(name='score', total_df=self.total_pandas_df) hist = gauss_dict['hist'] edges = gauss_dict['edges'] x = gauss_dict['x'] pdf = gauss_dict['pdf'] self.hist_plot['source'].data = { 'hist': hist, 'left_edge': edges[:-1], 'right_edge': edges[1:] } self.hist_plot['pdf_source'].data = {'x': x, 'y_pdf': pdf} self.hist_plot['quad_glyph'] = Quad(top='hist', bottom=0, left='left_edge', right='right_edge') self.hist_plot['pdf_glyph'] = Line(x='x', y='y_pdf', line_color="#D95B43", line_width=8, line_alpha=0.7) self.hist_plot['object_figure'].add_glyph(self.hist_plot['source'], self.hist_plot['quad_glyph']) self.hist_plot['object_figure'].add_glyph(self.hist_plot['pdf_source'], self.hist_plot['pdf_glyph']) self.hist_plot['object_figure'].yaxis.axis_label = 'Relative Frequency' self.hist_plot['object_figure'].xaxis.axis_label = 'Simulation Score' doc.add_root(self.hist_plot['object_figure']) self.write_text_file()
def pyramid(): xdr = DataRange1d(sources=[ source_pyramid.columns("male"), source_pyramid.columns("female") ]) ydr = DataRange1d(sources=[source_pyramid.columns("groups")]) plot = Plot(title=None, x_range=xdr, y_range=ydr, plot_width=600, plot_height=600) xaxis = LinearAxis() plot.add_layout(xaxis, 'below') yaxis = LinearAxis(ticker=SingleIntervalTicker(interval=5)) plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) male_quad = Quad(left="male", right=0, bottom="groups", top="shifted", fill_color="#3B8686") male_quad_glyph = plot.add_glyph(source_pyramid, male_quad) female_quad = Quad(left=0, right="female", bottom="groups", top="shifted", fill_color="#CFF09E") female_quad_glyph = plot.add_glyph(source_pyramid, female_quad) plot.add_layout( Legend(legends=[("Male", [male_quad_glyph]), ("Female", [female_quad_glyph])])) return plot
def foamtree_root(root): root.top = 14 root.bottom = 6 root.left = 6 root.right = 14 root.area = (root.top - root.bottom) * (root.right - root.left) glyph = Quad(left=root.left, right=root.right, top=root.top, bottom=root.bottom, fill_color=root.color, fill_alpha=0.5) plot.add_glyph(source, glyph) foamtree(root)
def test_Quad(): glyph = Quad() assert glyph.left is None assert glyph.right is None assert glyph.bottom is None assert glyph.top is None check_fill_properties(glyph) check_line_properties(glyph) check_properties_existence(glyph, [ "left", "right", "bottom", "top", ], FILL, LINE, GLYPH)
def test_Quad(): glyph = Quad() assert glyph.left is None assert glyph.right is None assert glyph.bottom is None assert glyph.top is None yield check_fill, glyph yield check_line, glyph yield (check_props, glyph, [ "left", "right", "bottom", "top", ], FILL, LINE)
def broken_barh(intervals, y_position, height, color='gray', mode="start_end", fig=None, options={}): """Create a broken_barh glyph and adds it to a figure if fig is given, else returns the source and the glyph. :param intervals: numpy.array :Note: Usage: > broken_barh(intervals, 2, 0.6, fig=p, color=["#9933FF"],options=default_options) or > source, glyph = broken_barh(intervals, 2, 0.6, color=["#FF00FF"], options=default_options) > p.add_glyph(source, glyph) """ from bokeh.models.glyphs import Quad from bokeh.models import ColumnDataSource assert (mode in ['start_end', 'start_width']), "Unknown mode" assert (isinstance(color, list)), "color has to be a list" nb_interval = intervals.shape[0] half_heigth = height / 2 if mode == "start_end": right = intervals[:, 1] elif mode == "start_width": right = intervals.sum(1) if len(color) == 1 and nb_interval != 1: color = nb_interval * [color[0]] quad_parameters = { "bottom": [y_position - half_heigth for i in range(nb_interval)], "top": [y_position + half_heigth for i in range(nb_interval)], "left": intervals[:, 0], "right": right, "fill_color": color } if fig is not None: # append any other options for opt_name, opt_values in options.items(): quad_parameters[opt_name] = opt_values quad_parameters["fill_color"] = color fig.quad(**quad_parameters) else: glyph = Quad(bottom="bottom", top="top", left="left", right="right", fill_color="fill_color", **options) source = ColumnDataSource(quad_parameters) return source, glyph
def generate_histogram(): nonlocal hist_plot hist_plot['plotting_data'] = np.array( data_handler.total_df[self.select_widget_hist.value]) hist_plot['plot_width'] = 610 hist_plot['plot_height'] = 400 hist_plot[ 'title'] = 'Gaussian Fit of ' + self.select_widget_hist.value hist_plot['object_figure'] = figure( width=hist_plot['plot_width'], height=hist_plot['plot_height'], title=hist_plot['title']) hist_plot['source'] = ColumnDataSource( data=dict(hist=[], left_edge=[], right_edge=[])) hist_plot['pdf_source'] = ColumnDataSource( data=dict(x=[], y_pdf=[])) # get stats and gaus fit data_handler.general_stats(self.select_widget_hist.value, None) data_handler.gaussian_fit( data_handler.total_df[self.select_widget_hist.value], data_handler.mu, data_handler.sigma, min(data_handler.total_df[self.select_widget_hist.value]), max(data_handler.total_df[self.select_widget_hist.value])) hist_plot['source'].data = { 'hist': data_handler.hist, 'left_edge': data_handler.edges[:-1], 'right_edge': data_handler.edges[1:] } hist_plot['pdf_source'].data = { 'x': data_handler.x, 'y_pdf': data_handler.pdf } hist_plot['quad_glyph'] = Quad(top='hist', bottom=0, left='left_edge', right='right_edge') hist_plot['pdf_glyph'] = Line(x='x', y='y_pdf', line_color="#D95B43", line_width=8, line_alpha=0.7) hist_plot['object_figure'].add_glyph(hist_plot['source'], hist_plot['quad_glyph']) hist_plot['object_figure'].add_glyph(hist_plot['pdf_source'], hist_plot['pdf_glyph'])
def test_Quad() -> None: glyph = Quad() assert glyph.left == field("left") assert glyph.right == field("right") assert glyph.bottom == field("bottom") assert glyph.top == field("top") check_line_properties(glyph) check_fill_properties(glyph) check_hatch_properties(glyph) check_properties_existence(glyph, [ "left", "right", "bottom", "top", ], FILL, HATCH, LINE, GLYPH)
def create_vhist(peak_source, p): # create the vertical histogram # LINE_ARGS = dict(color="#3A5785", line_color=None) data = peak_source.data['PEAK'] vhist, vedges = np.histogram(data, bins=10) vzeros = np.zeros(len(vedges) - 1) vmax = max(vhist) * 1.1 hist_source = ColumnDataSource({ 'top': vedges[1:], 'right': vhist, 'bottom': vedges[:-1], 'left': np.zeros_like(vhist) }) pv = figure(toolbar_location=None, plot_width=175, plot_height=p.height, min_border=10, y_axis_location="right") pv.ygrid.grid_line_color = None pv.xaxis.major_label_orientation = np.pi / 4 pv.background_fill_color = "#fafafa" glyph = Quad(left="left", bottom="bottom", top="top", right="right", fill_color='blue', fill_alpha=0.3) pv.add_glyph(hist_source, glyph) vh1 = pv.quad(left=0, bottom=vedges[:-1], top=vedges[1:], right=vzeros, alpha=0.7) # vh2 = pv.quad(left=0, bottom=vedges[:-1], top=vedges[1:], # right=vzeros, alpha=0.6) return vh1, pv, hist_source
def foamtree(node): if node.children: open_space_left = node.left open_space_top = node.top open_space_bottom = node.bottom open_space_right = node.right for n in node.children: if not n.seen: n.area = (n.leaves_subtree / n.parent.leaves_subtree) * n.parent.area if (open_space_right - open_space_left) >= (open_space_top - open_space_bottom): n.top = open_space_top n.bottom = open_space_bottom n.left = open_space_left n.right = (n.area / (n.top - n.bottom)) + n.left on_width = True else: n.top = open_space_top n.left = open_space_left n.right = open_space_right n.bottom = -(n.area / (n.right - n.left)) + n.top on_width = False glyph = Quad(left=n.left, right=n.right, top=n.top, bottom=n.bottom, fill_color=n.color, fill_alpha=0.5) plot.add_glyph(source, glyph) if on_width: open_space_left = n.right else: open_space_top = n.bottom foamtree(n) n.seen = True
def plot_detailed_profiler_data(self, indexes): if len(indexes) > 0: cpu_util = None for key in self.system_metrics.keys(): if key.startswith("CPUUtilization"): width = self.system_metrics[key]["cpu0"].shape[0] if cpu_util is None or np.min(indexes) <= width <= np.max( indexes): cpu_util = self.system_metrics[key] begin_timestamp = cpu_util["cpu0"][np.min(indexes), 0] end_timestamp = cpu_util["cpu0"][np.max(indexes), 0] print( f"Selected timerange: {begin_timestamp + self.start} to {end_timestamp + self.start}" ) events = self.framework_metrics_reader.get_events( begin_timestamp + self.start, end_timestamp + self.start, unit=TimeUnits.SECONDS) dataloaders = self.plot_dataloaders(events, begin_timestamp + self.start, end_timestamp + self.start) framework_events = self.plot_framework_events( events, begin_timestamp + self.start, end_timestamp + self.start) # define figure plot_dataloaders = figure( plot_height=250, plot_width=1000, tools="crosshair,xbox_select,pan,reset,save,xwheel_zoom", ) plot_dataloaders.xaxis.axis_label = "Time in ms" plot_dataloaders.yaxis.axis_label = "Thread ID" # tooltip hover = HoverTool(tooltips=[("metric", "@metric"), ("index", "$x{10}")]) for event in dataloaders.keys(): for entry in range(len(dataloaders[event])): # create source that contains time annotations source = ColumnDataSource(data=dict( top=[dataloaders[event][entry][2]], bottom=[dataloaders[event][entry][2] - 1], left=[dataloaders[event][entry][0]], right=[dataloaders[event][entry][1]], metric=[event], )) # vertical bars quad = Quad( top="top", bottom="bottom", left="left", right="right", fill_color="black", line_color=None, fill_alpha=0.2, ) # plot plot_dataloaders.add_glyph(source, quad) plot_dataloaders.add_tools(hover) plot_framework_events = figure( plot_height=250, plot_width=1000, tools="crosshair,xbox_select,pan,reset,save,xwheel_zoom", ) plot_framework_events.xaxis.axis_label = "Time in ms" plot_framework_events.yaxis.axis_label = "Framework metric" # tooltip hover = HoverTool(tooltips=[("metric", "@metric"), ("index", "$x{10}")]) for event in framework_events.keys(): for entry in range(len(framework_events[event])): # create source that contains time annotations source = ColumnDataSource(data=dict( top=[framework_events[event][entry][2]], bottom=[framework_events[event][entry][2] - 1], left=[framework_events[event][entry][0]], right=[framework_events[event][entry][1]], metric=[event], )) # vertical bars quad = Quad( top="top", bottom="bottom", left="left", right="right", fill_color="blue", fill_alpha=0.2, line_color=None, ) # plot plot_framework_events.add_glyph(source, quad) plot_framework_events.add_tools(hover) p = column([plot_dataloaders, plot_framework_events]) self.target = show(p, notebook_handle=True) else: print("No selection made")
), anchor="center")), ("line", Line(x="x", y="y", line_color="#F46D43")), ("multi_line", MultiLine(xs="xs", ys="ys", line_color="#8073AC", line_width=2)), ("oval", Oval(x="x", y="y", width=screen(15), height=screen(25), angle=-0.7, fill_color="#1D91C0")), ("patch", Patch(x="x", y="y", fill_color="#A6CEE3")), ("patches", Patches(xs="xs", ys="ys", fill_color="#FB9A99")), ("quad", Quad(left="x", right="xp01", top="y", bottom="ym01", fill_color="#B3DE69")), ("quadratic", Quadratic(x0="x", y0="y", x1="xp02", y1="y", cx="xp01", cy="yp01", line_color="#4DAF4A", line_width=3)), ("ray", Ray(x="x", y="y", length=45, angle=-0.7, line_color="#FB8072",
xdr = DataRange1d(sources=[source.columns("left", "right")]) ydr = DataRange1d(sources=[source.columns("top", "bottom")]) plot = Plot(title=None, x_range=xdr, y_range=ydr, plot_width=300, plot_height=300, h_symmetry=False, v_symmetry=False, min_border=0, toolbar_location=None) glyph = Quad(left="left", right="right", top="top", bottom="bottom", fill_color="#b3de69") plot.add_glyph(source, glyph) xaxis = LinearAxis() plot.add_layout(xaxis, 'below') yaxis = LinearAxis() plot.add_layout(yaxis, 'left') plot.add_layout(Grid(dimension=0, ticker=xaxis.ticker)) plot.add_layout(Grid(dimension=1, ticker=yaxis.ticker)) doc = Document() doc.add(plot)
def generate_plots(self, doc): ''' :param doc: curdoc() required for bokeh function handler :return: None ''' ''' ---------------------------------------------------------------------------------------------------------- Define Histogram ---------------------------------------------------------------------------------------------------------- ''' self.hist_plot = {} self.hist_plot['plotting_data'] = np.array( self.total_pandas_df[self.select_widget_hist.value]) self.hist_plot['plot_width'] = 610 self.hist_plot['plot_height'] = 400 self.hist_plot[ 'title'] = 'Gaussian Fit of ' + self.select_widget_hist.value self.hist_plot['object_figure'] = figure( width=self.hist_plot['plot_width'], height=self.hist_plot['plot_height'], title=self.hist_plot['title']) self.hist_plot['source'] = ColumnDataSource( data=dict(hist=[], left_edge=[], right_edge=[])) self.hist_plot['pdf_source'] = ColumnDataSource( data=dict(x=[], y_pdf=[])) # get stats and gaus fit hist_stats_list = basic_stats([self.select_widget_hist.value], self.total_pandas_df) mu = hist_stats_list[0][self.select_widget_hist.value][0] sigma = hist_stats_list[0][self.select_widget_hist.value][2] gauss_dict = gaussian_fit(self.select_widget_hist.value, self.total_pandas_df) hist = gauss_dict['hist'] edges = gauss_dict['edges'] x = gauss_dict['x'] pdf = gauss_dict['pdf'] self.hist_plot['source'].data = { 'hist': hist, 'left_edge': edges[:-1], 'right_edge': edges[1:] } self.hist_plot['pdf_source'].data = {'x': x, 'y_pdf': pdf} self.hist_plot['quad_glyph'] = Quad(top='hist', bottom=0, left='left_edge', right='right_edge') self.hist_plot['pdf_glyph'] = Line(x='x', y='y_pdf', line_color="#D95B43", line_width=8, line_alpha=0.7) self.hist_plot['object_figure'].add_glyph(self.hist_plot['source'], self.hist_plot['quad_glyph']) self.hist_plot['object_figure'].add_glyph(self.hist_plot['pdf_source'], self.hist_plot['pdf_glyph']) ''' ---------------------------------------------------------------------------------------------------------- Define Heatmap ---------------------------------------------------------------------------------------------------------- ''' self.heat_map = {} heat_frame = set_color(self.select_widget_1.value, self.select_widget_2.value, self.total_pandas_df) self.heat_map_source = ColumnDataSource(heat_frame) self.points_source = ColumnDataSource( data=dict(x=self.total_pandas_df[self.select_widget_1.value], y=self.total_pandas_df[self.select_widget_2.value])) self.heat_map['plot_width'] = 610 self.heat_map['plot_height'] = 400 self.heat_map[ 'title'] = "Heat Map of " + self.select_widget_1.value + ' vs. ' + self.select_widget_2.value self.heat_map['object_figure'] = figure( width=self.heat_map['plot_width'], height=self.heat_map['plot_height'], title=self.heat_map['title']) colors = [ '#FF0000', '#F2000D', '#E6001A', '#D90026', '#CC0033', '#BF0040', '#B2004C', '#A60059', '#990066', '#8C0073', '#800080', '#73008C', '#660099', '#5900A6', '#4D00B2', '#4000BF', '#3300CC', '#2600D9', '#1900E6', '#0D00F2', '#0000FF' ] # mapper is a transform required by bokeh to generate heatmaps mapper = LinearColorMapper(palette=colors, low=heat_frame['heat_values'].min(), high=heat_frame['heat_values'].max()) self.heat_map['circle_glyph'] = Circle(x='x', y='y', size=1, line_color=None, fill_color='black') self.heat_map['rect_glyph'] = Rect( x="rect_x", y="rect_y", width=heat_frame['rect_width'].loc[0], height=heat_frame['rect_width'].loc[0], fill_color={ 'field': 'heat_values', 'transform': mapper }, line_color=None, fill_alpha=0.75) self.heat_map['object_figure'].add_glyph(self.points_source, self.heat_map['circle_glyph']) self.heat_map['object_figure'].add_glyph(self.heat_map_source, self.heat_map['rect_glyph']) self.heat_map['color_bar'] = ColorBar( color_mapper=mapper, major_label_text_font_size="5pt", ticker=BasicTicker(desired_num_ticks=len(colors)), label_standoff=6, border_line_color=None, location=(0, 0), background_fill_alpha=0.75) self.heat_map['object_figure'].add_layout(self.heat_map['color_bar'], 'left') WIDGETBOX_WIDTH = 610 self.layout = layout([ self.select_widget_1, self.select_widget_2, self.select_widget_hist ], [self.heat_map['object_figure'], self.hist_plot['object_figure'] ], [self.x_range_slider, self.y_range_slider], [ widgetbox(self.data_table_heat, width=WIDGETBOX_WIDTH), widgetbox(self.data_table_hist, width=WIDGETBOX_WIDTH) ]) # unavoidable resize error forces two figures to be displayed at once rather that switch between # data can be updated easily but plot type should remain static # https://groups.google.com/a/continuum.io/forum/#!topic/bokeh/P2WPJ9an7IQ doc.add_root(self.layout) """ -------------------------------------------------------------------- Callbacks -------------------------------------------------------------------- """ def select_1_callback(attrname, old, new): self.points_source.data['x'] = self.total_pandas_df[new] self.data_table_heat.columns = [ TableColumn(field="labels", title="Statistics", width=int(self.DATA_TABLE_COL_WIDTH * 0.6)), TableColumn(field="variable_1", title=new, width=self.DATA_TABLE_COL_WIDTH), TableColumn(field="variable_2", title=self.select_widget_2.value, width=self.DATA_TABLE_COL_WIDTH), TableColumn(field="variable_1_2", title=new + ' and ' + self.select_widget_2.value, width=int(self.DATA_TABLE_COL_WIDTH * 1.8)) ] heat_frame = set_color(new, self.select_widget_2.value, self.total_pandas_df) self.heat_map_source.data['rect_x'] = heat_frame['rect_x'] self.heat_map_source.data['rect_width'] = heat_frame['rect_width'] self.heat_map_source.data['heat_values'] = heat_frame[ 'heat_values'] self.data_table_heat.source = ColumnDataSource( fill_data_table([new, self.select_widget_2.value], self.total_pandas_df)) self.heat_map[ 'object_figure'].title.text = "Heat Map of " + new + ' vs. ' + self.select_widget_2.value self.x_range_slider.start = self.total_pandas_df[new].min() self.x_range_slider.end = self.total_pandas_df[new].max() self.x_range_slider.step = (self.total_pandas_df[new].max() - self.total_pandas_df[new].min()) / 100 self.x_range_slider.value = (self.total_pandas_df[new].min(), self.total_pandas_df[new].max()) self.select_widget_1.on_change('value', select_1_callback) def select_2_callback(attrname, old, new): self.points_source.data['y'] = self.total_pandas_df[new] self.data_table_heat.columns = [ TableColumn(field="labels", title="Statistics", width=int(self.DATA_TABLE_COL_WIDTH * 0.6)), TableColumn(field="variable_1", title=self.select_widget_1.value, width=self.DATA_TABLE_COL_WIDTH), TableColumn(field="variable_2", title=new, width=self.DATA_TABLE_COL_WIDTH), TableColumn(field="variable_1_2", title=self.select_widget_1.value + ' and ' + new, width=int(self.DATA_TABLE_COL_WIDTH * 1.8)) ] heat_frame = set_color(self.select_widget_1.value, new, self.total_pandas_df) self.heat_map_source.data['rect_y'] = heat_frame['rect_y'] self.heat_map_source.data['rect_height'] = heat_frame[ 'rect_height'] self.heat_map_source.data['heat_values'] = heat_frame[ 'heat_values'] self.data_table_heat.source = ColumnDataSource( fill_data_table([new, self.select_widget_2.value], self.total_pandas_df)) self.heat_map[ 'object_figure'].title.text = "Heat Map of " + self.select_widget_1.value + ' vs. ' + new self.y_range_slider.start = self.total_pandas_df[new].min() self.y_range_slider.end = self.total_pandas_df[new].max() self.y_range_slider.step = (self.total_pandas_df[new].max() - self.total_pandas_df[new].min()) / 100 self.y_range_slider.value = (self.total_pandas_df[new].min(), self.total_pandas_df[new].max()) self.select_widget_2.on_change('value', select_2_callback) def select_hist_callback(attrname, old, new): # get stats and gaus fit hist_stats_list = basic_stats([new], self.total_pandas_df) mu = hist_stats_list[0][new][0] sigma = hist_stats_list[0][new][2] gauss_dict = gaussian_fit(new, self.total_pandas_df) hist = gauss_dict['hist'] edges = gauss_dict['edges'] x = gauss_dict['x'] self.hist_plot['source'].data = { 'hist': hist, 'left_edge': edges[:-1], 'right_edge': edges[1:] } if new not in self.sq_err_names: pdf = gauss_dict['pdf'] else: pdf = chi_squared(new, self.total_pandas_df) self.hist_plot['pdf_source'].data = {'x': x, 'y_pdf': pdf} self.hist_plot[ 'object_figure'].title.text = "Gaussian Fit of " + new self.data_table_hist.source = ColumnDataSource( fill_data_table([new], self.total_pandas_df)) self.data_table_hist.columns = [ TableColumn(field="labels", title="Statistics", width=self.DATA_TABLE_COL_WIDTH), TableColumn(field="variable_1", title=new, width=self.DATA_TABLE_COL_WIDTH) ] self.select_widget_hist.on_change('value', select_hist_callback) def x_range_callback(attrname, old, new): self.heat_map['object_figure'].x_range.start = new[0] self.heat_map['object_figure'].x_range.end = new[1] def y_range_callback(attrname, old, new): self.heat_map['object_figure'].y_range.start = new[0] self.heat_map['object_figure'].y_range.end = new[1] self.x_range_slider.on_change('value', x_range_callback) self.y_range_slider.on_change('value', y_range_callback)
def CapTreemap(team, year): # TODO: this is just a placeholder demo # get the data df = pd.read_csv('data/NFLSalaryCap.data') Team = NFLTeam filltree(Team, df[(df['Team'] == team) & (df['Year'] == year)]) preptree(Team) queue = list() Team.x = 0 Team.y = 0 Team.dx = 600 Team.dy = 600 queue.append(Team) glyphs = list() treemap(queue, glyphs) # get data x_range = Range1d(0, 600, bounds=(0, 600)) y_range = Range1d(0, 600, bounds=(0, 600)) TOOLS = "hover,save" p = figure(title=TeamName[team] + ' Cap Usage (' + str(year) + ')', x_range=x_range, y_range=y_range, plot_width=600, plot_height=600) p.grid.grid_line_color = None p.axis.visible = False # p.axis.axis_line_color = None # p.axis.major_tick_line_color = None # p.axis.minor_tick_line_color = None # p.axis.major_label_standoff = 0 # p.axis.major_label_text_font_size = '10pt' #TODO: mapping of team colors is an embarassment of dictionaries; # need to refactor the entire aesthetic side of this thing for glyph in glyphs: rect = Quad(left=glyph['x'], right=glyph['x'] + glyph['dx'], bottom=glyph['y'], top=glyph['y'] + glyph['dy'], fill_color=TeamColors[team][colordict[glyph['label']]]) if glyph['label'] in ['Offense', 'Defense', 'SpecialTeams']: label = Label(x=glyph['x'] + glyph['dx'] / 2, y=glyph['y'] + glyph['dy'] / 2, text=glyph['label'], text_font_size='14pt', text_font_style='bold', text_color='white') elif glyph['label'] in ['LB', 'OL', 'DL', 'DB', 'RB']: label = Label(x=glyph['x'], y=glyph['y'] + glyph['dy'] - 20, text=glyph['label'], text_font_style='bold', text_color='white') else: label = Label(x=glyph['x'], y=glyph['y'], text=glyph['label'], text_font_style='bold', text_color='white') p.add_glyph(rect) p.add_layout(label) return p