Hello,
I’ve been trying to find out the way to pass multiple data sources and variable from/to CustomJS.
To illustrate my questions, you will find the corresponding code below:
- How can python variables ( L, x,y and z) be passed to callback CustomsJS ?
- in CustomJS : L must replace 6 in all formulas , the projected xAz, yAz must be computer
- How can the slider (azimuth variable) can be passed to be displayed as x-label ?
Thanks
Philippe
···
==========================================================================
import numpy as np
import pandas as pd
from math import *
from ipywidgets import interact
from bokeh.io import push_notebook, show, output_notebook
from bokeh.plotting import *
from bokeh.layouts import widgetbox, gridplot
from bokeh.models import CustomJS, Slider, Range1d, formatters
output_notebook()
– Dataset 3D xt,yt,zt trajectory
df = pd.DataFrame({‘East’ : np.array([1,2,3,4]),
‘North’ : np.array([4,3,2,1]),
‘Depth’ : np.array([0,-10,-20,-30])})
xt = df[‘North’]
yt = df[‘North’]
zt = df[‘Depth’]
Az = Azimuth
Az =30
Crosshair definition
L = 6
Crosshair Line length L=3, Az=30
Xp1 = Lsin(Azpi/180)
Yp1 = Lcos(Azpi/180)
Xp2 = L*sin((90+Az)*pi/180)/2
Yp2 = L*cos((90+Az)*pi/180)/2
create arrays
xC = np.array([-Xp1/2,Xp1,0,-Xp2,Xp2])
yC = np.array([-Yp1/2,Yp1,0,-Yp2,Yp2])
computing xAz, yAz projection on vertical plane with Azimuth Az
xAz = pd.Series(ytcos(Azpi/180) + xtsin(Azpi/180))
yAz = pd.Series(yt*cos((Az+90)pi/180) + xtsin((Az+90)*pi/180))
sourceC = ColumnDataSource(data=dict(x=xC, y=yC))
sourceAz = ColumnDataSource(data=dict(x=xAz, y=yAz))
Bokeh figures ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
left, right, bottom, top = -5,5, -5,5
TopViewFig = figure(width=300, height=300, title=“Top View (TopViewFig)”,
x_range=Range1d(left, right), y_range=Range1d(bottom, top))
@@@@@
AzViewFig = figure(width=450, height=300,title=“Projection on vertical section with Az (AzViewFig)”,
x_axis_label=‘Azimuth Projection [m]: (’+str(Az)+’ degrees)’)
Plots ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
TopViewFig.line(xt,yt,color="#2222aa",line_width=3)
TopViewFig.line(‘x’,‘y’,source=sourceC, color="#999999", line_alpha=.8 )
AzViewFig.line(‘x’,‘y’,source=sourceAz,color="#999999", line_alpha=.8 )
callback = CustomJS(args=dict(source=sourceC), code="""
var data = source.data;
var a = Azimuth.value;
x = data[‘x’]
y = data[‘y’]
x[0] = -6/2Math.sin(aMath.PI/180);
y[0] = -6/2Math.cos(aMath.PI/180);
x[1] = 6Math.sin(aMath.PI/180);
y[1] = 6Math.cos(aMath.PI/180);
x[2] = 0;
y[2] = 0;
x[3] = -6/2*Math.sin((90+a)*Math.PI/180);
y[3] = -6/2*Math.cos((90+a)*Math.PI/180);
x[4] = 6/2*Math.sin((90+a)*Math.PI/180);
y[4] = 6/2*Math.cos((90+a)*Math.PI/180);
source.trigger(‘change’);
“”")
Azimuth_slider = Slider(start=0, end=360, value=Az, step=1,
title=“Azimuth (deg) 0-360”, callback=callback)
callback.args[“Azimuth”] = Azimuth_slider
layout = gridplot([TopViewFig, AzViewFig],
[widgetbox(Azimuth_slider)])
show(layout)