def make_plots(self, ticker1, ticker2): self.plot = circle(ticker1 + "_returns", ticker2 + "_returns", title="%s vs %s" %(ticker1, ticker2), source=self.source, plot_width=400, plot_height=400, tools="pan,wheel_zoom,select" ) session().plotcontext.children=[self] session().plotcontext._dirty = True
def make_plots(self, ticker1, ticker2): self.plot = circle(ticker1 + "_returns", ticker2 + "_returns", title="%s vs %s" % (ticker1, ticker2), source=self.source, plot_width=400, plot_height=400, tools="pan,wheel_zoom,select") session().plotcontext.children = [self] session().plotcontext._dirty = True
def wrapper(*args, **kwargs): docname = prefix + str(uuid.uuid4()) output_server(docname, url=url) app = func(*args, **kwargs) session().add(app) session().plotcontext.children=[app] session().plotcontext._dirty = True logger.debug("stored: %s", str(session().store_all())) app.docname = docname return app
def main(): app = make_plot() docname = session().docname return render_template('page.html', docname=docname, bokeh_location=bokeh_location, splitjs=splitjs )
def main(): app = make_plot() docname = session().docname return render_template('page.html', docname=docname, bokeh_location=bokeh_location, splitjs=splitjs)
def exampleapp(): app = make_app() docname = session().docname docid = session().docid extra_generated_classes = app.extra_generated_classes if len(extra_generated_classes) == 0: extra_generated_classes.append((app.__view_model__, app.__view_model__, app.jsmodel)) extra_generated_classes.append( (app.modelform.__view_model__, app.modelform.__view_model__, app.modelform.jsmodel) ) return render_template( "applet.html", extra_generated_classes=extra_generated_classes, title=app.__class__.__view_model__, docname=docname, docid=docid, splitjs=bokeh_app.splitjs, )
def exampleapp(): app = make_app() docname = session().docname docid = session().docid extra_generated_classes = app.extra_generated_classes if len(extra_generated_classes) == 0: extra_generated_classes.append( (app.__view_model__, app.__view_model__, app.jsmodel)) extra_generated_classes.append( (app.modelform.__view_model__, app.modelform.__view_model__, app.modelform.jsmodel)) return render_template( 'applet.html', extra_generated_classes=extra_generated_classes, title=app.__class__.__view_model__, docname=docname, docid=docid, splitjs=bokeh_app.splitjs)
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 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
pres_y = np.array([20]) bk.output_server('Pressure') bk.line( time_x, pres_y, color='#0000FF', tools= 'pan,wheel_zoom,box_zoom,reset,resize,crosshair,select,previewsave,embed', width=1200, height=300) bk.xaxis()[0].axis_label = 'Time' bk.yaxis()[0].axis_label = 'Pressure' renderer = [r for r in bk.curplot().renderers if isinstance(r, Glyph)][0] ds = renderer.data_source while True: ds.data["x"] = time_x ds.data["y"] = pres_y ds._dirty = True bk.session().store_obj(ds) time.sleep(1) t = t + 1 time_x = np.append(time_x, time_x[t - 1] + 1) pres_y = np.append( pres_y, pres_y[t - 1] + np.random.random() * pres_y[t - 1] * 0.01)
from bokeh import pyplot from pylab import * from bokeh import plotting x = linspace(-2*pi,2*pi,100) y = sin(x) plot(x,y,"r-") title("Matplotlib Figure in Bokeh") # dashed lines work #plot(x,y,"r-x", linestyle="-.") pyplot.show_bokeh(gcf(), filename="mpltest.html") plotting.session().dumpjson(file="mpltest.json")
# Generate data. In this case, we'll make a bunch of center-points and generate # verticies by subtracting random offsets from those center-points numpoly, numverts = 100, 4 centers = 100 * (np.random.random((numpoly, 2)) - 0.5) offsets = 10 * (np.random.random((numverts, numpoly, 2)) - 0.5) verts = centers + offsets verts = np.swapaxes(verts, 0, 1) # In your case, "verts" might be something like: # verts = zip(zip(lon1, lat1), zip(lon2, lat2), ...) # If "data" in your case is a numpy array, there are cleaner ways to reorder # things to suit. colors = ['red', 'green', 'blue', 'cyan', 'yellow', 'magenta', 'black'] ax = plt.axes() # Make the collection and add it to the plot. col = PolyCollection(verts, color=colors) ax.add_collection(col) plt.xlim([-60, 60]) plt.ylim([-60, 60]) plt.title("MPL-PolyCollection support in Bokeh") pyplot.show_bokeh(plt.gcf(), filename="polycollection.html") plotting.session().dumpjson(file="polycollection.json")
def make_app(): app = cls() app.create(session()) return app
import numpy as np import pandas as pd import seaborn as sns import matplotlib as mpl import matplotlib.pyplot as plt from bokeh import pyplot from bokeh import plotting # Generate the pandas dataframe data = np.random.multivariate_normal([0, 0], [[1, 2], [2, 20]], size=100) data = pd.DataFrame(data, columns=["X", "Y"]) mpl.rc("figure", figsize=(6, 6)) # Just plot seaborn kde sns.kdeplot(data, cmap="BuGn_d") plt.title("Seaborn kdeplot in bokeh.") pyplot.show_bokeh(plt.gcf(), filename="seaborn_kde.html") plotting.session().dumpjson(file="seaborn_kde.json")
import matplotlib.pyplot as plt from matplotlib.collections import LineCollection from bokeh import pyplot from bokeh import plotting # In order to efficiently plot many lines in a single set of axes, # add the lines all at once. Here is a simple example showing how it is done. N = 50 x = np.arange(N) # Here are many sets of y to plot vs x ys = [x + i for i in x] colors = [ '#ff0000', '#008000', '#0000ff', '#00bfbf', '#bfbf00', '#bf00bf', '#000000' ] line_segments = LineCollection([list(zip(x, y)) for y in ys], color=colors, linewidth=(0.5, 1, 1.5, 2), linestyle='dashed') ax = plt.axes() ax.add_collection(line_segments) ax.set_title('Line Collection with dashed colors') pyplot.show_bokeh(plt.gcf(), filename="lc_dashed.html") plotting.session().dumpjson(file="lc_dashed.json")
# Generate data. In this case, we'll make a bunch of center-points and generate # verticies by subtracting random offsets from those center-points numpoly, numverts = 100, 4 centers = 100 * (np.random.random((numpoly,2)) - 0.5) offsets = 10 * (np.random.random((numverts,numpoly,2)) - 0.5) verts = centers + offsets verts = np.swapaxes(verts, 0, 1) # In your case, "verts" might be something like: # verts = zip(zip(lon1, lat1), zip(lon2, lat2), ...) # If "data" in your case is a numpy array, there are cleaner ways to reorder # things to suit. colors = ['red','green','blue','cyan','yellow','magenta','black'] ax = plt.axes() # Make the collection and add it to the plot. col = PolyCollection(verts, color=colors) ax.add_collection(col) plt.xlim([-60, 60]) plt.ylim([-60, 60]) plt.title("MPL-PolyCollection support in Bokeh") pyplot.show_bokeh(plt.gcf(), filename="mpl_polycollection.html") plotting.session().dumpjson(file="mpl_polycollection.json")
import matplotlib.pyplot as plt from scipy import optimize from bokeh import pyplot from bokeh import plotting # Set the palette colors. sns.set(palette="Set2") # Build the sin wave def sine_wave(n_x, obs_err_sd=1.5, tp_err_sd=.3): x = np.linspace(0, (n_x - 1) / 2, n_x) y = np.sin(x) + np.random.normal(0, obs_err_sd) + np.random.normal(0, tp_err_sd, n_x) return y sines = np.array([sine_wave(31) for _ in range(20)]) # Generate the Seaborn plot with "ci" bars. ax = sns.tsplot(sines, err_style="ci_bars", interpolate=False) xmin, xmax = ax.get_xlim() x = np.linspace(xmin, xmax, sines.shape[1]) out, _ = optimize.leastsq(lambda p: sines.mean(0) - (np.sin(x / p[1]) + p[0]), (0, 2)) a, b = out xx = np.linspace(xmin, xmax, 100) plt.plot(xx, np.sin(xx / b) + a, c="#444444"); plt.title("Seaborn tsplot with CI in bokeh.") pyplot.show_bokeh(plt.gcf(), filename="mpl_seaborn_sinerror.html") plotting.session().dumpjson(file="mpl_seaborn_sinerror.json")
plt.plot(x, y1, 'ks', xfit, fit(xfit), 'r-', lw=2) plt.axis([2, 20, 2, 14]) plt.setp(plt.gca(), xticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20)) plt.ylabel('I', fontsize=20) plt.subplot(222) plt.plot(x, y2, 'ks', xfit, fit(xfit), 'r-', lw=2) plt.axis([2, 20, 2, 14]) plt.setp(plt.gca(), xticklabels=[], yticks=(4, 8, 12), yticklabels=[], xticks=(0, 10, 20)) plt.ylabel('II', fontsize=20) plt.subplot(223) plt.plot(x, y3, 'ks', xfit, fit(xfit), 'r-', lw=2) plt.axis([2, 20, 2, 14]) plt.ylabel('III', fontsize=20) plt.setp(plt.gca(), yticks=(4, 8, 12), xticks=(0, 10, 20)) plt.subplot(224) xfit = np.array([np.amin(x4), np.amax(x4)]) plt.plot(x4, y4, 'ks', xfit, fit(xfit), 'r-', lw=2) plt.axis([2, 20, 2, 14]) plt.setp(plt.gca(), yticklabels=[], yticks=(4, 8, 12), xticks=(0, 10, 20)) plt.ylabel('IV', fontsize=20) # We create the figure in matplotlib and then we "pass it" to Bokeh pyplot.show_bokeh(plt.gcf(), filename="subplots.html") plotting.session().dumpjson(file="subplots.json")
# colors = ['#ff0000', '#008000', '#0000ff', '#00bfbf', '#bfbf00', '#bf00bf', '#000000'] # colors = [(1.0, 0.0, 0.0, 1.0), (0.0, 0.5, 0.0, 1.0), (0.0, 0.0, 1.0, 1.0), (0.0, 0.75, 0.75, 1.0), # (0.75, 0.75, 0, 1.0), (0.75, 0, 0.75, 1.0), (0.0, 0.0, 0.0, 1.0)] colors = ['r', 'g', 'b', 'c', 'y', 'm', 'k'] widths = [5, 10, 20, 40, 20, 10, 5] segments = make_segments(x, y) lc = LineCollection(segments, colors=colors, linewidth=widths, alpha=alpha) ax = plt.gca() ax.add_collection(lc) return lc # Colored sine wave x = np.linspace(0, 4 * np.pi, 100) y = np.sin(x) colorline(x, y) plt.title("MPL support for ListCollection in Bokeh") plt.xlim(x.min(), x.max()) plt.ylim(-1.0, 1.0) pyplot.show_bokeh(plt.gcf(), filename="listcollection.html") plotting.session().dumpjson(file="listcollection.json")
nverts = 60 ncurves = 20 offs = (0.1, 0.0) rs = np.random.RandomState([12345678]) yy = np.linspace(0, 2*np.pi, nverts) ym = np.amax(yy) xx = (0.2 + (ym-yy)/ym)**2 * np.cos(yy-0.4) * 0.5 segs = [] for i in range(ncurves): xxx = xx + 0.02*rs.randn(nverts) curve = list(zip(xxx, yy*100)) segs.append(curve) colors = [(1.0, 0.0, 0.0, 1.0), (0.0, 0.5, 0.0, 1.0), (0.0, 0.0, 1.0, 1.0), (0.0, 0.75, 0.75, 1.0), (0.75, 0.75, 0, 1.0), (0.75, 0, 0.75, 1.0), (0.0, 0.0, 0.0, 1.0)] col = LineCollection(segs, linewidth=5, offsets=offs) ax = plt.axes() ax.add_collection(col, autolim=True) col.set_color(colors) ax.set_title('Successive data offsets') fig = plt.gcf() pyplot.show_bokeh(plt.gcf(), filename="mpl_lc_offsets.html") plotting.session().dumpjson(file="mpl_lc_offsets.json")
import numpy as np import matplotlib.pyplot as plt from matplotlib.collections import LineCollection from bokeh import pyplot from bokeh import plotting # In order to efficiently plot many lines in a single set of axes, # add the lines all at once. Here is a simple example showing how it is done. N = 50 x = np.arange(N) # Here are many sets of y to plot vs x ys = [x+i for i in x] colors = ['#ff0000', '#008000', '#0000ff', '#00bfbf', '#bfbf00', '#bf00bf', '#000000'] line_segments = LineCollection([list(zip(x,y)) for y in ys], color=colors, linewidth=(0.5,1,1.5,2), linestyle='dashed') ax = plt.axes() ax.add_collection(line_segments) ax.set_title('Line Collection with dashed colors') pyplot.show_bokeh(plt.gcf(), filename="lc_dashed.html") plotting.session().dumpjson(file="lc_dashed.json")
# Set the palette colors. sns.set(palette="Set2") # Build the sin wave def sine_wave(n_x, obs_err_sd=1.5, tp_err_sd=.3): x = np.linspace(0, (n_x - 1) / 2, n_x) y = np.sin(x) + np.random.normal(0, obs_err_sd) + np.random.normal( 0, tp_err_sd, n_x) return y sines = np.array([sine_wave(31) for _ in range(20)]) # Generate the Seaborn plot with "ci" bars. ax = sns.tsplot(sines, err_style="ci_bars", interpolate=False) xmin, xmax = ax.get_xlim() x = np.linspace(xmin, xmax, sines.shape[1]) out, _ = optimize.leastsq(lambda p: sines.mean(0) - (np.sin(x / p[1]) + p[0]), (0, 2)) a, b = out xx = np.linspace(xmin, xmax, 100) plt.plot(xx, np.sin(xx / b) + a, c="#444444") plt.title("Seaborn tsplot with CI in bokeh.") pyplot.show_bokeh(plt.gcf(), filename="seaborn_sinerror.html") plotting.session().dumpjson(file="seaborn_sinerror.json")
import numpy as np import matplotlib.pyplot as plt import seaborn as sns from bokeh import pyplot from bokeh import plotting # We generated random data data = 1 + np.random.randn(20, 6) # And then just call the violinplot from Seaborn sns.violinplot(data, color="Set3") plt.title("Seaborn violin plot in bokeh.") pyplot.show_bokeh(plt.gcf(), filename="mpl_seaborn_violet.html") plotting.session().dumpjson(file="mpl_seaborn_violet.json")
import numpy as np import matplotlib.pyplot as plt from bokeh import pyplot from bokeh import plotting x = np.linspace(-2 * np.pi, 2 * np.pi, 100) y = np.sin(x) plt.plot(x, y, "r-") plt.title("Matplotlib Figure in Bokeh") # dashed lines work #plt.plot(x,y,"r-x", linestyle="-.") pyplot.show_bokeh(plt.gcf(), filename="mpltest.html") plotting.session().dumpjson(file="mpltest.json")
t = 0 time_x = np.array([0]) pres_y = np.array([20]) bk.output_server('Pressure') bk.line(time_x, pres_y, color='#0000FF', tools='pan,wheel_zoom,box_zoom,reset,resize,crosshair,select,previewsave,embed', width=1200,height=300) bk.xaxis()[0].axis_label = 'Time' bk.yaxis()[0].axis_label = 'Pressure' renderer = [r for r in bk.curplot().renderers if isinstance(r, Glyph)][0] ds = renderer.data_source while True: ds.data["x"] = time_x ds.data["y"] = pres_y ds._dirty = True bk.session().store_obj(ds) time.sleep(1) t = t + 1 time_x = np.append(time_x, time_x[t-1]+1) pres_y = np.append(pres_y, pres_y[t-1] + np.random.random()*pres_y[t-1]*0.01)
# colors = ['red','green','blue','cyan','yellow','magenta','black'] # colors = ['#ff0000', '#008000', '#0000ff', '#00bfbf', '#bfbf00', '#bf00bf', '#000000'] # colors = [(1.0, 0.0, 0.0, 1.0), (0.0, 0.5, 0.0, 1.0), (0.0, 0.0, 1.0, 1.0), (0.0, 0.75, 0.75, 1.0), # (0.75, 0.75, 0, 1.0), (0.75, 0, 0.75, 1.0), (0.0, 0.0, 0.0, 1.0)] colors = ['r','g','b','c','y','m','k'] widths = [5, 10, 20, 40, 20, 10, 5] segments = make_segments(x, y) lc = LineCollection(segments, colors=colors, linewidth=widths, alpha=alpha) ax = plt.gca() ax.add_collection(lc) return lc # Colored sine wave x = np.linspace(0, 4 * np.pi, 100) y = np.sin(x) colorline(x, y) plt.title("MPL support for ListCollection in Bokeh") plt.xlim(x.min(), x.max()) plt.ylim(-1.0, 1.0) pyplot.show_bokeh(plt.gcf(), filename="listcollection.html") plotting.session().dumpjson(file="listcollection.json")