bokeh

Changing source of plot in bokeh with a callback

懵懂的女人 提交于 2019-12-03 09:13:53
Imagine I have 2 (or more) sources of data with the same number of columns and rows: #Data dates = [date(2016, i, 1) for i in range(1,13)] data1 = pd.DataFrame(index = dates, data = random.randn(12, 2), columns = ['A', 'B']) data2 = pd.DataFrame(index = dates, data = random.randn(12, 2), columns = ['A', 'B']) and I want to plot columns A & B in bokeh as so: #Bokeh source = ColumnDataSource(source1) source1 = ColumnDataSource(data1) source2 = ColumnDataSource(data2) p = figure(x_axis_type = 'datetime') l1 = p.line(source = source, x = dates, y= 'A', color = 'Red') l2 = p.line(source = source, x

how to adjust # of ticks on Bokeh axis (labels are overlapping on small figures)

限于喜欢 提交于 2019-12-03 09:04:57
问题 I have a multi-figure Bokeh plot of vertically stacked & aligned figures. Because I want to align the plots vertically, the y-axis labels are rotated to be vertical rather than horizontal. In certain scenarios, Bokeh produces too many ticks, such that the tick labels overlap completely, making illegible. Here is an example: import bokeh.plotting as bp import numpy as np y = np.random.uniform(0, 300, 50) x = np.arange(len(y)) bp.output_file("/tmp/test.html", "test") plot = bp.figure(plot_width

Two interactive bokeh plots: select a value in one graph and change the other

和自甴很熟 提交于 2019-12-03 09:00:29
I want to create an interactive python Bokeh plot. I have two dataframes which are linked by the column names . When I select a bar in plot1 I want to show in plot 2 the data of dataframe 2 (df2) that belong to that column. For example the df1 could contain the mean of all columns of df2. If you click on the displayed mean you can sea in the second graph the rawdata that formed the basis for the mean. Unfortunately I cannot get it working and I could not find a comparable example. Below is what I have so far. I assume the error is in mycolumn="@colnames" and the taptool is not returning what I

How to capture value of dropdown widget in bokeh python?

不问归期 提交于 2019-12-03 08:50:10
The official documentation of bokeh 0.12.1 in the link give the below code for creating a dropdown. http://bokeh.pydata.org/en/latest/docs/user_guide/interaction/widgets.html#userguide-interaction-widgets But its doesn't clearly mention how to capture the value of the dropdown widget when someone click and selects a value from the dropdown. from bokeh.io import output_file, show from bokeh.layouts import widgetbox from bokeh.models.widgets import Dropdown output_file("dropdown.html") menu = [("Item 1", "item_1"), ("Item 2", "item_2"), None, ("Item 3", "item_3")] dropdown = Dropdown(label=

How can I get data from a ColumnDataSource object which is synchronized with local variables of Bokeh's CustomJS function?

不想你离开。 提交于 2019-12-03 08:26:56
Based on the following code sample, I want to extract the data (for example the x value) in the CustomJS function to save it in the python list rect_data . Although the variable x is synchronized with the ColumnDataSource object source , the python list rect_data remains an empty list when I draw a rectangular selection in the figure of the executed code below. What am I doing wrong and how can I solve this problem? Thank you in advance! # You must first run "bokeh serve" to view this example from bokeh.models import CustomJS, ColumnDataSource, BoxSelectTool, Range1d, Rect from bokeh.plotting

Using colormap with bokeh scatter

橙三吉。 提交于 2019-12-03 07:41:49
In matplotlib the scatterplot offers the possibility of using the color of a plot to indicate value or magnitude like this plot: For bokeh , similar examples seem to manually generate the rgb colors, which makes it difficult to produce plots with color scaled by magnitude, esp. wrt. diverging colormaps. Is it possible to have similar functionality in bokeh , or to use matplotlib colormaps to set the color? It's easy enough to just use matplotlib 's colormaps directly. For example, the following uses viridis in bokeh 's example (note that I'm using a jupyter notebook): import numpy as np from

Embedding a plot in a website with Python/bokeh

风流意气都作罢 提交于 2019-12-03 07:24:44
问题 I am trying to statically embed a bokeh plot in a personal website, and am encountering some behavior I do not understand. Basically, I am generating a plot using bokeh as follows: import bokeh.plotting as bplt import numpy as np x=np.random.random(100) y=np.random.random(100) bplt.output_file("t.html") plot=bplt.line(x,y) ##the following line refers to the bokeh installed on my home computer print plot.create_html_snippet( static_path='/usr/local/lib/python2.7/site-packages/bokeh/server

How to refresh Bokeh Document

旧街凉风 提交于 2019-12-03 06:24:48
I would like to refresh a bokeh document so I can replace old plots with new ones. However, right now I just get the new plots appended to the document so the old ones don't go away. #myfile.py from bokeh.plotting import curdoc, figure doc = curdoc() p1 = figure(width=1500, height=230, active_scroll="wheel_zoom") doc.add_root(p1) doc.clear() p2 = figure(width=1500, height=500, active_scroll="wheel_zoom") doc.add_root(p2) This results in the second plot being displayed after the first plot, though the expected behavior I am looking for is the second plot replacing the first plot. How can I

Infinite horizontal line in Bokeh

╄→гoц情女王★ 提交于 2019-12-03 05:00:42
Is there a way to plot an infinite horizontal line with Bokeh? The endpoints of the line should never become visible, no matter how far out the user is zooming. This is what I've tried so far. It just prints an empty canvas: import bokeh.plotting as bk import numpy as np p = bk.figure() p.line([-np.inf,np.inf], [0,0], legend="y(x) = 0") bk.show(p) One way would be to set the endpoints extremely high/low and the figure's x_range and y_range very small in relation to them. import bokeh.plotting as bk import numpy as np p = bk.figure(x_range=[-10,10]) p.line([-np.iinfo(np.int64).max, np.iinfo(np

how to adjust # of ticks on Bokeh axis (labels are overlapping on small figures)

喜你入骨 提交于 2019-12-03 02:21:40
I have a multi-figure Bokeh plot of vertically stacked & aligned figures. Because I want to align the plots vertically, the y-axis labels are rotated to be vertical rather than horizontal. In certain scenarios, Bokeh produces too many ticks, such that the tick labels overlap completely, making illegible. Here is an example: import bokeh.plotting as bp import numpy as np y = np.random.uniform(0, 300, 50) x = np.arange(len(y)) bp.output_file("/tmp/test.html", "test") plot = bp.figure(plot_width=800, plot_height=200) plot.yaxis.axis_label_text_font_size = "12pt" plot.yaxis.major_label_orientation