import numpy as np from astropy.io import ascii import bokeh.plotting as bk import bokeh.models as mod from collections import OrderedDict import itertools as it #Create a function to calc all colors def colors(dat): colors = ['u','g','r','i','z'] #create an iterable object to make all color combinations run = it.combinations(colors,2) for i in run: dat[i[0]+i[1]] = dat['psfMag_'+i[0]]-dat['psfMag_'+i[1]]-dat['extinction_'+i[0]]+dat['extinction_'+i[1]] #return the table object with the added columns return dat allobjects = ascii.read('Randomfun_jprchlik.csv',delimiter=',',data_start=1,header_start=0) c = 3.*10**5. #km/s #calculate radial velocites allobjects['rv'] = allobjects['z']*c #calcuate colors from sloan data allobjects = colors(allobjects) #Convert to a dictionary to convert to Pandas object indict = {} for i in allobjects.keys(): indict[i] = allobjects[i] #Create Pandas object from dictionary #Wouldnt have to do this if directly read in as a Pandas object source = bk.ColumnDataSource(data=indict) #create a file to put figures bk.output_file('Example_bokeh.html',autosave=True) #list to load in tools which will be used in plots utools = "pan,save,wheel_zoom,box_zoom,box_select,reset,hover,tap" #make a url which calls up data in the object which allows for the clicking of data points #@variable means use the variable information for that data point #e.g. @plate will grap allobjects['plate'][j] where j is the data point being queried urls = 'http://dr12.sdss3.org/spectrumDetail?mjd=@mjd&fiber=@fiberID&plateid=@plate' #What to show when hovering over a data point tooltips = OrderedDict([('(u-g)0','@ug'),('(g-r)0','@gr'),('RV (km/s)','@rv'),('Teff','@elodieTEff'),('log(g)','@elodieLogG'),('[Fe/H]','@elodieFeH')]) #create a figure #tell it what tools to use #Give axis labels and limits p1 = bk.figure(tools=utools,x_axis_label='(g-r)',y_axis_label='(u-g)',x_range=mod.Range1d(start=-.6,end=.6),y_range=mod.Range1d(start=-1,end=1)) #can also be square ect. but creates a scatter plot in figure p1 plot1 = p1.circle('gr','ug',source=source) #grab the hovertool hover1 = p1.select(dict(type=mod.HoverTool))[0] #tell the hovertool what to display hover1.tooltips = tooltips #Grab the taptool which allows for clicking data points tap1 = p1.select(dict(type=mod.TapTool))[0] #Tell the taptool what to do when clicking #it doesnt have to open urls but that is the best #use I can find for it so far tap1.action = mod.OpenURL(url=urls) #repeat for another figure #create a figure p2 = bk.figure(tools=utools,x_axis_label='RV (km/s)',y_axis_label='(u-g)',x_range=mod.Range1d(start=-200,end=200.),y_range=mod.Range1d(start=-1,end=1)) #can also be square ect. but creates a scatter plot in figure p2 plot2 = p2.circle('rv','ug',source=source) #grab the hovertool hover2 = p2.select(dict(type=mod.HoverTool))[0] #tell the hovertool what to display hover2.tooltips = tooltips #Grab the taptool which allows for clicking data points tap2 = p2.select(dict(type=mod.TapTool))[0] #Tell the taptool what to do when clicking #it doesnt have to open urls but that is the best #use I can find for it so far tap2.action = mod.OpenURL(url=urls) #grid the plots nicely together bk.gridplot([[p1,p2]]) #enjoy #append notes on the end of the file #This is not needed except for this example #to link to the data so you can do it yourself addedinfo = """

File to Make this plot


Data for the Plot

""" fz = open('Example_bokeh.html','a') fz.write(addedinfo) fz.close()