Skip to content

Instantly share code, notes, and snippets.

@Pabla007
Created April 8, 2019 23:54
Show Gist options
  • Save Pabla007/e4709cda745a8dbc9549caaef213ea6e to your computer and use it in GitHub Desktop.
Save Pabla007/e4709cda745a8dbc9549caaef213ea6e to your computer and use it in GitHub Desktop.
Static plot with dynamic Interactive Features
from starkit.gridkit import load_grid
import h5py
import numpy as np
#print dir(plt)
grid =load_grid('C:\Users\pabla\OneDrive\Documents\p.h5')
grid
import matplotlib.pyplot as plt
grid.teff = 5780.
grid.logg = 4.4
grid.mh = 0.0
wave, flux= grid()
plt.plot(wave, flux,linestyle="--",dashes=(500000,10))
from bokeh.plotting import figure,output_file,show,output_notebook
import bokeh.io
# this is here only for completeness to clarify where
# the methods are nested (you probably already imported this earlier)
bokeh.io.reset_output()
bokeh.io.output_notebook()
output_notebook()
p=figure(plot_width=400,plot_height=400,tools='box_zoom,box_select,hover')
p.line(wave,flux)
#p.line(wave,flux,line_width="2" )
#p.line(df,df1,line_width="2")
#plt.plot(wave,flux,color='green', linestyle='--',linewidth=2)
#show(p)
from bokeh.layouts import row, widgetbox
from bokeh.models import CustomJS, Slider
from bokeh.plotting import figure, output_file, show, ColumnDataSource
x =wave
y =flux
source = ColumnDataSource(data=dict(x=x, y=y))
plot = figure(plot_width=400, plot_height=400)
plot.line('x', 'y', source=source, line_width=1, line_alpha=0.5)
#show(plot)
callback = CustomJS(args=dict(source=source), code="""
var data = source.data;
var teff= teff.value;
var log = 4.4;
var mh = 0.0;
var x = data['x']
var y = data['y']
grid.teff=teff
wave,flux=grid()
source.change.emit();
""")
teff_slider = Slider(start=1, end=10000, value=1, step=5,title="Teff", callback=callback)
callback.args["teff"] = teff_slider
layout = row(plot,widgetbox(teff_slider))
output_notebook()
#show(layout)
# myapp.py
from bokeh.io import curdoc
from bokeh.io import output_file
def callback(attr,old,new):
print 'hi'
N=slider.value
print N
#output_file("simranjit.htm")
# add a button widget and configure with the call back
slider = Slider(start=1, end=10000, value=1, step=5,title="Teff")
slider.on_change('value',callback)
#layout=row(slider,plot)
#show(layout)
# put the button and plot in a layout and add to the document
curdoc().add_root(row(slider, p))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment