Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bokeh - How to Click and Drag?

Tags:

python

bokeh

I would like to click-and-drag the scatter points the points of a bokeh scatter plot. Any ideas how to do this?

(edit: this is an example of what I'd like to do)

For an example of a scatter, the code below generates the scatter plot chart found half-way through this page.

from bokeh.plotting import figure, output_file, show

# create a Figure object
p = figure(width=300, height=300, tools="pan,reset,save")

# add a Circle renderer to this figure
p.circle([1, 2.5, 3, 2], [2, 3, 1, 1.5], radius=0.3, alpha=0.5)

# specify how to output the plot(s)
output_file("foo.html")

# display the figure
show(p)
like image 783
Pythonic Avatar asked May 12 '15 07:05

Pythonic


People also ask

How do you zoom in on bokeh?

2. Zoom In. Bokeh can be achieved at any focal length, but if you're struggling to get a strong bokeh effect, try zooming in more, or using a lens with a longer focal length. If zooming in means you can't fit your subject in the frame, move further away from your subject and re-shoot.

What is hover tool?

The hover tool displays tooltips associated with individual glyphs. You can configure these tooltips to activate in different ways with a mode property: "mouse" only when the mouse is directly over a glyph.

How do you speed up bokeh?

To achieve bokeh in an image, you need to use a fast lens—the faster the better. You'll want to use a lens with at least an f/2.8 aperture, with faster apertures of f/2, f/1.8 or f/1.4 being ideal.


1 Answers

Multi-gesture edit tools are only a recent addition, landing in version 0.12.14. You can find much more information in the Edit Tools section of the User's Guide.

Specifically to be able to move points as described in the OP, use the PointDrawTool:

enter image description here

Here is a complete example you can run that also has a data table showing the updated coordinates of the glyphs as they are moved (you will need to activate the tool in the toolbar first, it is off by default):

from bokeh.plotting import figure, output_file, show, Column
from bokeh.models import DataTable, TableColumn, PointDrawTool, ColumnDataSource

output_file("tools_point_draw.html")

p = figure(x_range=(0, 10), y_range=(0, 10), tools=[],
           title='Point Draw Tool')
p.background_fill_color = 'lightgrey'

source = ColumnDataSource({
    'x': [1, 5, 9], 'y': [1, 5, 9], 'color': ['red', 'green', 'yellow']
})

renderer = p.scatter(x='x', y='y', source=source, color='color', size=10)
columns = [TableColumn(field="x", title="x"),
           TableColumn(field="y", title="y"),
           TableColumn(field='color', title='color')]
table = DataTable(source=source, columns=columns, editable=True, height=200)

draw_tool = PointDrawTool(renderers=[renderer], empty_value='black')
p.add_tools(draw_tool)
p.toolbar.active_tap = draw_tool

show(Column(p, table))
like image 107
bigreddot Avatar answered Sep 28 '22 12:09

bigreddot