def create_figure(s1, s3): """Return figure object of probability distribution.""" plot = Figure(title='Prior Distribution') plot.xaxis.axis_label = 'Probability of Heads (-)' plot.yaxis.axis_label = 'Probability Density (-)' plot.line('x', 'p', source=s1, line_width=4) plot.patch('x', 'y', source=s3, alpha=0.25, line_width=0) return plot
def create_fig(self, sources): """ Implementation of :meth:`LivePlot.create_fig` to set up the bokeh figure """ fig = Figure(background_fill_color= None, toolbar_location = None, x_range=[-100, 100], y_range=[-100, 100], tools="", **self._fig_args) # Remove existing axes and grid fig.xgrid.grid_line_color = None fig.ygrid.grid_line_color = None fig.axis.visible = False # Draw circular grid th = np.linspace(0, 360, 100) # Draw visibility field self.vis_horizon = 10 #fig.patch(*pol2rect([90 - self.vis_horizon]*len(th), th), color='lightgray') fig.patch(*azel2rect(th, [self.vis_horizon]*len(th)), color='lightgray') for r in [0, 20, 40, 60, 80]: fig.line(*azel2rect(th, [r]*len(th)), line_dash='dashed') for th in np.arange(0,360,45): fig.line(*azel2rect([th,th], [0,90]), line_dash='dashed') # Add grid labels lx,ly = azel2rect([0, 90, 180, 270], [0]*4) lx[1] -= 30 lx[2] -= 20 ly[0] -= 10 lx[0] -= 10 src_labels = ColumnDataSource(dict( labels= ['N (0)', 'E (90)', 'S (180)', 'W (270)'], label_x= lx, label_y =ly)) fig.add_layout(LabelSet(x='label_x', y='label_y', text='labels', source=src_labels)) fig.line(source=sources['dpass'], x='x', y = 'y', line_width=2) fig.circle(source=sources['ant_cmd'], x='x', y='y', size=20, fill_color=None) fig.circle(source=sources['ant_cur'], x='x', y='y', size=10, color='green') fig.circle(source=sources['sat'], x= 'x', y ='y', size=10, color= 'yellow') return fig
def add_geom(fig: Figure, geom: BaseGeometry, **kwargs): """Add Shapely geom into Bokeh plot. Args: fig (Figure): geom (BaseGeometry): """ if isinstance(geom, Point): fig.circle(*geom.xy, **kwargs) elif isinstance(geom, LineString): fig.line(*geom.xy, **kwargs) elif isinstance(geom, Polygon): fig.patch(*geom.exterior.xy, **kwargs) elif isinstance(geom, BaseMultipartGeometry): for item in geom: add_geom(fig, item, **kwargs) else: raise TypeError('Object geom {geom} no instance of {types}.'.format( geom=geom, types=BaseGeometry))
function1_input.on_change('value', input_change) # text input for the second function to be convolved function2_input = TextInput(value=convolution_settings.function1_input_init, title="my second function:") function2_input.on_change('value', input_change) # initialize plot toolset = "crosshair,pan,reset,resize,save,wheel_zoom" # Generate a figure container plot = Figure(plot_height=400, plot_width=400, tools=toolset, title="Convolution of two functions", x_range=[convolution_settings.x_min_view, convolution_settings.x_max_view], y_range=[convolution_settings.y_min_view, convolution_settings.y_max_view]) # Plot the line by the x,y values in the source property plot.line('x', 'y', source=source_function1, line_width=3, line_alpha=0.6, color='red', legend='function 1') plot.line('x', 'y', source=source_function2, color='green', line_width=3, line_alpha=0.6, legend='function 2') plot.line('x', 'y', source=source_result, color='blue', line_width=3, line_alpha=0.6, legend='convolution') plot.scatter('x', 'y', source=source_xmarker, color='black') plot.line('x', 'y', source=source_xmarker, color='black', line_width=3) plot.patch('x', 'y_pos', source=source_overlay, fill_color='blue', fill_alpha=.2) plot.patch('x', 'y_neg', source=source_overlay, fill_color='red', fill_alpha=.2) # calculate data update_data() # lists all the controls in our app controls = widgetbox(x_value_input, function_type, function1_input, function2_input, width=400) # make layout curdoc().add_root(row(plot, controls, width=800))
p.line(x='x',y='z',source=latprim4,line_dash='dotted') p.line(x='x',y='z',source=latprim5,line_dash='dotted') left=np.linspace(start=scanel[0],stop=scanel[1],num=101) top=np.linspace(start=scanaz[0],stop=scanaz[1],num=101) scanpts=np.append(np.stack((left*0+scanaz[0],left),axis=-1), np.stack((top,top*0+scanel[1]),axis=-1),axis=0) scanpts=np.append(scanpts,np.stack((left*0+scanaz[1],np.flipud(left)),axis=-1),axis=0) scanpts=np.append(scanpts,np.stack((np.flipud(top),top*0+scanel[0]),axis=-1),axis=0)*np.pi/180 scanu=np.sin(scanpts[:,0])*np.cos(scanpts[:,1]) scanv=np.sin(scanpts[:,1])*np.cos(tilt)-np.cos(scanpts[:,0])*np.cos(scanpts[:,1])*np.sin(tilt) scansource = ColumnDataSource(dict(x=scanu, y=scanv)) p.patch(x='x',y='y',source=scansource,alpha=0.3,line_width=5) p.line(x='x',y='y',source=scansource) grate1=ColumnDataSource(dict(x=londf.values[:,0]-kgx*kmult,y=londf.values[:,2]+kgy*kmult)) grate2=ColumnDataSource(dict(x=londf.values[:,0]+kgx*kmult,y=londf.values[:,2]-kgy*kmult)) grate3=ColumnDataSource(dict(x=londf.values[:,0]+kgx*kmult,y=londf.values[:,2]+kgy*kmult)) grate4=ColumnDataSource(dict(x=londf.values[:,0]-kgx*kmult,y=londf.values[:,2]-kgy*kmult)) grate5=ColumnDataSource(dict(x=londf.values[:,0]-kgx,y=londf.values[:,2])) grate6=ColumnDataSource(dict(x=londf.values[:,0]+kgx,y=londf.values[:,2])) grate7=ColumnDataSource(dict(x=londf.values[:,0],y=londf.values[:,2]+kgy)) grate8=ColumnDataSource(dict(x=londf.values[:,0],y=londf.values[:,2]-kgy)) p.line(x='x',y='y',source=grate1, color="red",line_width=5) p.line(x='x',y='y',source=grate2, color="red",line_width=5) p.line(x='x',y='y',source=grate3, color="red",line_width=5) p.line(x='x',y='y',source=grate4, color="red",line_width=5)
color='green', line_width=3, line_alpha=0.6, legend_label='function 2') plot.line('x', 'y', source=source_result, color='blue', line_width=3, line_alpha=0.6, legend_label='convolution') plot.scatter('x', 'y', source=source_xmarker, color='black') plot.line('x', 'y', source=source_xmarker, color='black', line_width=3) plot.patch('x', 'y_pos', source=source_overlay, fill_color='blue', fill_alpha=.2) plot.patch('x', 'y_neg', source=source_overlay, fill_color='red', fill_alpha=.2) # calculate data update_data() # lists all the controls in our app controls = widgetbox(x_value_input, function_type, function1_input,
wavelength_slider.on_change('value',set_slider_has_changed) interactor.on_click(on_click_change) # create plots #REMARK: color might not be used from internal vis.js and has no effect - colormap always according to z! see https://github.com/bokeh/bokeh/issues/7814 surface = diffraction_Surface3d(x="x", y="y", z="z", color="color", data_source=source_surf, width=500,height=100) # wave surface # contour plots of wave contour_zero = diffraction_Contour(plot, line_width=2,line_color='black', path_filter = 10) # zero level contour_pos = diffraction_Contour(plot, line_width=1, line_color='red', path_filter = 10) # some other levels contour_neg = diffraction_Contour(plot, line_width=1, line_color='blue', path_filter = 10) # some other levels kvector = diffraction_Quiver(plot, fix_at_middle=False) # visualization of wave k vector plot.line(x=[x_min,0], y=[0,0], line_dash='dashed') plot.line(x=[x_max,0], y=[0,0], line_width=10) # the wall plot.line(x='x', y='y', source=source_wavefront) # wavefront visualization plot.patch(x='x', y='y', color='yellow', source=source_light, alpha=.1) # light area plot.patch(x='x', y='y', color='red',source=source_reflection, alpha=.1) # reflection area plot.patch(x='x', y='y', color='blue', source=source_shadow, alpha=.1) # shadow area plot.scatter(x='x',y='y', source=source_value_plotter, size=10) # value probing plot.toolbar.logo = None initialize() # add app description description_filename = join(dirname(__file__), "description.html") description = LatexDiv(text=open(description_filename).read(), render_as_text=False, width=1130) # add area image area_image = Div(text=""" <p>
menu=leibnitz_settings.sample_curve_names) sample_curve_input.on_change('value', sample_curve_change) # initialize plot toolset = "crosshair,pan,reset,save,wheel_zoom" # Generate a figure container plot = Figure(plot_height=400, plot_width=400, tools=toolset, title="Leibnitz sector formula", x_range=[leibnitz_settings.x_min_view, leibnitz_settings.x_max_view], y_range=[leibnitz_settings.y_min_view, leibnitz_settings.y_max_view]) # Plot the line by the x,y values in the source property plot.line('x', 'y', source=source_curve, line_width=3, line_alpha=1, color='black', legend_label='curve') plot.scatter('x', 'y', source=source_point, color='blue', legend_label='point at t') plot.scatter([0], [0], color='black', marker='x') pat = plot.patch('x', 'y', source=source_sector, fill_color='blue', fill_alpha=.2, legend_label='area') plot.line('x_start', 'y_start', source=source_lines, line_width=1, line_alpha=1, color='blue') plot.line('x_end', 'y_end', source=source_lines, line_width=1, line_alpha=1, color='blue') plot.text('x', 'y', text='text', text_color='text_color', source=source_text) # calculate data update_curve() update_point() # lists all the controls in our app controls = widgetbox(t_value_input, sample_curve_input, x_component_input, y_component_input) # make layout curdoc().add_root(row(plot, controls)) curdoc().title = split(dirname(__file__))[-1].replace('_',' ').replace('-',' ') # get path of parent directory and only use the name of the Parent Directory for the tab name. Replace underscores '_' and minuses '-' with blanks ' '
r_mean = 658.0 r_start = 658.0-138.0 r_end = 658.0+138.0 r_dev = 138.0/2.335 r_x = np.linspace(r_start,r_end,1000) r_y = bb_filter_my(r_mean,r_dev,r_x) ''' p3 = Figure(plot_width=500, plot_height=500) p3.title = "Plot at 5500K" p3.yaxis.axis_label = "Flux" p3.xaxis.axis_label = "Wavelength (nm)" p3.patch(ux_pass, uz_pass, line_width=2, line_alpha=0.1, color=(62, 6, 148), legend="Ultraviolet(U)") p3.patch(bx_pass, bz_pass, line_width=2, line_alpha=0.1, color="blue", legend="Blue(B)") p3.patch(vx_pass, vz_pass, line_width=2, line_alpha=0.1, color="violet", legend="Violet(V)") p3.patch(rx_pass,
#standard_dev = 138/2.355 r_mean = 658.0 r_start = 658.0-138.0 r_end = 658.0+138.0 r_dev = 138.0/2.335 r_x = np.linspace(r_start,r_end,1000) r_y = bb_filter_my(r_mean,r_dev,r_x) ''' p3 = Figure(plot_width = 500,plot_height = 500) p3.title = "Plot at 5500K" p3.yaxis.axis_label = "Flux" p3.xaxis.axis_label = "Wavelength (nm)" p3.patch(ux_pass,uz_pass,line_width = 2, line_alpha = 0.1, color = (62,6,148), legend = "Ultraviolet(U)") p3.patch(bx_pass,bz_pass,line_width = 2, line_alpha = 0.1, color = "blue", legend = "Blue(B)") p3.patch(vx_pass,vz_pass,line_width = 2, line_alpha = 0.1, color = "violet", legend = "Violet(V)") p3.patch(rx_pass,rz_pass,line_width = 2, line_alpha = 0.1, color = "red", legend = "Red(R)") #.....................................FluxVsWavelength Implementation......................................................... x = np.linspace(50,3000,500) #print x y = bb_flux(x,temp) #print y source = ColumnDataSource( data=dict( x=x,y=y,gv=gv)) #source1 = ColumnDataSource( data=dict( x=x,y=y,gv=gv,)) hover = HoverTool( tooltips = [ ("(w,B)", "($x, $y)"), ] )
import matplotlib.image as mpimg from astropy.table import Table from bokeh.plotting import Figure, gridplot, output_file, show from bokeh.models import ColumnDataSource, HBox, VBoxForm, Paragraph, Range1d from bokeh.io import curdoc from bokeh.models.widgets import Select, CheckboxButtonGroup, CheckboxGroup from bokeh.models import NumeralTickFormatter from __future__ import print_function mjup = 317.8 p1 = Figure(x_range=[0.003, 3000], y_range=[0.01, 30000], tools="pan,save,wheel_zoom,reset",toolbar_location='above', \ title=' ', y_axis_type="log", x_axis_type='log', plot_height=400, plot_width=800) p1.background_fill_color = "white" p1.patch([0.003, 1.0, 0.2, 0.003, 0.003], [1, 20, 30000., 30000., 1.], alpha=0.5, fill_color='pink', line_width=0) p1.patch([0.003, 0.04, 0.04, 0.003, 0.003], [100, 100, 30000., 30000., 10000.], alpha=0.6, fill_color='lightblue', line_width=0) p1.patch([3, 3000, 3000, 30, 3], [300, 300, 30000., 30000., 300.], alpha=0.6, fill_color='purple', line_width=0) p1.yaxis.axis_label = 'Planet Mass / Earth' p1.xaxis.axis_label = 'Semi-major Axis / Snow Line' p1.xaxis.axis_label_text_font_style = 'bold' p1.yaxis.axis_label_text_font_style = 'bold' p1.xaxis[0].formatter = NumeralTickFormatter(format="0.00") p1.x_range = Range1d(0.003, 3000, bounds=(0.003, 3000))
def create_plot(Pi, a_prior, b_prior): """Plots the prior probability distribution of an unfair coin using Bayes' theorem. Parameters ---------- Pi : float Probability of the coin to come up heads. Returns ------- Script and div components of the Bokeh document. """ # generate prior probability distribution n = 1000 a = a_prior b = b_prior x = np.linspace(0, 1, n) dist = beta(a, b) p = dist.pdf(x) s1 = ColumnDataSource(data=dict(x=x, p=p)) s2 = ColumnDataSource(data=dict(params=[Pi, a_prior, b_prior, a, b])) # arrays for the area under the curve patch xs = np.hstack((x, [1, 0])) ys = np.hstack((p, [0, 0])) s3 = ColumnDataSource(data=dict(x=xs, y=ys)) # plot probability distribution plot = Figure(title='Posterior Distribution') plot.xaxis.axis_label = 'Probability of Heads (-)' plot.yaxis.axis_label = 'Probability Density (-)' plot.line('x', 'p', source=s1, line_width=4) plot.patch('x', 'y', source=s3, alpha=0.25, line_width=0) # calculate mode of prior if a == 1 and b == 1: mode_str = "any value" else: mode_str = str(round((a - 1.0) / (a + b - 2.0), 7)) # add current stats of simulation text = """<b>True Probability:</b> {:g}<br> <b>Number of Heads:</b> {:d}<br> <b>Number of Tails:</b> {:d}<br> <b>Mode:</b> {:s}<br> <b>Variance: </b> {:g} """.format(Pi, a - a_prior, b - b_prior, mode_str, 1.0 / 12) div = Div(text=text) # create button widget and JS callback with open(os.path.join('flask_app', 'static', 'callback.js'), 'r') as fp: code = fp.read() callback = CustomJS(args=dict(s1=s1, s2=s2, s3=s3, div=div), code=code) button = Button(label='Flip Coin', callback=callback) # combine button and plot into one object and return components widgets = row(button, div) layout = column(widgets, plot) return components(layout)
sample_curve_input = Dropdown(label="choose a sample function pair or enter one below", menu=leibnitz_settings.sample_curve_names) sample_curve_input.on_click(sample_curve_change) # initialize plot toolset = "crosshair,pan,reset,resize,save,wheel_zoom" # Generate a figure container plot = Figure(plot_height=400, plot_width=400, tools=toolset, title="Leibnitz sector formula", x_range=[leibnitz_settings.x_min_view, leibnitz_settings.x_max_view], y_range=[leibnitz_settings.y_min_view, leibnitz_settings.y_max_view]) # Plot the line by the x,y values in the source property plot.line('x', 'y', source=source_curve, line_width=3, line_alpha=1, color='black', legend='curve') plot.scatter('x', 'y', source=source_point, color='blue', legend='point at t') plot.scatter([0], [0], color='black', marker='x') pat = plot.patch('x', 'y', source=source_sector, fill_color='blue', fill_alpha=.2, legend='area') plot.line('x_start', 'y_start', source=source_lines, line_width=1, line_alpha=1, color='blue') plot.line('x_end', 'y_end', source=source_lines, line_width=1, line_alpha=1, color='blue') plot.text('x', 'y', text='text', text_color='text_color', source=source_text) # calculate data update_curve() update_point() # lists all the controls in our app controls = widgetbox(t_value_input, sample_curve_input, x_component_input, y_component_input) # make layout curdoc().add_root(row(plot, controls))
plot.line('t', 'x_orig', source=source_orig, line_width=3, line_alpha=0.6, color='red', legend='original function') plot.line('t', 'x_fourier', source=source_fourier, color='green', line_width=3, line_alpha=0.6, legend='fourier series') plot.patch('x_patch', 'y_patch', source=source_interval_patch, alpha=.2) plot.line('x_min', 'y_minmax', source=source_interval_bound) plot.line('x_max', 'y_minmax', source=source_interval_bound) sample_controls = widgetbox(sample_function_type) default_controls = column(default_function_input, default_function_period_start, default_function_period_end) # Panels for sample functions or default functions sample_funs = Panel(child=sample_controls, title='sample function') default_funs = Panel(child=default_controls, title='default function') # Add panels to tabs fun_tabs = Tabs(tabs=[sample_funs, default_funs]) fun_tabs.on_change('active', type_input_change) # add callback for panel tabs
) # Plot the line by the x,y values in the source property plot.line('t', 'x_orig', source=source_orig, line_width=3, line_alpha=0.6, color='red', legend='original function' ) plot.line('t', 'x_fourier', source=source_fourier, color='green', line_width=3, line_alpha=0.6, legend='fourier series' ) plot.patch('x_patch', 'y_patch', source=source_interval_patch, alpha=.2) plot.line('x_min', 'y_minmax', source=source_interval_bound) plot.line('x_max', 'y_minmax', source=source_interval_bound) sample_controls = widgetbox(sample_function_type) default_controls = column(default_function_input,default_function_period_start,default_function_period_end) # Panels for sample functions or default functions sample_funs = Panel(child=sample_controls, title='sample function') default_funs = Panel(child=default_controls, title='default function') # Add panels to tabs fun_tabs = Tabs(tabs=[sample_funs, default_funs]) fun_tabs.on_change('active', type_input_change) # add callback for panel tabs # lists all the controls in our app