Advertisement
Guest User

Untitled

a guest
Apr 18th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. from starkit.gridkit import load_grid
  2. import h5py
  3. import numpy as np
  4.  
  5. #print dir(plt)
  6. grid =load_grid('C:\Users\pabla\OneDrive\Documents\p.h5')
  7. grid
  8. import matplotlib.pyplot as plt
  9.  
  10.  
  11. grid.teff = 5780.
  12. grid.logg = 4.4
  13. grid.mh = 0.0
  14. wave, flux= grid()
  15. plt.plot(wave, flux,linestyle="--",dashes=(500000,10))
  16.  
  17.  
  18. from bokeh.plotting import figure,output_file,show,output_notebook
  19. import bokeh.io
  20. # this is here only for completeness to clarify where
  21. # the methods are nested (you probably already imported this earlier)
  22.  
  23.  
  24. bokeh.io.reset_output()
  25. bokeh.io.output_notebook()
  26. output_notebook()
  27. p=figure(plot_width=400,plot_height=400,tools='box_zoom,box_select,hover')
  28. p.line(wave,flux)
  29. #p.line(wave,flux,line_width="2" )
  30. #p.line(df,df1,line_width="2")
  31. #plt.plot(wave,flux,color='green', linestyle='--',linewidth=2)
  32. #show(p)
  33.  
  34. from bokeh.layouts import row, widgetbox
  35. from bokeh.models import CustomJS, Slider
  36. from bokeh.plotting import figure, output_file, show, ColumnDataSource
  37.  
  38. x =wave
  39. y =flux
  40.  
  41. source = ColumnDataSource(data=dict(x=x, y=y))
  42.  
  43. plot = figure(plot_width=400, plot_height=400)
  44.  
  45. plot.line('x', 'y', source=source, line_width=1, line_alpha=0.5)
  46. #show(plot)
  47. callback = CustomJS(args=dict(source=source), code="""
  48. var data = source.data;
  49. var teff= teff.value;
  50. var log = 4.4;
  51. var mh = 0.0;
  52. var x = data['x']
  53. var y = data['y']
  54. grid.teff=teff
  55. wave,flux=grid()
  56.  
  57. source.change.emit();
  58. """)
  59.  
  60. teff_slider = Slider(start=1, end=10000, value=1, step=5,title="Teff", callback=callback)
  61. callback.args["teff"] = teff_slider
  62.  
  63. layout = row(plot,widgetbox(teff_slider))
  64.  
  65. output_notebook()
  66.  
  67. #show(layout)
  68.  
  69.  
  70. # myapp.py
  71. from bokeh.io import curdoc
  72. from bokeh.io import output_file
  73. def callback(attr,old,new):
  74. print 'hi'
  75. N=slider.value
  76. print N
  77.  
  78. #output_file("simranjit.htm")
  79. # add a button widget and configure with the call back
  80. slider = Slider(start=1, end=10000, value=1, step=5,title="Teff")
  81. slider.on_change('value',callback)
  82. #layout=row(slider,plot)
  83. #show(layout)
  84. # put the button and plot in a layout and add to the document
  85. curdoc().add_root(row(slider, p))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement