<jupyter_start><jupyter_text>Mixing ipyvolume with BokehThis example shows how the selection from a ipyvolume quiver plot can be controlled with a bokeh scatter plot and it's selection tools.  Ipyvolume quiver plotThe 3d quiver plot is done using ipyvolume<jupyter_code>import ipyvolume
import ipyvolume as ipv
import vaex<jupyter_output><empty_output><jupyter_text>We load some data from vaex, but only use the first 10 000 samples for performance reasons of Bokeh.<jupyter_code>ds = vaex.example()
N = 10000<jupyter_output><empty_output><jupyter_text>We make a quiver plot using ipyvolume's matplotlib's style api.<jupyter_code>ipv.figure()
quiver = ipv.quiver(ds.data.x[:N],  ds.data.y[:N],  ds.data.z[:N],
                    ds.data.vx[:N], ds.data.vy[:N], ds.data.vz[:N],
                    size=1, size_selected=5, color_selected="grey")
ipv.xyzlim(-30, 30)
ipv.show()<jupyter_output><empty_output><jupyter_text>Bokeh scatter partThe 2d scatter plot is done using Bokeh.<jupyter_code>from bokeh.io import output_notebook, show
from bokeh.plotting import figure
import ipyvolume.bokeh
output_notebook()
tools = "wheel_zoom,box_zoom,box_select,lasso_select,help,reset,"
p = figure(title="E Lz space", tools=tools, webgl=True, width=500, height=500)
r = p.circle(ds.data.Lz[:N], ds.data.E[:N],color="navy", alpha=0.2)
# A 'trick' from ipyvolume to link the selection (one way traffic atm)
ipyvolume.bokeh.link_data_source_selection_to_widget(r.data_source, quiver, 'selected')
show(p)<jupyter_output><empty_output><jupyter_text>Now try doing a selection and see how the above 3d quiver plot reflects this selection.<jupyter_code># this code is currently broken
# import ipywidgets
#out = ipywidgets.Output()
#with out:
#    show(p)
#ipywidgets.HBox([out, ipv.gcc()])<jupyter_output><empty_output><jupyter_text>Embedding in html A bit of a hack, but it is possible to embed the widget and the bokeh part into a single html file (use at own risk).<jupyter_code>from bokeh.resources import CDN
from bokeh.embed import components

script, div = components((p))
template_options = dict(extra_script_head=script + CDN.render_js() + CDN.render_css(),
                        body_pre="<h2>Do selections in 2d (bokeh)<h2>" + div + "<h2>And see the selection in ipyvolume<h2>")
ipyvolume.embed.embed_html("tmp/bokeh.html",
                           [ipv.gcc(), ipyvolume.bokeh.wmh], all_states=True,
                           template_options=template_options)
!open tmp/bokeh.html<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11040255081705859, 'fraction_numerical': 0.012754085292945397, 'mean_word_length': 4.990453460620525, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '169406', 'license': 'MIT', 'n_tokens_mistral': 905, 'n_tokens_neox': 871, 'n_words': 226, 'path': 'docs/source/bokeh.ipynb', 'repo_name': 'buzmakov/ipyvolume', 'size': '2509'}