def update_source(self): sort_relevant, sort_crawled, sort_frontier = self.generate_data() # Sorted by Relevance # Generate the column that calculates the center of the rectangle for the rect glyph. sort_relevant['relevant_rect'] = sort_relevant['relevant_count'].map(lambda x: x/2) sort_relevant['frontier_rect'] = sort_relevant['frontier_count'].map(lambda x: x/2) sort_relevant['crawled_rect'] = sort_relevant['crawled_count'].map(lambda x: x/2) sort_relevant_source = ColumnDataSource(sort_relevant) # Sorted by Frontier # Generate the column that calculates the center of the rectangle for the rect glyph. sort_frontier['relevant_rect'] = sort_frontier['relevant_count'].map(lambda x: x/2) sort_frontier['frontier_rect'] = sort_frontier['frontier_count'].map(lambda x: x/2) sort_frontier['crawled_rect'] = sort_frontier['crawled_count'].map(lambda x: x/2) sort_frontier_source = ColumnDataSource(sort_frontier) # Sorted by Crawled # Generate the column that calculates the center of the rectangle for the rect glyph. sort_crawled['relevant_rect'] = sort_crawled['relevant_count'].map(lambda x: x/2) sort_crawled['frontier_rect'] = sort_crawled['frontier_count'].map(lambda x: x/2) sort_crawled['crawled_rect'] = sort_crawled['crawled_count'].map(lambda x: x/2) sort_crawled_source = ColumnDataSource(sort_crawled) return sort_relevant_source, sort_crawled_source, sort_frontier_source
def create(self, doc): self.modelform = InstallersModel() self.modelform.create_inputs(doc) self.downloads_source = ColumnDataSource(dict( dates=[], downloads=[], )) self.punchcard_source = ColumnDataSource( dict( counts=[], percentages=[], hours=sum([[str(hour)] * 7 for hour in xrange(0, 24)], []), days=[ "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" ] * 24, )) self.update_data() self.downloads_plot = self.make_downloads_plot(self.downloads_source) self.punchcard_plot = self.make_punchcard_plot(self.punchcard_source) self.children.append(self.modelform) self.children.append( VBox(children=[self.downloads_plot, self.punchcard_plot]))
def __init__(self, **kw): super(RadialGraph, self).__init__(**kw) self._node_source = ColumnDataSource(dict(id=[], time=[], relevance=[])) self._edge_source = ColumnDataSource(dict(parent=[], child=[])) self._session = Session() self._doc = Document()
def add_gauge(radius, max_value, length, direction, color, major_step, minor_step): major_angles, minor_angles = [], [] major_labels, minor_labels = [], [] total_angle = start_angle - end_angle major_angle_step = float(major_step)/max_value*total_angle minor_angle_step = float(minor_step)/max_value*total_angle major_angle = 0 while major_angle <= total_angle: major_angles.append(start_angle - major_angle) major_angle += major_angle_step minor_angle = 0 while minor_angle <= total_angle: minor_angles.append(start_angle - minor_angle) minor_angle += minor_angle_step major_labels = [ major_step*i for i, _ in enumerate(major_angles) ] minor_labels = [ minor_step*i for i, _ in enumerate(minor_angles) ] n = major_step/minor_step minor_angles = [ x for i, x in enumerate(minor_angles) if i % n != 0 ] minor_labels = [ x for i, x in enumerate(minor_labels) if i % n != 0 ] glyph = Arc(x=0, y=0, radius=radius, start_angle=start_angle, end_angle=end_angle, direction="clock", line_color=color, line_width=2) add_glyph(glyph, global_source) rotation = 0 if direction == 1 else -pi x, y = zip(*[ polar_to_cartesian(radius, angle) for angle in major_angles ]) angles = [ angle + rotation for angle in major_angles ] source = ColumnDataSource(dict(x=x, y=y, angle=angles)) plot.data_sources.append(source) glyph = Ray(x="x", y="y", length=length, angle="angle", line_color=color, line_width=2) add_glyph(glyph, source) x, y = zip(*[ polar_to_cartesian(radius, angle) for angle in minor_angles ]) angles = [ angle + rotation for angle in minor_angles ] source = ColumnDataSource(dict(x=x, y=y, angle=angles)) plot.data_sources.append(source) glyph = Ray(x="x", y="y", length=length/2, angle="angle", line_color=color, line_width=1) add_glyph(glyph, source) x, y = zip(*[ polar_to_cartesian(radius+2*length*direction, angle) for angle in major_angles ]) text_angles = [ angle - pi/2 for angle in major_angles ] source = ColumnDataSource(dict(x=x, y=y, angle=text_angles, text=major_labels)) plot.data_sources.append(source) glyph = Text(x="x", y="y", angle="angle", text="text", text_align="center", text_baseline="middle") add_glyph(glyph, source)
def make_plot(): source = ColumnDataSource( dict( dates=[date(2014, 3, i) for i in [1, 2, 3, 4, 5]], downloads=[100, 27, 54, 64, 75], )) xdr = DataRange1d(sources=[source.columns("dates")]) ydr = DataRange1d(sources=[source.columns("downloads")]) plot = Plot(title="Product downloads", x_range=xdr, y_range=ydr, plot_width=400, plot_height=400) line = Line(x="dates", y="downloads", line_color="blue") plot.add_glyph(source, line) circle = Circle(x="dates", y="downloads", fill_color="red") plot.add_glyph(source, circle) xaxis = DatetimeAxis() 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)) plot.add_tools(HoverTool(tooltips=dict(downloads="@downloads"))) return plot, source
def to_data_source(self, df): index = self.reorder_dendogram(df) # col = lambda v: self.color(v) print self._color(0.2) _names = df.columns.tolist() names = [_names[i] for i in index] xnames = [] ynames = [] values = [] colors = [] for n in names: xnames.extend([n] * len(names)) ynames.extend(names) v = df.loc[n, names].tolist() values.extend(values) colors.extend([ self._color(x) for x in v]) # alphas = np.abs(df.values).flatten() self.column_source = ColumnDataSource( data=dict( xname = xnames, yname = ynames, colors= colors, values= values, ) ) return self, names
def classical_gear(module, large_teeth, small_teeth): xdr = Range1d(start=-300, end=150) ydr = Range1d(start=-100, end=100) source = ColumnDataSource(data=dict(dummy=[0])) plot = Plot( title=None, x_range=xdr, y_range=ydr, plot_width=800, plot_height=800 ) plot.add_tools(PanTool(), WheelZoomTool(), ResetTool()) radius = pitch_radius(module, large_teeth) angle = 0 glyph = Gear( x=-radius, y=0, module=module, teeth=large_teeth, angle=angle, fill_color=fill_color[0], line_color=line_color ) plot.add_glyph(source, glyph) radius = pitch_radius(module, small_teeth) angle = half_tooth(small_teeth) glyph = Gear( x=radius, y=0, module=module, teeth=small_teeth, angle=angle, fill_color=fill_color[1], line_color=line_color ) plot.add_glyph(source, glyph) return plot
def sample_gear(): xdr = Range1d(start=-30, end=30) ydr = Range1d(start=-30, end=30) source = ColumnDataSource(data=dict(dummy=[0])) plot = Plot(title=None, data_sources=[source], x_range=xdr, y_range=ydr, width=800, height=800) plot.tools.extend( [PanTool(plot=plot), WheelZoomTool(plot=plot), ResetTool(plot=plot)]) glyph = Gear(x=0, y=0, module=5, teeth=8, angle=0, shaft_size=0.2, fill_color=fill_color[2], line_color=line_color) renderer = Glyph(data_source=source, xdata_range=xdr, ydata_range=ydr, glyph=glyph) plot.renderers.append(renderer) return plot
def make_plot(): source = ColumnDataSource( dict( dates=[date(2014, 3, i) for i in [1, 2, 3, 4, 5]], downloads=[100, 27, 54, 64, 75], )) xdr = DataRange1d(sources=[source.columns("dates")]) ydr = DataRange1d(sources=[source.columns("downloads")]) plot = Plot(title="Product downloads", data_sources=[source], x_range=xdr, y_range=ydr, width=400, height=400) line = Line(x="dates", y="downloads", line_color="blue") line_glyph = Glyph(data_source=source, xdata_range=xdr, ydata_range=ydr, glyph=line) plot.renderers.append(line_glyph) circle = Circle(x="dates", y="downloads", fill_color="red") circle_glyph = Glyph(data_source=source, xdata_range=xdr, ydata_range=ydr, glyph=circle) plot.renderers.append(circle_glyph) hover = HoverTool(plot=plot, tooltips=dict(downloads="@downloads")) plot.tools.append(hover) xaxis = DatetimeAxis(plot=plot, dimension=0) yaxis = LinearAxis(plot=plot, dimension=1) xgrid = Grid(plot=plot, dimension=0, axis=xaxis) ygrid = Grid(plot=plot, dimension=1, axis=yaxis) return plot, source
def trail_map(data): lon = (min(data.lon) + max(data.lon))/2 lat = (min(data.lat) + max(data.lat))/2 map_options = GMapOptions(lng=lon, lat=lat, zoom=13) plot = GMapPlot(title="%s - Trail Map" % title, map_options=map_options, plot_width=800, plot_height=800) xaxis = LinearAxis() plot.add_layout(xaxis, 'below') yaxis = LinearAxis() plot.add_layout(yaxis, 'left') xgrid = Grid(plot=plot, dimension=0, ticker=xaxis.ticker, grid_line_dash="dashed", grid_line_color="gray") ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker, grid_line_dash="dashed", grid_line_color="gray") plot.renderers.extend([xgrid, ygrid]) hover = HoverTool(tooltips=dict(distance="@dist")) plot.add_tools(hover, PanTool(), WheelZoomTool(), ResetTool(), BoxSelectTool()) line_source = ColumnDataSource(dict(x=data.lon, y=data.lat, dist=data.dist)) line = Line(x="x", y="y", line_color="blue", line_width=2) plot.add_glyph(line_source, line) plot.x_range = DataRange1d(sources=[line_source.columns("x")]) plot.y_range = DataRange1d(sources=[line_source.columns("y")]) return plot
def plot_circle_density(nodes, degrees, plot_width=800, plot_height=800): print("Plotting circle density graph") TOOLS="hover,pan,wheel_zoom,box_zoom,reset,click,previewsave" plt.figure(plot_width=plot_width, plot_height=plot_height, tools=TOOLS) theta = np.random.uniform(0, 2*np.pi, size=len(nodes)) max_d, min_d = np.max(degrees), np.min(degrees) scale = 1.0/np.log(degrees) - 1.0/np.log(max_d) xs = np.cos(theta)*scale ys = np.sin(theta)*scale source_dict = dict( xs = xs, ys = ys, degrees = degrees, nodes = nodes, alphas = np.log(degrees)/np.log(max(degrees)), ) source = ColumnDataSource(source_dict) plt.hold(True) plt.circle('xs', 'ys', source=source, radius=0.0025, fill_alpha='alphas', x_axis_type=None, y_axis_type=None, title="Density Distribution of Degrees") plt.text([max(xs), max(xs)], [.95*max(ys), .85*max(ys)], ["distance from center = 1 / log(deg)", "angle = random"], angle=0, text_baseline="bottom", text_align="right") hover = [t for t in plt.curplot().tools if isinstance(t, HoverTool)][0] hover.tooltips = OrderedDict([ ('node', '@nodes'), ('degree', '@degrees') ]) plt.hold(False) return plt.curplot()
def line_advanced(): source = ColumnDataSource(data=dict(x=x,y=y,z=z,widths=widths, heights=heights)) xdr = DataRange1d(sources=[source.columns("x")]) xdr2 = DataRange1d(sources=[source.columns("x")]) ydr = DataRange1d(sources=[source.columns("y")]) ydr2 = DataRange1d(sources=[source.columns("y")]) line_glyph = Line(x="x", y="y", line_color="blue") renderer = GlyphRenderer(data_source = source, xdata_range = xdr, ydata_range = ydr, glyph = line_glyph) pantool = PanTool(dataranges = [xdr, ydr], dimensions=["width","height"]) zoomtool = ZoomTool(dataranges=[xdr,ydr], dimensions=("width","height")) plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source], border=50) plot.tools = [pantool, zoomtool] plot.renderers.append(renderer) #notice that these two have a differen y data range renderer2 = GlyphRenderer(data_source = source, xdata_range = xdr, ydata_range = ydr2, glyph = line_glyph) plot2 = Plot(x_range=xdr, y_range=ydr2, data_sources=[source], border=50) plot2.renderers.append(renderer2) #notice that these two have a differen y data range renderer3 = GlyphRenderer(data_source = source, xdata_range = xdr2, ydata_range = ydr, glyph = line_glyph) plot3 = Plot(x_range=xdr2, y_range=ydr, data_sources=[source], border=50) plot3.renderers.append(renderer3) #this is a dummy plot with no renderers plot4 = Plot(x_range=xdr2, y_range=ydr, data_sources=[source], border=50) sess = session.HTMLFileSession("line_linked_advanced.html") sess.add(plot, renderer, source, xdr, ydr, pantool, zoomtool) sess.add(plot2, renderer2, ydr2, xdr2, renderer3, plot3, plot4) grid = GridPlot(children=[[plot, plot2], [plot3, plot4 ]], name="linked_advanced") sess.add(grid) sess.plotcontext.children.append(grid) sess.save(js="relative", css="relative", rootdir=os.path.abspath(".")) print "Wrote line_linked_advanced.html" webbrowser.open("file://" + os.path.abspath("line_linked_advanced.html"))
def test_Column_data_source(): pytest.importorskip('bokeh') from bokeh.objects import ColumnDataSource cds = into(ColumnDataSource(), data_table) assert isinstance(cds, ColumnDataSource) assert set(cds.column_names) == set(data_table.fields)
def make_continuous_bar_source(df, x_field, y_field, agg): labels, edges = pd.cut(df[x_field], 50, retbins=True, labels=False) centers = pd.rolling_mean(edges, 2)[1:] labels = centers[labels] df[x_field] = labels group = df.groupby(x_field)[y_field] aggregate = getattr(group, agg) result = aggregate().reset_index() return ColumnDataSource(data=result)
def sample_gear(): xdr = Range1d(start=-30, end=30) ydr = Range1d(start=-30, end=30) source = ColumnDataSource(data=dict(dummy=[0])) plot = Plot(title=None, x_range=xdr, y_range=ydr, plot_width=800, plot_height=800) plot.add_tools(PanTool(), WheelZoomTool(), ResetTool()) glyph = Gear(x=0, y=0, module=5, teeth=8, angle=0, shaft_size=0.2, fill_color=fill_color[2], line_color=line_color) plot.add_glyph(source, glyph) return plot
def create(cls): """ This function is called once, and is responsible for creating all objects (plots, datasources, etc) """ obj = cls() obj.source = ColumnDataSource(data=dict(x=[], y=[])) obj.text = TextInput(title="title", name='title', value='my sin wave') obj.offset = Slider(title="offset", name='offset', value=0.0, start=-5.0, end=5.0) obj.amplitude = Slider(title="amplitude", name='amplitude', value=1.0, start=-5.0, end=5.0) obj.phase = Slider(title="phase", name='phase', value=0.0, start=0.0, end=2 * np.pi) obj.freq = Slider(title="frequency", name='frequency', value=1.0, start=0.1, end=5.1) obj.plot = line('x', 'y', source=obj.source, plot_width=400, plot_height=400, line_width=3, line_alpha=0.6, title=obj.text.value, x_range=[0, 4 * np.pi], y_range=[-2.5, 2.5]) obj.update_data() obj.inputs = VBoxForm(children=[ obj.text, obj.offset, obj.amplitude, obj.phase, obj.freq ]) obj.children.append(obj.inputs) obj.children.append(obj.plot) return obj
def altitude_profile(data): plot = Plot(title="%s - Altitude Profile" % title, plot_width=800, plot_height=400) xaxis = LinearAxis(axis_label="Distance (km)") plot.add_layout(xaxis, 'below') yaxis = LinearAxis(axis_label="Altitude (m)") plot.add_layout(yaxis, 'left') xgrid = Grid(plot=plot, dimension=0, ticker=xaxis.ticker) ygrid = Grid(plot=plot, dimension=1, ticker=yaxis.ticker) plot.renderers.extend([xgrid, ygrid]) plot.add_tools(PanTool(), WheelZoomTool(), ResetTool(), BoxSelectTool()) X, Y = data.dist, data.alt y0 = min(Y) patches_source = ColumnDataSource( dict(xs=[[X[i], X[i + 1], X[i + 1], X[i]] for i in range(len(X[:-1]))], ys=[[y0, y0, Y[i + 1], Y[i]] for i in range(len(Y[:-1]))], color=data.colors[:-1])) patches = Patches(xs="xs", ys="ys", fill_color="color", line_color="color") plot.add_glyph(patches_source, patches) line_source = ColumnDataSource(dict( x=data.dist, y=data.alt, )) line = Line(x='x', y='y', line_color="black", line_width=1) plot.add_glyph(line_source, line) plot.x_range = DataRange1d(sources=[line_source.columns("x")]) plot.y_range = DataRange1d(sources=[line_source.columns("y")]) return plot
def make_plot(): sess = session() data = pd.DataFrame({'a': np.random.randn(100), 'b': np.random.randn(100)}) source = ColumnDataSource(data=data) scatter_plot = circle(source=source, x='a', y='b', plot_width=500, plot_height=500) app = App(data_source=source, scatter_plot=scatter_plot, stats=str(data.describe())) return app
def __init__(self): from bokeh.objects import ColumnDataSource from bokeh.document import Document from bokeh.session import Session from bokeh.sampledata.population import load_population self.document = Document() self.session = Session() self.session.use_doc('population') self.session.load_document(self.document) self.df = load_population() self.source_pyramid = ColumnDataSource(data=dict())
def make_box_violin_plot(data, maxwidth=0.9): """ data: dict[Str -> List[Number]] maxwidth: float Maximum width of tornado plot within each factor/facet Returns the plot object """ print("Plotting box violin graph") plot_width = 500 plot_height = 350 df = pd.DataFrame(columns=["group", "width", "height", "texts", "cats"]) bar_height = 50 bins = [0, 1e1, 1e2, 1e3, 1e4, 1e5, 1e10] # Compute histograms, while keeping track of max Y values and max counts for i, (group, vals) in enumerate(data.iteritems()): hist, edges = np.histogram(vals, bins) df = df.append(pd.DataFrame(dict( group = group, width = np.log2(hist[1:]), height = np.ones(len(hist) - 1), texts = ["%d Nodes" % i for i in hist[1:-1]] + ["%d" % hist[-1]], cats = [">10^%d" % np.log10(bin) for bin in bins[1:-1]], ))) df.replace(-np.inf, 0) # Normalize the widths df["width"] *= (maxwidth / df["width"].max()) ds = ColumnDataSource(df) xdr = FactorRange(factors=sorted(df["group"].unique())) ydr = FactorRange(factors=list(df["cats"])) plot = Plot(data_sources=[ds], x_range=xdr, y_range=ydr, title="Degree Distribution (log scale)", plot_width=plot_width, plot_height=plot_height, tools=[]) yaxis = CategoricalAxis(plot=plot, location="left", axis_label="degree") plot.left.append(yaxis) glyph = Rect(x="group", y="cats", width="width", height="height", fill_color="#3366ff") text_glyph = Text(x="group", y="cats", text="texts", text_baseline="middle", text_align="center", angle=0) plot.renderers.append(Glyph(data_source=ds, xdata_range=xdr, ydata_range=ydr, glyph=glyph)) plot.renderers.append(Glyph(data_source=ds, xdata_range=xdr, ydata_range=ydr, glyph=text_glyph)) return plot
def cds(): pytest.importorskip('bokeh') from bokeh.objects import ColumnDataSource cds = ColumnDataSource({ 'id': [1, 2, 3], 'name': ['Alice', 'Bob', 'Charlie'], 'amount': [100, 200, 300], 'timestamp': [ datetime(2000, 12, 25, 0, 0, 1), datetime(2001, 12, 25, 0, 0, 1), datetime(2002, 12, 25, 0, 0, 1) ] }) return cds
def classical_gear(module, large_teeth, small_teeth): xdr = Range1d(start=-300, end=150) ydr = Range1d(start=-100, end=100) source = ColumnDataSource(data=dict(dummy=[0])) plot = Plot(title=None, data_sources=[source], x_range=xdr, y_range=ydr, width=800, height=800) plot.tools.extend( [PanTool(plot=plot), WheelZoomTool(plot=plot), ResetTool(plot=plot)]) radius = pitch_radius(module, large_teeth) angle = 0 glyph = Gear(x=-radius, y=0, module=module, teeth=large_teeth, angle=angle, fill_color=fill_color[0], line_color=line_color) renderer = Glyph(data_source=source, xdata_range=xdr, ydata_range=ydr, glyph=glyph) plot.renderers.append(renderer) radius = pitch_radius(module, small_teeth) angle = half_tooth(small_teeth) glyph = Gear(x=radius, y=0, module=module, teeth=small_teeth, angle=angle, fill_color=fill_color[1], line_color=line_color) renderer = Glyph(data_source=source, xdata_range=xdr, ydata_range=ydr, glyph=glyph) plot.renderers.append(renderer) return plot
def large_plot(n): from bokeh.objects import (Plot, PlotContext, LinearAxis, Grid, Glyph, ColumnDataSource, DataRange1d, PanTool, WheelZoomTool, BoxZoomTool, BoxSelectTool, BoxSelectionOverlay, ResizeTool, PreviewSaveTool, ResetTool) from bokeh.glyphs import Line context = PlotContext() objects = set([context]) for i in xrange(n): source = ColumnDataSource(data=dict(x=[0, i + 1], y=[0, i + 1])) xdr = DataRange1d(sources=[source.columns("x")]) ydr = DataRange1d(sources=[source.columns("y")]) plot = Plot(x_range=xdr, y_range=ydr, data_sources=[source]) xaxis = LinearAxis(plot=plot, dimension=0) yaxis = LinearAxis(plot=plot, dimension=1) xgrid = Grid(plot=plot, dimension=0) ygrid = Grid(plot=plot, dimension=1) tickers = [ xaxis.ticker, xaxis.formatter, yaxis.ticker, yaxis.formatter ] renderer = Glyph(data_source=source, xdata_range=xdr, ydata_range=ydr, glyph=Line(x='x', y='y')) plot.renderers.append(renderer) pan = PanTool(plot=plot) wheel_zoom = WheelZoomTool(plot=plot) box_zoom = BoxZoomTool(plot=plot) box_select = BoxSelectTool(plot=plot) box_selection = BoxSelectionOverlay(tool=box_select) resize = ResizeTool(plot=plot) previewsave = PreviewSaveTool(plot=plot) reset = ResetTool(plot=plot) tools = [ pan, wheel_zoom, box_zoom, box_select, box_selection, resize, previewsave, reset ] plot.tools.append(tools) context.children.append(plot) objects |= set( [source, xdr, ydr, plot, xaxis, yaxis, xgrid, ygrid, renderer] + tickers + tools) return context, objects
def create(self, doc): """ This function is called once, and is responsible for creating all objects (plots, datasources, etc) """ self.modelform = MyModel() self.modelform.create_inputs(doc) self.source = ColumnDataSource(data={'x': [], 'y': []}) self.update_data() self.plot = line('x', 'y', source=self.source, plot_width=400, plot_height=400, title=self.modelform.title) self.children.append(self.modelform) self.children.append(self.plot)
def __init__(self): self.document = Document() self.session = Session() self.session.use_doc('data_tables_server') self.session.load_document(self.document) self.manufacturer_filter = None self.model_filter = None self.transmission_filter = None self.drive_filter = None self.class_filter = None self.source = ColumnDataSource() self.update_data() self.document.add(self.create()) self.session.store_document(self.document)
def epicyclic_gear(module, sun_teeth, planet_teeth): xdr = Range1d(start=-150, end=150) ydr = Range1d(start=-150, end=150) source = ColumnDataSource(data=dict(dummy=[0])) plot = Plot( title=None, x_range=xdr, y_range=ydr, plot_width=800, plot_height=800 ) plot.add_tools(PanTool(), WheelZoomTool(), ResetTool()) annulus_teeth = sun_teeth + 2*planet_teeth glyph = Gear( x=0, y=0, module=module, teeth=annulus_teeth, angle=0, fill_color=fill_color[0], line_color=line_color, internal=True ) plot.add_glyph(source, glyph) glyph = Gear( x=0, y=0, module=module, teeth=sun_teeth, angle=0, fill_color=fill_color[2], line_color=line_color ) plot.add_glyph(source, glyph) sun_radius = pitch_radius(module, sun_teeth) planet_radius = pitch_radius(module, planet_teeth) radius = sun_radius + planet_radius angle = half_tooth(planet_teeth) for i, j in [(+1, 0), (0, +1), (-1, 0), (0, -1)]: glyph = Gear( x=radius*i, y=radius*j, module=module, teeth=planet_teeth, angle=angle, fill_color=fill_color[1], line_color=line_color ) plot.add_glyph(source, glyph) return plot
def create(cls): """ This function is called once, and is responsible for creating all objects (plots, datasources, etc) """ obj = cls() obj.pretext = PreText(text="", width=500, height=80) obj.inputs = VBoxForm() obj.outputs = VBox() #inputs obj.source = ColumnDataSource(data=dict(xs=[], ys=[])) obj.make_inputs() # outputs obj.make_data() obj.make_line_plot() obj.make_stats(err=None) obj.set_children() return obj
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") 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(), PreviewSaveTool(), ResetTool(), ResizeTool(), WheelZoomTool(), ) return plot
session.load_document(document) days_of_week = { 0: "Monday", 1: "Tuesday", 2: "Wednesday", 3: "Thursday", 4: "Friday", 5: "Saturday", 6: "Sunday" } bounds_start = datetime.date(2012, 11, 1) bounds_end = datetime.date(2013, 12, 30) start = datetime.date(2013, 5, 26) end = datetime.date(2013, 7, 5) source_country = ColumnDataSource(data=dict()) source_dow = ColumnDataSource(data=dict()) source_jobtype = ColumnDataSource(data=dict()) source_par = Paragraph() country_choices = [ "Dominican Republic___________________", "Colombia_____________________________", "Mexico_______________________________", "Peru_________________________________", "Argentina____________________________" ] countries = [ "Brazil", "Canada", "Italy", "Panama", "Costa Rica", "Saint Martin", "Peru", "Argentina", "Bolivia", "Venezuela", "Ecuador", "El Salvador", "China", "Chile", "Puerto Rico", "Dominican Republic", "Spain", "Dubai",
title="Austin") select_tool = BoxSelectTool() overlay = BoxSelectionOverlay(tool=select_tool) plot.renderers.append(overlay) plot.tools.append(select_tool) xgrid = Grid(plot=plot, dimension=0) ygrid = Grid(plot=plot, dimension=1) pantool = PanTool(plot=plot) wheelzoomtool = WheelZoomTool(plot=plot) plot.tools.extend([pantool, wheelzoomtool]) # Plot some data on top source = ColumnDataSource(data=dict(lat=[30.2861, 30.2855, 30.2869], lon=[-97.7394, -97.7390, -97.7405], fill=['orange', 'blue', 'green'])) circle_renderer = Glyph(data_source=source, xdata_range=x_range, ydata_range=y_range, glyph=Circle(x="lon", y="lat", fill_color="fill", size=15, radius_units="screen", line_color="black")) plot.data_sources.append(source) plot.renderers.append(circle_renderer) try: