def display_season_overview(src, seasonNum, yrange, xrange): # creating and displaying visualizations figure_season_overview = figure(title="Season Overview : "+str(seasonNum), tools="hover, save",\ y_range=yrange, x_range=list(xrange), plot_width=1200, plot_height=500) figure_season_overview.xaxis.major_label_orientation = 45 # Configuring figure_season_overview.yaxis.axis_label = 'Stadium Cities' # figure figure_season_overview.xaxis.axis_label = 'Dates' # settings rect = Rect(x="dates", y="cities", width=0.8, height=0.8, fill_alpha=0.8, fill_color="type_color") rect_render = figure_season_overview.add_glyph(src, rect) legend = Legend(items=[ LegendItem(label=field("label"), renderers=[rect_render]) ]) figure_season_overview.add_layout(legend, 'left') figure_season_overview.legend.background_fill_color = "grey" figure_season_overview.legend.background_fill_alpha = 0.1 figure_season_overview.legend.border_line_color = "black" figure_season_overview.select_one(HoverTool).tooltips = [ ("Date", "@dates"), ("Team1", "@team1"), # Configuring ("Team2", "@team2"), # Hover ("Venue", "@venues"), # Tool ("City", "@cities"), ("Winner", "@winners"), ("Man of the match","@player_of_match") ] return figure_season_overview # displaying generated visualization
def plot_sequence(seq, plot_width=1000, plot_height=20, fontsize='10pt', xaxis=True, tools=""): """Plot a single sequence. Args: seq: sequence to plot, a string xaxis: display x-axis tick labels or not tools: which bokeh tools to display, if needed """ if seq is None or len(seq) == 0: return plotters.plot_empty('no sequence', plot_width=plot_width, plot_height=plot_height) text = list(seq) N = len(seq) x = np.array(range(N)) + 1 colors = utils.get_sequence_colors([seq]) source = ColumnDataSource(dict(x=x, text=text, colors=colors)) x_range = Range1d(0, N, bounds='auto') p = figure(plot_width=plot_width, plot_height=plot_height, x_range=x_range, y_range=(0, 1), tools=tools, min_border=0, toolbar_location='below') rects = Rect(x="x", y=0, width=1, height=2, fill_color="colors", line_color=None, fill_alpha=0.4) p.add_glyph(source, rects) if len(seq) < 200: glyph = Text(x="x", y=0, text="text", text_align='center', text_color="black", text_font="monospace", text_font_size=fontsize) p.add_glyph(source, glyph) p.grid.visible = False if xaxis == False: p.xaxis.visible = False else: if plot_height < 40: p.plot_height = 50 if tools != "": p.plot_height = 70 p.yaxis.visible = False p.toolbar.logo = None return p
def test1(rows=20, cols=100, plot_width=800): """Bokeh random colors plot""" x = np.arange(1, cols) y = np.arange(0, rows, 1) xx, yy = np.meshgrid(x, y) gx = xx.ravel() gy = yy.flatten() colors = utils.random_colors(len(gx)) source = ColumnDataSource(dict(x=gx, y=gy, color=colors)) plot_height = 50 x_range = Range1d(0, 10, bounds='auto') #entire sequence view (no text, with zoom) p = figure(title=None, plot_width=plot_width, plot_height=300, tools="xpan,xwheel_zoom,save,reset") rects = Rect(x="x", y="y", width=1, height=1, fill_color="color", line_width=0) p.add_glyph(source, rects) p.yaxis.visible = False p.grid.visible = False p.toolbar.logo = None #p = gridplot([[p]], toolbar_location='right') return p
def topicplot(): xdr = DataRange1d(sources=[topicsource.columns("width")]) ydr = FactorRange(factors=list(reversed(list(barDefault2.Term)))) #"Top-{R} Most Relevant Terms for Topic {topic} ({count}% of tokens)".format(R=R, ...) title = "Top-{R} Most Salient Terms".format(R=R) plot = Plot(title=title, title_text_font_size="16px", x_range=xdr, y_range=ydr, plot_width=mdswidth, plot_height=mdsheight) plot.add_glyph( topicsource, Rect(x="x", y="y", width="width", height=1, fill_color=base_color, fill_alpha=0.2, line_color=base_color)) plot.add_layout(LinearAxis(), "above") plot.add_layout(CategoricalAxis(), "left") return plot
def legend(): # Set ranges xdr = Range1d(0, 100) ydr = Range1d(0, 500) # Create plot plot = Plot( x_range=xdr, y_range=ydr, title="", plot_width=500, plot_height=500, min_border=0, toolbar_location=None, outline_line_color="#FFFFFF", ) # For each color in your palette, add a Rect glyph to the plot with the appropriate properties palette = RdBu11 width = 40 for i, color in enumerate(palette): rect = Rect(x=40, y=(width * (i + 1)), width=width, height=40, fill_color=color, line_color='black') plot.add_glyph(rect) # Add text labels and add them to the plot minimum = Text(x=50, y=0, text=['-6 ºC']) plot.add_glyph(minimum) maximum = Text(x=50, y=460, text=['6 ºC']) plot.add_glyph(maximum) return plot
def build_renderers(self): glyph = Rect(x='x', y='y', width='width', height='height', fill_color='color', fill_alpha='fill_alpha') yield GlyphRenderer(glyph=glyph)
def build_renderers(self): """Yields a `GlyphRenderer` associated with a `Rect` glyph.""" glyph = Rect(x='x', y='y', width='width', height='height', fill_color='color', fill_alpha='fill_alpha', line_color='line_color') yield GlyphRenderer(glyph=glyph)
def test_Rect(): glyph = Rect() assert glyph.x == "x" assert glyph.y == "y" assert glyph.width == "width" assert glyph.height == "height" assert glyph.angle == "angle" assert glyph.dilate == False yield check_fill, glyph yield check_line, glyph yield check_props, glyph, ["x", "y", "width", "height", "angle", "dilate"], FILL, LINE
def draw(self, plot): rect = Rect(x="x", y="y", width='width', height='height', fill_alpha=0.3, fill_color="#de5eff") plot.add_glyph(self.sources['integration'], rect, selection_glyph=rect, nonselection_glyph=rect) plot.add_tools(self.tool)
def africa_map_add_legend(palette, africa_map_plot_width): """This creates the colormap legend under the map of Africa. Input: palette: Defines colormap to use in legend africa_map_plot_width: Width of map plot used for scaling/positioning Credit: Adds glyphs for legend. Based on [1] References: [1] https://github.com/chdoig/scipy2015-blaze-bokeh/blob/master /1.5%20Glyphs%20-%20Legend%20(solution).ipynb """ # Set ranges xdr = Range1d(0, africa_map_plot_width) ydr = Range1d(0, 60) # Create plot legend = Plot( x_range=xdr, y_range=ydr, plot_width=africa_map_plot_width, plot_height=60, min_border=0, toolbar_location=None, outline_line_color="#FFFFFF", ) # Add the legend color boxes and text width = 40 height = 20 for i, color in enumerate(palette): rect = Rect(x=(width * (i + 1)), y=40, width=width * 1, height=height, fill_color=color, line_color='black') legend.add_glyph(rect) tick_min = Text(x=width / 2, y=0, text=['0']) legend.add_glyph(tick_min) text_scale = Text(x=width * 3, y=0, text=['Logarithmic scale']) legend.add_glyph(text_scale) tick_max = Text(x=width * (len(palette)), y=0, text='tick_max') legend.add_glyph(colormap_legend_cds, tick_max) return legend
def __init__(self, head_selection): self.head_selection = head_selection self.color_names = ['1 Blue', '2 Orange', '3 Green', '4 Red', '5 Purple', '6 Brown', '7 Pink', '8 Gray', '9 Olive', '10 Cyan'] self.active_heads = [] self.args = Settings() self.field_height = self.args.field_height self.field_width = self.args.field_width self.pixel_per_meters = 1#self.args.pixel_per_meters self.source_object = ColumnDataSource(data={'x': [], 'y': []}) self.object_glyph = Circle(x='x', y='y', radius=0.5, fill_alpha=0.8, fill_color='red') self.source_vehicle = ColumnDataSource(data={'x': [], 'y': [], 'angle': [], 'width': [], 'height': []}) self.source_vehicle.selected.on_change('indices', self._tap_on_veh) self.vehicle_glyph = Rect(x='x', y='y', angle='angle', width='width', height='height', fill_color='red', fill_alpha=0.8) self.image = None self.get_image() self.image_height = int(self.pixel_per_meters*self.field_height) self.image_width = int(self.pixel_per_meters*self.field_width) self.image_center = np.array([self.image_width//2, self.image_height//2]) self.source_ellipse = [] self.ellipse_glyph = Ellipse(x='x', y='y', width='width', height='height', angle='angle', fill_alpha='alpha', line_color=None, fill_color='blue') self.n_ellipses = 0 self.source_lane = [] self.lane_glyph = Line(x='x', y='y', line_color='gray', line_dash='dashed', line_width=3) self.n_lanes = 0 self.source_arrow = [[], []] self.arrow_glyph = Scatter(x='x', y='y', angle='angle', size='size', marker='triangle', line_color=None) self.arrow_glyph_list = [] self.source_path_fut = [] self.source_path_pred = [] self.source_path_past = [] self.fut_path_glyph = Line(x='x', y='y', line_color='green', line_width=2) self.pred_path_glyph = Line(x='x', y='y', line_color='red', line_width=2) self.past_path_glyph = Line(x='x', y='y', line_color='gray', line_width=2) self.n_past = 0 self.n_fut = 0 self.n_pred = 0 self.attention_matrix = None
def __init__(self, car_width=0.1, car_height=0.05, rod_length=0.5, pendulum_size=0.05): self.car_width = car_width self.car_height = car_height self.rod_length = rod_length self.pendulum_size = pendulum_size self.pendulum = GlyphRenderer(data_source=ColumnDataSource( dict(x=[0], y=[0])), glyph=Ellipse(x='x', y='y', width=self.pendulum_size, height=self.pendulum_size)) self.car = GlyphRenderer(data_source=ColumnDataSource( dict(x=[0], y=[0])), glyph=Rect(x='x', y='y', width=self.car_width, height=self.car_height)) self.rod = GlyphRenderer(data_source=ColumnDataSource( dict(x=[0, 0], y=[0, 0])), glyph=Line(x='x', y='y', line_width=2)) self.move = GlyphRenderer(data_source=ColumnDataSource( dict(x=deque([0, 1], maxlen=200), y=deque([0, 1], maxlen=200))), glyph=Ellipse(x='x', y='y', width=0.008, height=0.008, fill_alpha=0.25, line_alpha=0.0, fill_color="#cc0000")) self.ground = GlyphRenderer(data_source=ColumnDataSource( dict(x=[-100, 100], y=[-car_height / 2, -car_height / 2])), glyph=Line(x='x', y='y', line_width=1, line_alpha=0.5))
def test2(start=0, end=500, rows=3, plot_width=1000, callback=None): """Plot with random rects for scroll testing""" from bokeh.models import BoxZoomTool m = rows length = end x = np.arange(0, end, 2) y = list(range(1, m)) * len(x) y = y[:len(x)] colors = utils.random_colors(len(y)) w = [random.random() * 3 for i in x] txt = [str(i) for i in range(len(x))] source = ColumnDataSource({ 'x': x, 'y': y, 'w': w, 'text': txt, 'color': colors }) tools = "xpan,xwheel_zoom,box_select" p = figure(title=None, plot_width=plot_width, plot_height=200, x_range=(0, 100), y_range=(0, m), tools=tools, min_border=0, toolbar_location='right') rects = Rect(x="x", y="y", width="w", height=.6, fill_color='color', fill_alpha=0.8, line_width=2, name='rects') #t = Text(x="x", y="y", text='text', text_font_size='9pt') p.add_glyph(source, rects) tool = p.select(dict(type=BoxZoomTool)) tool.dimensions = ["width"] p.toolbar.logo = None return p
def large_plot(): source = ColumnDataSource(data=dict(x=[0, 1], y=[0, 1])) xdr = Range1d(start=0, end=1) xdr.tags.append("foo") xdr.tags.append("bar") ydr = Range1d(start=10, end=20) ydr.tags.append("foo") ydr.tags.append(11) plot = Plot(x_range=xdr, y_range=ydr) ydr2 = Range1d(start=0, end=100) plot.extra_y_ranges = {"liny": ydr2} circle = Circle(x="x", y="y", fill_color="red", size=5, line_color="black") plot.add_glyph(source, circle, name="mycircle") line = Line(x="x", y="y") plot.add_glyph(source, line, name="myline") rect = Rect(x="x", y="y", width=1, height=1, fill_color="green") plot.add_glyph(source, rect, name="myrect") plot.add_layout(DatetimeAxis(), 'below') plot.add_layout(LogAxis(), 'left') plot.add_layout(LinearAxis(y_range_name="liny"), 'left') plot.add_layout(Grid(dimension=0), 'left') plot.add_layout(Grid(dimension=1), 'left') plot.add_tools( BoxZoomTool(), PanTool(), SaveTool(), ResetTool(), ResizeTool(), WheelZoomTool(), ) return plot
def setupColorBar(self): colorTimeline = figure(height=30, y_range=(-.5, .5), width=self.figureWidth, x_range=(0, 100), toolbar_location=None, output_backend="webgl", name="colorBarPlot", tools="") colorTimeline.axis.visible = False colorTimeline.grid.visible = False self.mapper = LinearColorMapper(palette="Inferno256", low=0, high=100) # colorTimeline.image(image=range(self.numSamples),x=0,y=.5,dh=1,dw=1,fill_color={'field':"x",'transform': self.mappers[colorBarType-1]}, # name="cbar" + str(colorBarType)) self.colorSource = ColumnDataSource({ "x": range(100), "place": range(100) }) # colorTimeline.rect(x="x", y=0, width=1, height=1,fill_color={'field':"place",'transform': self.mapper},name="colorBar", # line_width=0.0,line_color= None,line_alpha = 0.0,source=colorSource # ) colorBar = Rect(x="x", y=0, width=1, height=1, fill_color={ 'field': "place", 'transform': self.mapper }, name="colorBar", line_width=0.0, line_color=None, line_alpha=0.0) colorTimeline.add_glyph(self.colorSource, colorBar) self.colorBar = colorTimeline
def plot_coverage(df, plot_width=800, plot_height=60, xaxis=True): """Plot a bam coverage dataframe returned from get_coverage Args: df: dataframe of coverage data (from get_coverage) plot_width: width of plot xaxis: plot the x-axis ticks and labels """ if df is None or len(df) == 0: return plot_empty(plot_width=plot_width, plot_height=plot_height) df['y'] = df.coverage / 2 source = ColumnDataSource(df) x_range = (df.pos.min(), df.pos.max()) top = df.coverage.max() print(top) hover = HoverTool(tooltips=[("pos", "@pos"), ("coverage", "@coverage")], point_policy='follow_mouse') p = figure(title=None, plot_width=plot_width, plot_height=plot_height, x_range=x_range, y_range=(0, top), tools=[hover], min_border=0, toolbar_location='right') rects = Rect(x="pos", y="y", width=1, height="coverage", fill_color="gray", fill_alpha=0.3) p.add_glyph(source, rects) p.grid.visible = False p.yaxis.visible = False if xaxis == False: p.xaxis.visible = False p.toolbar.logo = None return p
def test_Rect() -> None: glyph = Rect() assert glyph.x == field("x") assert glyph.y == field("y") assert glyph.width is None assert glyph.height is None assert glyph.angle == 0 assert glyph.dilate is False check_fill_properties(glyph) check_line_properties(glyph) check_properties_existence(glyph, [ "x", "y", "width", "width_units", "height", "height_units", "angle", "angle_units", "dilate", ], FILL, LINE, GLYPH)
def test_Rect(): glyph = Rect() assert glyph.x is None assert glyph.y is None assert glyph.width is None assert glyph.height is None assert glyph.angle == 0 assert glyph.dilate == False yield check_fill_properties, glyph yield check_line_properties, glyph yield (check_properties_existence, glyph, [ "x", "y", "width", "width_units", "height", "height_units", "angle", "angle_units", "dilate", ], FILL, LINE, GLYPH)
def __init__(self, total: int, title: str, color: str, bokeh_session: object): """ Initialize a ProgressBar instance. :param total: number of steps the progress bar is divided into. In other words, the number of times update should be called. :param title: the title of the progress bar :param color: the color of the progress bar :param bokeh_session: bokeh server session """ self.color = color self.title = title self.total = total self.current_source_index = 0 self.source = self.create_column_data_source() plot = Plot(plot_width=1000, plot_height=50, min_border=0, toolbar_location=None, outline_line_color=None) glyph = Rect(x="x_coordinate", y=0, width=1, height=1, angle=-0.0, fill_color="color", line_color="color", line_alpha=0.3, fill_alpha=0.3) plot.add_glyph(self.source, glyph) self.title_object = Title() self.title_object.text = " " + self.title plot.title = self.title_object bokeh_session.document.add_root(plot)
def BarGraph(x, y, names=None, plot_width=1000, plot_height=230): n = ['' for i in x] if names == None else names source = ColumnDataSource(dict(x=x, y=y, m=y / 2, n=[' ' + _ for _ in n])) plot = figure( title=None, plot_width=plot_width, plot_height=plot_height, x_axis_type=None, y_range=Range1d(0, 1.09 * max(source.data['y'])), tools="xpan,reset", min_border=0, toolbar_location='below', background_fill_color='black', background_fill_alpha=0.12, ) rect = Rect(x="x", y="m", height="y", width=0.9, fill_color="red", fill_alpha=0.2, line_color=None) plot.add_glyph(source, rect) text = Text(x="x", y=0, angle=90, angle_units='deg', text="n", text_align='left', text_color="black", text_font="monospace", text_font_size="12pt") plot.add_glyph(source, text) plot.grid.visible = False plot.yaxis.visible = False return plot
def __init__(self, body_width=0.5, body_height=0.25, num_bodies=2, body_distance=1.0): self.body_width = body_width self.body_height = body_height self.num_bodies = num_bodies self.rod_colors = viridis(51) self.body_distance = body_distance self.bodies = [] self.rods = [] for _ in range(num_bodies): self.bodies.append( GlyphRenderer(data_source=ColumnDataSource(dict(x=[0], y=[0])), glyph=Rect(x='x', y='y', width=self.body_height, height=self.body_width))) for _ in range(num_bodies - 1): self.rods.append( GlyphRenderer(data_source=ColumnDataSource( dict(x=[0, 0], y=[0, 0])), glyph=Line(x='x', y='y', line_width=2, line_color=self.rod_colors[0]))) self.ground = GlyphRenderer(data_source=ColumnDataSource( dict(x=[-100, 100], y=[-self.body_height / 2, -self.body_height / 2])), glyph=Line(x='x', y='y', line_width=1, line_alpha=0.5))
source = ColumnDataSource( dict( names=list(css3_colors.Name), groups=list(css3_colors.Group), colors=list(css3_colors.Color), )) xdr = FactorRange(factors=list(css3_colors.Group.unique())) ydr = FactorRange(factors=list(reversed(css3_colors.Name))) plot = Plot(x_range=xdr, y_range=ydr, plot_width=600, plot_height=2000) plot.title.text = "CSS3 Color Names" rect = Rect(x="groups", y="names", width=1, height=1, fill_color="colors", line_color=None) rect_renderer = plot.add_glyph(source, rect) xaxis_above = CategoricalAxis(major_label_orientation=pi / 4) plot.add_layout(xaxis_above, 'above') xaxis_below = CategoricalAxis(major_label_orientation=pi / 4) plot.add_layout(xaxis_below, 'below') plot.add_layout(CategoricalAxis(), 'left') url = "http://www.colors.commutercreative.com/@names/" tooltips = """Click the color to go to:<br /><a href="{url}">{url}</a>""".format( url=url)
w = x / 15.0 + 0.3 h = y / 20.0 + 0.3 source = ColumnDataSource(dict(x=x, y=y, w=w, h=h)) plot = Plot(title=None, plot_width=300, plot_height=300, h_symmetry=False, v_symmetry=False, min_border=0, toolbar_location=None) glyph = Rect(x="x", y="y", width="w", height="h", angle=-0.7, fill_color="#cab2d6") 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)) curdoc().add_root(plot)
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", line_width=2)), ("rect", Rect(x="x", y="y", width=screen(10), height=screen(20), angle=-0.7, fill_color="#CAB2D6")), ("segment", Segment(x0="x", y0="y", x1="xm01", y1="ym01", line_color="#F4A582", line_width=3)), ("text", Text(x="x", y="y", text=["hello"])), ("wedge", Wedge(x="x", y="y", radius=screen(15), start_angle=0.6,
###### MAIN PLOT (beam, supports, load) ###### # define plot: plot_main = Figure(title="Rod with Supports and Load", tools="", x_range=x_range, y_range=(-2.0,2.5), height=fig_height) # set properties plot_main.axis.visible = False plot_main.outline_line_width = 2 plot_main.outline_line_color = "Black" plot_main.title.text_font_size = "13pt" plot_main.toolbar.logo = None # plot error message if both supports are set to sliding error_label = LabelSet(x='x', y='y', text='name', source=error_msg) plot_main.add_layout(error_label) plot_main.add_glyph(error_msg_frame,Rect(x="x", y="y", width=8, height=1, angle=0, fill_color='red', fill_alpha=0.2)) # plot helper line plot_main.add_glyph(aux_line, aux_line_glyph) # measures beam_measure_doublearrow_glyph = Arrow(start=OpenHead(line_color=c_black, line_width=2, size=8), end=OpenHead(line_color='black',line_width= 2, size=8), x_start=xr_start, y_start=-1.2, x_end=xr_end, y_end=-1.2, line_width=5, line_color=c_black) beam_measure_singlearrow_glyph = Arrow(end=NormalHead(fill_color=c_gray, line_width=1, size=6), x_start=xr_start-0.1, y_start=-0.8, x_end=xr_start+0.8, y_end=-0.8, line_width=1, line_color=c_black) beam_measure_label_source.data = dict(x=[xr_start+0.25, 0.5*(xr_end-xr_start)], y=[-0.7,-1.6], text=["x","L"]) beam_measure_label = LatexLabelSet(x='x', y='y', text='text', source=beam_measure_label_source, level='glyph')#, x_offset=3, y_offset=-15) plot_main.line(x=[xr_start, xr_start], y=[-0.7,-0.9], line_color=c_black) # vertical line for single x-arrow plot_main.add_layout(beam_measure_singlearrow_glyph) plot_main.add_layout(beam_measure_doublearrow_glyph)
values=[], rel_change=[])) ####### Plot Data: # estBloodSource = ColumnDataSource(data=dict(est_blood_x=[], # est_blood_y=[], # values = [])) # estPlot_blood.circle('est_blood_x', 'est_blood_y', source=estBloodSource, size=10, line_width=3, line_alpha=0.6, color = 'black') # Baseline # estGlyphs = Rect(x="estGlyph_x", y="estGlyph_y", width="estGlyph_w", height="estGlyph_h", fill_color="grey", fill_alpha = .2) # estPlot_blood.add_glyph(estGlyphSource, estGlyphs) # estPlot_bloodPressure.circle('est_bloodPressure_x', 'est_bloodPressure_y', source=estBloodPressureSource, size = 10, line_width=3, line_alpha=0.6, color = 'black') predictGlyphs = Rect(x="predictGlyph_x", y="predictGlyph_y", width="predictGlyph_w", height="predictGlyph_h", fill_color="grey", fill_alpha=.2) predictPlot_blood.add_glyph(predictGlyphSource, predictGlyphs) predictPlot_blood.circle('predict_blood_x', 'predict_blood_y1', source=predictBloodSource, size=10, line_width=3, line_alpha=0.6, color='red') # Intervention predictPlot_blood.circle('predict_blood_x', 'predict_blood_y0', source=predictBloodSource0, size=10, line_width=3,
toolbar_location=None, outline_line_alpha=0, ) grid.xaxis.visible = False grid.yaxis.visible = False grid.xgrid.grid_line_color = None grid.ygrid.grid_line_color = None # Add blank dice x_dice = np.arange(0, 5) + 0.5 x_dice, y_dice = np.meshgrid(x_dice, x_dice) alpha_dice = np.ones(x_dice.shape) dice_src = ColumnDataSource(dict(x=x_dice, y=y_dice, fill_alpha=alpha_dice)) dice = Rect(x="x", y="y", width=0.95, height=0.95, fill_color="#cab2d6", fill_alpha="fill_alpha") grid.add_glyph(dice_src, dice) # Add letters # TODO: random orientation U/D/L/R x_letters = x_dice.reshape(25, 1) y_letters = (y_dice - 0.3).reshape(25, 1) letter_angles = np.zeros(len(x_letters)) xoffset = np.zeros(len(x_letters)) yoffset = np.zeros(len(x_letters)) text = np.full(len(x_letters), "X") letter_src = ColumnDataSource( dict( x=x_letters,
6.1, 4.65, 215., 5.02, 5.5, 77.1, 47.4, 5.08, 1.22, 4.68, 18., 284., 1.36 ]) / medianBlood w = np.array(np.ones(26) * .75) h = np.array([ 1.6000e+00, 1.0415e+02, 3.7000e-01, 2.2328e+02, 8.7400e+00, 2.2810e+01, 5.0000e-01, 9.9000e-01, 2.7000e-01, 1.0000e-01, 1.7972e+02, 2.3310e+01, 2.0300e+01, 1.9600e+00, 6.8000e-01, 7.0160e+01, 1.4100e+00, 8.9000e-01, 5.1600e+00, 3.4700e+00, 1.4300e+00, 1.4500e+00, 1.0200e+00, 1.9190e+01, 5.5650e+01, 7.1000e-01 ]) / (medianBlood * 4) glyphSource_chol = ColumnDataSource( data=dict(x4=x_glyph, y4=y_glyph, w=w, h=h)) glyph = Rect(x="x4", y="y4", width="w", height="h", fill_color="grey", fill_alpha=.2) plot1.add_glyph(glyphSource_chol, glyph) plot1.xaxis.ticker = FixedTicker( ticks=list(range(0, len(responseVariables[0:-2])))) plot1.xaxis.axis_label = 'Biomarker' plot1.xaxis.axis_label_text_font_size = '16pt' plot1.xaxis.major_label_overrides = dict( zip(range(0, len(responseVariables[0:-2])), responseVariables[0:-2])) plot1.xaxis.major_label_text_font_size = '12pt' plot1.xaxis.major_label_orientation = 3.14 / 4 tab1 = Panel(child=plot1, title="Blood test") plot2 = figure(plot_height=500,
def bokeh(self, glyphType="line", glyphSize=1, fillColor="red", lineColor="black", lineAlpha=1, fillAlpha=0.1, lineDash='solid'): #glyphs from bokeh.models.glyphs import Rect, Segment, Line, Patches, Arc from bokeh.models.renderers import GlyphRenderer from bokeh.models.markers import (Marker, Asterisk, Circle, CircleCross, CircleX, Cross, Diamond, DiamondCross, InvertedTriangle, Square, SquareCross, SquareX, Triangle, X) #data from bokeh.models import ColumnDataSource #Parameters of the histogram l = self.low h = self.high num = self.num bin_width = (h - l) / num x = list() center = l for _ in range(num): x.append(center + bin_width / 2) center += bin_width y = self.numericalValues ci = [2. * v for v in self.confidenceIntervalValues()] source = ColumnDataSource(data=dict(x=x, y=y, ci=ci)) glyph = None if glyphType == "square": glyph = Square(x='x', y='y', line_color=lineColor, fill_color=fillColor, line_alpha=lineAlpha, size=glyphSize, line_dash=lineDash) elif glyphType == "diamond": glyph = Diamond(x='x', y='y', line_color=lineColor, fill_color=fillColor, line_alpha=lineAlpha, size=glyphSize, line_dash=lineDash) elif glyphType == "cross": glyph = Cross(x='x', y='y', line_color=lineColor, fill_color=fillColor, line_alpha=lineAlpha, size=glyphSize, line_dash=lineDash) elif glyphType == "triangle": glyph = Triangle(x='x', y='y', line_color=lineColor, fill_color=fillColor, line_alpha=lineAlpha, size=glyphSize, line_dash=lineDash) elif glyphType == "circle": glyph = Circle(x='x', y='y', line_color=lineColor, fill_color=fillColor, line_alpha=lineAlpha, size=glyphSize, line_dash=lineDash) elif glyphType == "rect": glyph = Rect(x='x', y='y', width=bin_width, height=0.1, fill_alpha=fillAlpha, line_color=lineColor, fill_color=fillColor) elif glyphType == "errors": glyph = Rect(x='x', y='y', width=bin_width, height='ci', fill_alpha=fillAlpha, line_color=lineColor, fill_color=fillColor) elif glyphType == "histogram": h = y y = [yy / 2 for yy in y] source = ColumnDataSource(dict(x=x, y=y, h=h)) glyph = Rect(x='x', y='y', width=bin_width, height='h', fill_alpha=fillAlpha, line_color=lineColor, fill_color=fillColor) else: glyph = Line(x='x', y='y', line_color=lineColor, line_alpha=lineAlpha, line_width=glyphSize, line_dash=lineDash) return GlyphRenderer(glyph=glyph, data_source=source)
def bokeh(self, glyphType="line", glyphSize=1, fillColor="red", lineColor="black", lineAlpha=1, fillAlpha=0.1, lineDash='solid'): #glyphs from bokeh.models.glyphs import Rect, Segment, Line, Patches, Arc from bokeh.models.renderers import GlyphRenderer from bokeh.models.markers import (Marker, Asterisk, Circle, CircleCross, CircleX, Cross, Diamond, DiamondCross, InvertedTriangle, Square, SquareCross, SquareX, Triangle, X) #data from bokeh.models import ColumnDataSource from math import sqrt #Parameters of the histogram l = self.low h = self.high num = self.num bin_width = (h - l) / num x = list() y = list() center = l for v in self.values: if not math.isnan(v.mean): y.append(v.mean) x.append(center + bin_width / 2) center += bin_width source = ColumnDataSource(data=dict(x=x, y=y)) glyph = None if glyphType == "square": glyph = Square(x='x', y='y', line_color=lineColor, fill_color=fillColor, line_alpha=lineAlpha, size=glyphSize, line_dash=lineDash) elif glyphType == "diamond": glyph = Diamond(x='x', y='y', line_color=lineColor, fill_color=fillColor, line_alpha=lineAlpha, size=glyphSize, line_dash=lineDash) elif glyphType == "cross": glyph = Cross(x='x', y='y', line_color=lineColor, fill_color=fillColor, line_alpha=lineAlpha, size=glyphSize, line_dash=lineDash) elif glyphType == "triangle": glyph = Triangle(x='x', y='y', line_color=lineColor, fill_color=fillColor, line_alpha=lineAlpha, size=glyphSize, line_dash=lineDash) elif glyphType == "circle": glyph = Circle(x='x', y='y', line_color=lineColor, fill_color=fillColor, line_alpha=lineAlpha, size=glyphSize, line_dash=lineDash) elif glyphType == "errors": w = [bin_width for _ in x] h = [ sqrt(v.variance / v.entries) if v.entries > 0 else 0.0 for v in self.values ] source = ColumnDataSource(dict(x=x, y=y, w=w, h=h)) glyph = Rect(x='x', y='y', width='w', height='h', fill_alpha=fillAlpha, line_color=lineColor, fill_color=fillColor) elif glyphType == "histogram": w = [bin_width for _ in x] h = y y = [yy / 2 for yy in y] source = ColumnDataSource(dict(x=x, y=y, w=w, h=h)) glyph = Rect(x='x', y='y', width='w', height='h', fill_alpha=fillAlpha, line_color=lineColor, fill_color=fillColor) else: glyph = Line(x='x', y='y', line_color=lineColor, line_alpha=lineAlpha, line_width=glyphSize, line_dash=lineDash) return GlyphRenderer(glyph=glyph, data_source=source)