コード例 #1
0
ファイル: view.py プロジェクト: leonardokl/grade-ideal
    def exibir(self):
        for i in self.dados.keys():
            if len(self.dados[i]) > 0: continue
            else: return
        defaults.width, defaults.height = 400, 300
        # prepare some data
        # input options
        hist_pontuacao = Histogram(self.dados["pontos"],
                                   title="Grades por pontuação",
                                   xlabel="Pontuação",
                                   ylabel="Número de grades",
                                   responsive=True,
                                   bins=30)

        hist_tamanho = Histogram(self.dados["tamanhos"],
                                 title="Grades por quantidade de disciplinas",
                                 xlabel="Número de disciplinas",
                                 ylabel="Número de grades",
                                 responsive=True,
                                 bins=8)

        hist_pop = Histogram(self.dados["popularidade"],
                             title="Ocorrências da disciplina x",
                             xlabel="Disciplina",
                             ylabel="Ocorrências nas grades",
                             responsive=True,
                             bins=46)

        output_file("html/histograms.html")

        show(hplot(hist_pontuacao, hist_tamanho, hist_pop))
コード例 #2
0
ファイル: view.py プロジェクト: AllanDenis/grade-ideal
	def exibir(self):
		for i in self.dados.keys():
			if len(self.dados[i]) > 0: continue
			else: return
		defaults.width, defaults.height = 400, 300
		# prepare some data
		# input options
		hist_pontuacao = Histogram(self.dados["pontos"],
						title="Grades por pontuação",
						xlabel="Pontuação",
						ylabel="Número de grades",
						responsive=True,
						bins=30)

		hist_tamanho = Histogram(self.dados["tamanhos"],
						title="Grades por quantidade de disciplinas",
						xlabel="Número de disciplinas",
						ylabel="Número de grades",
						responsive=True,
						bins=8)
		
		hist_pop = Histogram(self.dados["popularidade"],
						title="Ocorrências da disciplina x",
						xlabel="Disciplina",
						ylabel="Ocorrências nas grades",
						responsive=True,
						bins=46)
		
		output_file("html/histograms.html")

		show(hplot(	hist_pontuacao,
					hist_tamanho,
					hist_pop
		))		
コード例 #3
0
ファイル: xplorny.py プロジェクト: r-hong/AppXplor
def getDistrib():
        if request.method == 'GET':
                return render_template('distrib.html')
        else:
                bronx=[[2009,'https://data.cityofnewyork.us/resource/en2c-j6tw.json'],[2010,'https://data.cityofnewyork.us/resource/n2s5-fumm.json'],[2011,'https://data.cityofnewyork.us/resource/bawj-6bgn.json'],[2012,'https://data.cityofnewyork.us/resource/3qfc-4tta.json']]
                brooklyn=[[2009,'https://data.cityofnewyork.us/resource/rmv8-86p4.json'],[2010,'https://data.cityofnewyork.us/resource/w6yt-hctp.json'],[2011,'https://data.cityofnewyork.us/resource/5mw2-hzqx.json'],[2012,'https://data.cityofnewyork.us/resource/bss9-579f.json']]
                manhattan=[[2009,'https://data.cityofnewyork.us/resource/956m-xy24.json'],[2010,'https://data.cityofnewyork.us/resource/ad4c-mphb.json'],[2011,'https://data.cityofnewyork.us/resource/ikqj-pyhc.json'],[2012,'https://data.cityofnewyork.us/resource/dvzp-h4k9.json']]
                queens=[[2009,'https://data.cityofnewyork.us/resource/m59i-mqex.json'],[2010,'https://data.cityofnewyork.us/resource/crbs-vur7.json'],[2011,'https://data.cityofnewyork.us/resource/s3zn-tf7c.json'],[2012,'https://data.cityofnewyork.us/resource/jcih-dj9q.json']]
                statenIsland=[[2009,'https://data.cityofnewyork.us/resource/cyfw-hfqk.json'],[2010,'https://data.cityofnewyork.us/resource/wv4q-e75v.json'],[2011,'https://data.cityofnewyork.us/resource/a5qt-5jpu.json'],[2012,'https://data.cityofnewyork.us/resource/tkdy-59zg.json']]
                featureNames=[['comparable_rental_2_market_value_per_sqft',  'Market value per square foot'],['comparable_rental_2_full_market_value',      'Full market value'],['comparable_rental_2_year_built',             'Year Built'],['comparable_rental_2_gross_income_per_sqft', 'Gross income per square foot']]
                #request was a POST (get the var from the form)
		#... All Boroughs are selected by default
                app_xplor.vars['feat'] = request.form['feat']
                app_xplor.vars['year'] = request.form['year']

                #Translating name of the feature into the name in the original database
                dbFeatureName = convertField(app_xplor.vars['feat'],featureNames)

		#Building the queries
		queryA = buildQuery(int(app_xplor.vars['year']),bronx,dbFeatureName)
		queryB = buildQuery(int(app_xplor.vars['year']),brooklyn,dbFeatureName)
		queryC = buildQuery(int(app_xplor.vars['year']),manhattan,dbFeatureName)
		queryD = buildQuery(int(app_xplor.vars['year']),queens,dbFeatureName)
		queryE = buildQuery(int(app_xplor.vars['year']),statenIsland,dbFeatureName)
                #executing the queries on the tables
                rawA = pd.read_json(queryA)
                rawB = pd.read_json(queryB)
                rawC = pd.read_json(queryC)
                rawD = pd.read_json(queryD)
		rawE = pd.read_json(queryE)
		
                #Managind the data to be input for a boxplot 
                rawA['Borough']='Bronx'
                rawB['Borough']='Brooklyn'
                rawC['Borough']='Manhattan'
                rawD['Borough']='Queens'
		rawE['Borough']='Staten Island'
		
                allData = pd.concat([rawA, rawB, rawC, rawD, rawE])
                cleanData= allData.dropna()
                cleanData.columns=[app_xplor.vars['feat'],'Borough']
		
                #plot
                defaults.width = 450
                defaults.height = 350   
                box_plot = BoxPlot(cleanData, label='Borough',title=str(app_xplor.vars['year']))
		#box_plot = BoxPlot(cleanData, label='Borough',title='Year')
                output_file("templates/results.html")
                show(
                    vplot(
                        hplot(box_plot)
                    )
                )
                return redirect('/goDistrib')
コード例 #4
0
ファイル: threshold_scan.py プロジェクト: cgottard/my_fe65
 def analyze(self):
     h5_filename = self.output_filename +'.h5'
     
     with tb.open_file(h5_filename, 'r+') as in_file_h5:
         raw_data = in_file_h5.root.raw_data[:]
         meta_data = in_file_h5.root.meta_data[:]
         
         hit_data = self.dut.interpret_raw_data(raw_data, meta_data)
         in_file_h5.createTable(in_file_h5.root, 'hit_data', hit_data, filters=self.filter_tables)
        
     status_plot = plotting.plot_status(h5_filename)
     occ_plot, H = plotting.plot_occupancy(h5_filename)
     tot_plot,_ = plotting.plot_tot_dist(h5_filename)
     lv1id_plot, _ = plotting.plot_lv1id_dist(h5_filename)
     scan_pix_hist, _ = plotting.scan_pix_hist(h5_filename)                   
              
     output_file(self.output_filename + '.html', title=self.run_name)
     save(vplot(hplot(occ_plot, tot_plot, lv1id_plot), scan_pix_hist, status_plot))
コード例 #5
0
ファイル: histogram_multi.py プロジェクト: chakas/bokeh
from bokeh.charts import Histogram, defaults, vplot, hplot, show, output_file
from bokeh.sampledata.autompg import autompg as df

defaults.width = 450
defaults.height = 350

# input options
hist = Histogram(df["mpg"], title="df['mpg']")
hist2 = Histogram(df, "displ", title="df, 'displ'")
hist3 = Histogram(df, values="hp", title="df, values='hp'")

hist4 = Histogram(df, values="hp", color="cyl", title="df, values='hp', color='cyl'", legend="top_right")

hist5 = Histogram(df, values="mpg", bins=50, title="df, values='mpg', bins=50")

output_file("histogram_multi.html")

show(vplot(hplot(hist, hist2, hist3), hplot(hist4, hist5)))
コード例 #6
0
                          cat=categories,
                          title="All negative input | Grouped",
                          ylabel="Random Number",
                          width=width,
                          height=height)

np_custom = Bar(mixed,
                cat=categories,
                title="Custom range (start=-3, end=0.4)",
                ylabel="Random Number",
                width=width,
                height=height,
                continuous_range=Range1d(start=-3, end=0.4))

np_mixed_grouped = Bar(mixed,
                       cat=categories,
                       title="Mixed-sign input | Grouped",
                       ylabel="Random Number",
                       width=width,
                       height=height)

# collect and display
output_file("bar.html")

show(
    vplot(
        hplot(dict_stacked, df_grouped),
        hplot(np_stacked, np_negative_grouped),
        hplot(np_mixed_grouped, np_custom),
    ))
コード例 #7
0
ファイル: histogram_multi.py プロジェクト: 0-T-0/bokeh
from bokeh.charts import Histogram, defaults, vplot, hplot, show, output_file
from bokeh.sampledata.autompg import autompg as df

defaults.plot_width = 400
defaults.plot_height = 350

# input options
hist  = Histogram(df['mpg'], title="df['mpg']")
hist2 = Histogram(df, 'displ', title="df, 'displ'")
hist3 = Histogram(df, values='hp', title="df, values='hp'")

hist4 = Histogram(df, values='hp', color='cyl',
                  title="df, values='hp', color='cyl'", legend='top_right')

hist5 = Histogram(df, values='mpg', bins=50,
                  title="df, values='mpg', bins=50")

output_file("histogram_multi.html", title="histogram_multi.py example")

show(vplot(
    hplot(hist, hist2),
    hplot(hist3, hist4),
    hplot(hist5)
))
コード例 #8
0
ファイル: timewalk_scan.py プロジェクト: Marrkson/fe65_p2
 def tdc_table(self, scanrange):
     h5_filename = self.output_filename + '.h5'
     with tb.open_file(h5_filename, 'r+') as in_file_h5:
         raw_data = in_file_h5.root.raw_data[:]
         meta_data = in_file_h5.root.meta_data[:]
         if (meta_data.shape[0] == 0): return
         repeat_command = in_file_h5.root.meta_data.attrs.kwargs
         a = repeat_command.rfind("repeat_command: ")
         repeat_command = repeat_command[a + len("repeat_command: "):a + len("repeat_command: ") + 7]
         a = repeat_command.rfind("\n")
         repeat_command = int(repeat_command[0:a])
         param, index = np.unique(meta_data['scan_param_id'], return_index=True)
         pxl_list = []
         for p in param:
             pix_no = int(p) / int(len(self.inj_charge))
             pxl_list.append(self.pixel_list[pix_no][0] * 64 + self.pixel_list[pix_no][1])
         index = index[1:]
         index = np.append(index, meta_data.shape[0])
         index = index - 1
         stops = meta_data['index_stop'][index]
         split = np.split(raw_data, stops)
         avg_tdc = []
         avg_tdc_err = []
         avg_del = []
         avg_del_err = []
         hits = []
         deletelist = ()
         for i in range(len(split[:-1])):  # loop on pulses
             rwa_data_param = split[i]
             tdc_data = rwa_data_param & 0xFFF  # take last 12 bit
             tdc_delay = (rwa_data_param & 0x0FF00000) >> 20
             counter = 0.0
             TOT_sum = 0.0
             DEL_sum = 0.0
             if (tdc_data.shape[0] == 0 or tdc_data.shape[0] == 1):
                 counter = 1.0
             for j in range(tdc_data.shape[0]):  # loop on repeats
                 if (j > 0):
                     counter += 1
                     TOT_sum += tdc_data[j]
                     DEL_sum += tdc_delay[j]
             if (counter > 1):
                 hits.append(counter)
                 avg_tdc.append((float(TOT_sum) / float(counter)) * 1.5625)
                 avg_tdc_err.append(1.5625 / (np.sqrt(12.0 * counter)))
                 avg_del.append((float(DEL_sum) / float(counter)) * 1.5625)
                 avg_del_err.append(1.5625 / (np.sqrt(12.0 * counter)))
             else:
                 deletelist = np.append(deletelist, i)
         pxl_list = np.delete(pxl_list, deletelist)
         newpix = [0]
         pix_no_old = pxl_list[0]
         runparam = 0
         for p in pxl_list:
             if p != pix_no_old:
                 newpix = np.append(newpix, runparam)
             pix_no_old = p
             runparam = runparam + 1
             addedvalues = 0
         for pixels in range(len(newpix)):
             missingvalues = 0
             if newpix[pixels] == newpix[-1]:
                 missingvalues = scanrange - abs(newpix[pixels] + addedvalues - len(hits))
             else:
                 if abs(newpix[pixels] - newpix[pixels + 1]) < scanrange:
                     missingvalues = scanrange - abs(newpix[pixels] - newpix[pixels + 1])
             if missingvalues != 0:
                 hits = np.insert(hits, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 avg_tdc = np.insert(avg_tdc, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 avg_tdc_err = np.insert(avg_tdc_err, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 avg_del = np.insert(avg_del, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 avg_del_err = np.insert(avg_del_err, newpix[pixels] + addedvalues, np.zeros(missingvalues))
                 pxl_list = np.insert(pxl_list, newpix[pixels] + addedvalues,
                                      (pxl_list[newpix[pixels] + addedvalues]) * np.ones(missingvalues))
             addedvalues = addedvalues + missingvalues
         injections = []
         for pixels in range(int(len(pxl_list) / len(self.inj_charge))):
             for i in range(len(self.inj_charge)):
                 injections = np.append(injections, self.inj_charge[i])
         pix, stop = np.unique(pxl_list, return_index=True)
         stop = np.sort(stop)
         stop = list(stop)
         stop.append(len(avg_tdc))
         repeat_command_dic={}
         repeat_command_dic['repeat_command']=repeat_command
         avg_tab = np.rec.fromarrays([injections, pxl_list, hits, avg_tdc, avg_tdc_err, avg_del, avg_del_err],
                                     dtype=[('charge', float), ('pixel_no', int), ('hits', int),
                                            ('tot_ns', float), ('err_tot_ns', float), ('delay_ns', float),
                                            ('err_delay_ns', float)])
         tdc_table=in_file_h5.createTable(in_file_h5.root, 'tdc_data', avg_tab, filters=self.filter_tables)
         tdc_table.attrs.repeat_command = repeat_command_dic
         thresholds = ()
         expfit0 = ()
         expfit1 = ()
         expfit2 = ()
         expfit3 = ()
         pixels = ()
         for i in range(len(stop) - 1):
             s1 = int(stop[i])
             s2 = int(stop[i + 1])
             A, mu, sigma = analysis.fit_scurve(hits[s1:s2], injections[s1:s2],repeat_command)
             if np.max(hits[s1:s2]) > (repeat_command + 200):  # or mu > 3000:
                 thresholds = np.append(thresholds, 0)
                 expfit0 = np.append(expfit0, 0)
                 expfit1 = np.append(expfit1, 0)
                 expfit2 = np.append(expfit2, 0)
                 expfit3 = np.append(expfit3, 0)
                 pixels = np.append(pixels, pxl_list[s1])
                 continue
             for values in range(s1, s2):
                 if injections[values] >= 5 / 4 * mu:
                     s1 = values
                     break
             numberer = 0
             hitvaluesold = hits[-1]
             for hitvalues in hits[s1:s2]:
                 if abs(hitvalues - hitvaluesold) <= 1 and hitvalues != 0:
                     break
                 numberer = numberer + 1
                 hitvaluesold = hitvalues
             if numberer == len(avg_del[s1:s2]):
                 numberer = 0
             expfit = analysis.fit_exp(injections[s1:s2], avg_del[s1:s2], mu, abs(numberer))
             startexp = -expfit[0] * np.log((25.0 + np.min(avg_del[s1:s2]) - expfit[3]) / expfit[2]) - expfit[1]
             if np.isnan(startexp) or startexp >= 2000:
                 startexp = 0
             thresholds = np.append(thresholds, startexp)
             expfit0 = np.append(expfit0, expfit[0])
             expfit1 = np.append(expfit1, expfit[1])
             expfit2 = np.append(expfit2, expfit[2])
             expfit3 = np.append(expfit3, expfit[3])
             pixels = np.append(pixels, pxl_list[s1])
         thresh = np.rec.fromarrays([pixels, thresholds, expfit0, expfit1, expfit2, expfit3],
                                    dtype=[('pixel_no', int), ('td_threshold', float),
                                           ('expfit0', float), ('expfit1', float), ('expfit2', float),
                                           ('expfit3', float)])
         in_file_h5.createTable(in_file_h5.root, 'td_threshold', thresh, filters=self.filter_tables)
     p1, p2, single_scan = plotting.plot_timewalk(h5_filename)
     output_file(self.output_filename + '.html', title=self.run_name)
     status = plotting.plot_status(h5_filename)
     save(hplot(vplot(p1, p2, status), single_scan))
コード例 #9
0
ファイル: bar_multi.py プロジェクト: tommycarpi/py-tracy
                values='displ',
                agg='mean',
                group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')

bar_plot8 = Bar(df,
                label='cyl',
                values='neg_mpg',
                agg='mean',
                group='origin',
                color='origin',
                legend='top_right',
                title="label='cyl' values='neg_mpg' agg='mean' group='origin'")

# infer labels from index
df = df.set_index('cyl')
bar_plot9 = Bar(df,
                values='mpg',
                agg='mean',
                legend='top_right',
                title='inferred labels')

# collect and display
output_file("bar_multi.html")

show(
    vplot(hplot(bar_plot, bar_plot2, bar_plot3),
          hplot(bar_plot4, bar_plot5, bar_plot6),
          hplot(bar_plot7, bar_plot8, bar_plot9)))
コード例 #10
0
ファイル: boxplot_multi.py プロジェクト: tommycarpi/py-tracy
                    title="label='cyl' color='blue'",
                    color='blue')

# color by one dimension and label by two dimensions
box_plot5 = BoxPlot(df, label=['cyl', 'origin'], values='mpg',
                    title="label=['cyl', 'origin'] color='cyl'",
                    color='cyl')

# specify custom marker for outliers
box_plot6 = BoxPlot(df, label='cyl', values='mpg', marker='cross',
                    title="label='cyl', values='mpg', marker='cross'")

# color whisker by cylinder
box_plot7 = BoxPlot(df, label='cyl', values='mpg', whisker_color='cyl',
                    title="label='cyl', values='mpg', whisker_color='cyl'")

# remove outliers
box_plot8 = BoxPlot(df, label='cyl', values='mpg', outliers=False,
                    title="label='cyl', values='mpg', outliers=False")

# collect and display
output_file("boxplot_multi.html")

show(
    vplot(
        hplot(box_plot, box_plot2, box_plot3),
        hplot(box_plot4, box_plot5, box_plot6),
        hplot(box_plot7, box_plot8)
    )
)
コード例 #11
0
ファイル: p3.py プロジェクト: RaquelFigueroa/project3
ch1TotalSubscribers = channel1_data["total_subscribers"]
ch2TotalSubscribers = channel2_data["total_subscribers"]

# Data to be used for graphone ordered into groups
data = {
    'Numbers': ['Dislikes', 'Likes', 'Subscribers', 'Total Views', 'Dislikes', 'Likes', 'Subscribers', 'Total Views'],
    'Channels': [ch1, ch1, ch1, ch1, ch2, ch2, ch2, ch2],
    'Total': [ch1TotalDislikes, ch1TotalLikes, ch1TotalSubscribers, ch1TotalViews, ch2TotalDislikes, ch2TotalLikes, ch2TotalSubscribers, ch2TotalViews]   
}

# Puts all the data into a format which may be graphed with correct parameters:
bar = Bar(data, values='Total', label=['Channels', 'Numbers'],agg = 'sum',
           title="Comparing two Youtube Channels", width=500, height = 1000,
           group = 'Numbers', tools=['hover', 'resize', 'box_zoom', 'wheel_zoom', 'pan'])

# Allows the hover tool to function:
hover = bar.select(dict(type=HoverTool))
hover.tooltips = [('Value of Channel',' $x'),('Value of Total',' @height')]

# outputs a file with the data for the graph:
output_file("stacked_bar.html")

# Shows the graph:
show(hplot(bar))
#
#End of graphing functions code!
#**************************************************************************************

print(channel1_data)
print(channel2_data)
コード例 #12
0
ファイル: p3.py プロジェクト: StevenGroves/project3
def robots():
	

	def choose_channel():
		channel_name = raw_input('Enter a channel name: ')
		return channel_name

	def retrieve_links(name_of_channel):
		
		root_url = "https://www.youtube.com"
		url = urllib2.urlopen("https://www.youtube.com/user/" + name_of_channel + "/videos")

		content = url.read()

		soup = BeautifulSoup(content, "html.parser")
		list_of_links = []

		#searches for all 'a' tags that have "/watch" in them.
		for elem in soup.find_all('a', href=re.compile('/watch')):
			list_of_links.append(root_url + elem['href'])

		#This loop gets rid of duplicate links
		i = 0
		while i < len(list_of_links):
		   if list_of_links[i] == list_of_links[i+1]:
		       list_of_links.remove(list_of_links[i])
		       i += 1

		#print("Links for the %d most recent videos:" % len(list_of_links))

		#for x in range(len(list_of_links)):
			#print(list_of_links[x])

		return list_of_links


	#This function will go to each link and scrape data of subscribers, views, likes and dislikes
	def get_data(list_of_links = []):
		
		data = {}
		data['total_views'] = 0
		data['total_likes'] = 0
		data['total_dislikes'] = 0
		data['total_subscribers'] = 0
		

	 	for x in range(len(list_of_links)):

	 		url = urllib2.urlopen(list_of_links[x])
	 		link_content = url.read()
	 		link_soup = BeautifulSoup(link_content, "html.parser")

	 		#print("Video number: %d" % (x+1))
	 		views = link_soup.find('div', {'class' : 'watch-view-count'})
	 		views = views.get_text()
	 		views = views.replace(",", "")
	 		views = views.replace(" views", "")
	 		data['total_views'] += int(views)
	 		#print("%s views" % views)

	 		likes = link_soup.find('button', {'class' : "yt-uix-button yt-uix-button-size-default yt-uix-button-opacity yt-uix-button-has-icon no-icon-markup like-button-renderer-like-button like-button-renderer-like-button-unclicked yt-uix-clickcard-target   yt-uix-tooltip"})
	 		likes = likes.get_text()
	 		likes = likes.replace(",", "")
	 		data['total_likes'] += int(likes)
	 		#print("%s likes" % likes)

	 		dislikes = link_soup.find('button', {'class' : "yt-uix-button yt-uix-button-size-default yt-uix-button-opacity yt-uix-button-has-icon no-icon-markup like-button-renderer-dislike-button like-button-renderer-dislike-button-unclicked yt-uix-clickcard-target   yt-uix-tooltip"})
	 		dislikes = dislikes.get_text()
	 		dislikes = dislikes.replace(",", "")
	 		data['total_dislikes'] += int(dislikes)
	 		#print("%s dislikes" % dislikes)
	 		#print(" ")
	 	
		subscribers = link_soup.find('span', {'class' : "yt-subscription-button-subscriber-count-branded-horizontal yt-subscriber-count"})
		subscribers = subscribers.get_text()
		subscribers = subscribers.replace(",", "")
		data['total_subscribers'] = int(subscribers)

		return data

	name1 = request.args['example']
	name2 = request.args['example2']

	ch1 = name1
	ch2 = name2

	channel1 = retrieve_links(ch1)
	channel2 = retrieve_links(ch2)

	channel1_data = get_data(channel1)
	channel2_data = get_data(channel2)

	#*************************************************************************************************
	#Graphing functions added here:

	# Puts integer values into variables to be used in bokeh graphing:
	ch1TotalViews = channel1_data["total_views"]
	ch2TotalViews = channel2_data["total_views"]

	ch1TotalLikes = channel1_data["total_likes"]
	ch2TotalLikes = channel2_data["total_likes"]

	ch1TotalDislikes = channel1_data["total_dislikes"]
	ch2TotalDislikes = channel2_data["total_dislikes"]

	ch1TotalSubscribers = channel1_data["total_subscribers"]
	ch2TotalSubscribers = channel2_data["total_subscribers"]

	# Data to be used for graphone ordered into groups
	data = {
	    'Numbers': ['Dislikes', 'Likes', 'Subscribers', 'Total Views', 'Dislikes', 'Likes', 'Subscribers', 'Total Views'],
	    'Channels': [ch1, ch1, ch1, ch1, ch2, ch2, ch2, ch2],
	    'Total': [ch1TotalDislikes, ch1TotalLikes, ch1TotalSubscribers, ch1TotalViews, ch2TotalDislikes, ch2TotalLikes, ch2TotalSubscribers, ch2TotalViews]   
	}

	# Puts all the data into a format which may be graphed with correct parameters:
	bar = Bar(data, values='Total', label=['Channels', 'Numbers'],agg = 'sum',
	           title="Comparing two Youtube Channels", width=500, height = 1000,
	           group = 'Numbers', tools=['hover', 'resize', 'box_zoom', 'wheel_zoom', 'pan'])

	# Allows the hover tool to function:
	hover = bar.select(dict(type=HoverTool))
	hover.tooltips = [('Value of Channel',' $x'),('Value of Total',' @height')]

	# outputs a file with the data for the graph:
	output_file("stacked_bar.html")

	# Shows the graph:
	show(hplot(bar))
	#
	#End of graphing functions code!
	#**************************************************************************************

	return render_template("resultsPage.html")
コード例 #13
0
ファイル: dots_multi.py プロジェクト: 0-T-0/bokeh
# multiple columns
dot_plot5 = Dot(df, label=['cyl', 'origin'], values='mpg', agg='mean',
                title="label=['cyl', 'origin'] values='mpg' agg='mean'")

dot_plot6 = Dot(df, label='origin', values='mpg', agg='mean', stack='cyl',
                title="label='origin' values='mpg' agg='mean' stack='cyl'",
                legend='top_right')

dot_plot7 = Dot(df, label='cyl', values='displ', agg='mean', group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')

dot_plot8 = Dot(df, label='cyl', values='neg_mpg', agg='mean', group='origin',
                color='origin', legend='top_right',
                title="label='cyl' values='neg_mpg' agg='mean' group='origin'")
dot_plot8.title_text_font_size = '11pt'

# infer labels from index
df = df.set_index('cyl')
dot_plot9 = Dot(df, values='mpg', agg='mean', legend='top_right', title='inferred labels')

output_file("dots_multi.html", title="dots_multi.py example")

show(vplot(
    hplot(dot_plot, dot_plot2),
    hplot(dot_plot3, dot_plot4),
    hplot(dot_plot5, dot_plot6),
    hplot(dot_plot7, dot_plot8),
    hplot(dot_plot9)
))
コード例 #14
0
ファイル: timewalk_scan.py プロジェクト: Marrkson/fe65_p2
 def tdc_table(self, scanrange):
     h5_filename = self.output_filename + '.h5'
     with tb.open_file(h5_filename, 'r+') as in_file_h5:
         raw_data = in_file_h5.root.raw_data[:]
         meta_data = in_file_h5.root.meta_data[:]
         if (meta_data.shape[0] == 0): return
         repeat_command = in_file_h5.root.meta_data.attrs.kwargs
         a = repeat_command.rfind("repeat_command: ")
         repeat_command = repeat_command[a + len("repeat_command: "):a +
                                         len("repeat_command: ") + 7]
         a = repeat_command.rfind("\n")
         repeat_command = int(repeat_command[0:a])
         param, index = np.unique(meta_data['scan_param_id'],
                                  return_index=True)
         pxl_list = []
         for p in param:
             pix_no = int(p) / int(len(self.inj_charge))
             pxl_list.append(self.pixel_list[pix_no][0] * 64 +
                             self.pixel_list[pix_no][1])
         index = index[1:]
         index = np.append(index, meta_data.shape[0])
         index = index - 1
         stops = meta_data['index_stop'][index]
         split = np.split(raw_data, stops)
         avg_tdc = []
         avg_tdc_err = []
         avg_del = []
         avg_del_err = []
         hits = []
         deletelist = ()
         for i in range(len(split[:-1])):  # loop on pulses
             rwa_data_param = split[i]
             tdc_data = rwa_data_param & 0xFFF  # take last 12 bit
             tdc_delay = (rwa_data_param & 0x0FF00000) >> 20
             counter = 0.0
             TOT_sum = 0.0
             DEL_sum = 0.0
             if (tdc_data.shape[0] == 0 or tdc_data.shape[0] == 1):
                 counter = 1.0
             for j in range(tdc_data.shape[0]):  # loop on repeats
                 if (j > 0):
                     counter += 1
                     TOT_sum += tdc_data[j]
                     DEL_sum += tdc_delay[j]
             if (counter > 1):
                 hits.append(counter)
                 avg_tdc.append((float(TOT_sum) / float(counter)) * 1.5625)
                 avg_tdc_err.append(1.5625 / (np.sqrt(12.0 * counter)))
                 avg_del.append((float(DEL_sum) / float(counter)) * 1.5625)
                 avg_del_err.append(1.5625 / (np.sqrt(12.0 * counter)))
             else:
                 deletelist = np.append(deletelist, i)
         pxl_list = np.delete(pxl_list, deletelist)
         newpix = [0]
         pix_no_old = pxl_list[0]
         runparam = 0
         for p in pxl_list:
             if p != pix_no_old:
                 newpix = np.append(newpix, runparam)
             pix_no_old = p
             runparam = runparam + 1
             addedvalues = 0
         for pixels in range(len(newpix)):
             missingvalues = 0
             if newpix[pixels] == newpix[-1]:
                 missingvalues = scanrange - abs(newpix[pixels] +
                                                 addedvalues - len(hits))
             else:
                 if abs(newpix[pixels] - newpix[pixels + 1]) < scanrange:
                     missingvalues = scanrange - abs(newpix[pixels] -
                                                     newpix[pixels + 1])
             if missingvalues != 0:
                 hits = np.insert(hits, newpix[pixels] + addedvalues,
                                  np.zeros(missingvalues))
                 avg_tdc = np.insert(avg_tdc, newpix[pixels] + addedvalues,
                                     np.zeros(missingvalues))
                 avg_tdc_err = np.insert(avg_tdc_err,
                                         newpix[pixels] + addedvalues,
                                         np.zeros(missingvalues))
                 avg_del = np.insert(avg_del, newpix[pixels] + addedvalues,
                                     np.zeros(missingvalues))
                 avg_del_err = np.insert(avg_del_err,
                                         newpix[pixels] + addedvalues,
                                         np.zeros(missingvalues))
                 pxl_list = np.insert(
                     pxl_list, newpix[pixels] + addedvalues,
                     (pxl_list[newpix[pixels] + addedvalues]) *
                     np.ones(missingvalues))
             addedvalues = addedvalues + missingvalues
         injections = []
         for pixels in range(int(len(pxl_list) / len(self.inj_charge))):
             for i in range(len(self.inj_charge)):
                 injections = np.append(injections, self.inj_charge[i])
         pix, stop = np.unique(pxl_list, return_index=True)
         stop = np.sort(stop)
         stop = list(stop)
         stop.append(len(avg_tdc))
         repeat_command_dic = {}
         repeat_command_dic['repeat_command'] = repeat_command
         avg_tab = np.rec.fromarrays([
             injections, pxl_list, hits, avg_tdc, avg_tdc_err, avg_del,
             avg_del_err
         ],
                                     dtype=[('charge', float),
                                            ('pixel_no', int),
                                            ('hits', int),
                                            ('tot_ns', float),
                                            ('err_tot_ns', float),
                                            ('delay_ns', float),
                                            ('err_delay_ns', float)])
         tdc_table = in_file_h5.createTable(in_file_h5.root,
                                            'tdc_data',
                                            avg_tab,
                                            filters=self.filter_tables)
         tdc_table.attrs.repeat_command = repeat_command_dic
         thresholds = ()
         expfit0 = ()
         expfit1 = ()
         expfit2 = ()
         expfit3 = ()
         pixels = ()
         for i in range(len(stop) - 1):
             s1 = int(stop[i])
             s2 = int(stop[i + 1])
             A, mu, sigma = analysis.fit_scurve(hits[s1:s2],
                                                injections[s1:s2],
                                                repeat_command)
             if np.max(
                     hits[s1:s2]) > (repeat_command + 200):  # or mu > 3000:
                 thresholds = np.append(thresholds, 0)
                 expfit0 = np.append(expfit0, 0)
                 expfit1 = np.append(expfit1, 0)
                 expfit2 = np.append(expfit2, 0)
                 expfit3 = np.append(expfit3, 0)
                 pixels = np.append(pixels, pxl_list[s1])
                 continue
             for values in range(s1, s2):
                 if injections[values] >= 5 / 4 * mu:
                     s1 = values
                     break
             numberer = 0
             hitvaluesold = hits[-1]
             for hitvalues in hits[s1:s2]:
                 if abs(hitvalues - hitvaluesold) <= 1 and hitvalues != 0:
                     break
                 numberer = numberer + 1
                 hitvaluesold = hitvalues
             if numberer == len(avg_del[s1:s2]):
                 numberer = 0
             expfit = analysis.fit_exp(injections[s1:s2], avg_del[s1:s2],
                                       mu, abs(numberer))
             startexp = -expfit[0] * np.log(
                 (25.0 + np.min(avg_del[s1:s2]) - expfit[3]) /
                 expfit[2]) - expfit[1]
             if np.isnan(startexp) or startexp >= 2000:
                 startexp = 0
             thresholds = np.append(thresholds, startexp)
             expfit0 = np.append(expfit0, expfit[0])
             expfit1 = np.append(expfit1, expfit[1])
             expfit2 = np.append(expfit2, expfit[2])
             expfit3 = np.append(expfit3, expfit[3])
             pixels = np.append(pixels, pxl_list[s1])
         thresh = np.rec.fromarrays(
             [pixels, thresholds, expfit0, expfit1, expfit2, expfit3],
             dtype=[('pixel_no', int), ('td_threshold', float),
                    ('expfit0', float), ('expfit1', float),
                    ('expfit2', float), ('expfit3', float)])
         in_file_h5.createTable(in_file_h5.root,
                                'td_threshold',
                                thresh,
                                filters=self.filter_tables)
     p1, p2, single_scan = plotting.plot_timewalk(h5_filename)
     output_file(self.output_filename + '.html', title=self.run_name)
     status = plotting.plot_status(h5_filename)
     save(hplot(vplot(p1, p2, status), single_scan))
コード例 #15
0
ファイル: bar_multi.py プロジェクト: chakas/bokeh
bar_plot4 = Bar(df, label='cyl', title="label='cyl' color='DimGray'", color='dimgray')

# multiple columns
bar_plot5 = Bar(df, label=['cyl', 'origin'], values='mpg', agg='mean',
                title="label=['cyl', 'origin'] values='mpg' agg='mean'")

bar_plot6 = Bar(df, label='origin', values='mpg', agg='mean', stack='cyl',
                title="label='origin' values='mpg' agg='mean' stack='cyl'",
                legend='top_right')

bar_plot7 = Bar(df, label='cyl', values='displ', agg='mean', group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')

bar_plot8 = Bar(df, label='cyl', values='neg_mpg', agg='mean', group='origin',
                color='origin', legend='top_right',
                title="label='cyl' values='neg_mpg' agg='mean' group='origin'")

# infer labels from index
df = df.set_index('cyl')
bar_plot9 = Bar(df, values='mpg', agg='mean', legend='top_right', title='inferred labels')

output_file("bar_multi.html")

show(vplot(
    hplot(bar_plot,  bar_plot2, bar_plot3),
    hplot(bar_plot4, bar_plot5, bar_plot6),
    hplot(bar_plot7, bar_plot8, bar_plot9)
))
コード例 #16
0
ファイル: dots_multi.py プロジェクト: numpand/bokeh
                label='cyl',
                values='displ',
                agg='mean',
                group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')

dot_plot8 = Dot(df,
                label='cyl',
                values='neg_mpg',
                agg='mean',
                group='origin',
                color='origin',
                legend='top_right',
                title="label='cyl' values='neg_mpg' agg='mean' group='origin'")

# infer labels from index
df = df.set_index('cyl')
dot_plot9 = Dot(df,
                values='mpg',
                agg='mean',
                legend='top_right',
                title='inferred labels')

output_file("dots_multi.html")

show(
    vplot(hplot(dot_plot, dot_plot2, dot_plot3),
          hplot(dot_plot4, dot_plot5, dot_plot6),
          hplot(dot_plot7, dot_plot8, dot_plot9)))
コード例 #17
0
ファイル: dots_multi.py プロジェクト: chakas/bokeh
dot_plot4 = Dot(df, label='cyl', title="label='cyl' color='DimGray'", color='dimgray')

# multiple columns
dot_plot5 = Dot(df, label=['cyl', 'origin'], values='mpg', agg='mean',
                title="label=['cyl', 'origin'] values='mpg' agg='mean'")

dot_plot6 = Dot(df, label='origin', values='mpg', agg='mean', stack='cyl',
                title="label='origin' values='mpg' agg='mean' stack='cyl'",
                legend='top_right')

dot_plot7 = Dot(df, label='cyl', values='displ', agg='mean', group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')

dot_plot8 = Dot(df, label='cyl', values='neg_mpg', agg='mean', group='origin',
                color='origin', legend='top_right',
                title="label='cyl' values='neg_mpg' agg='mean' group='origin'")

# infer labels from index
df = df.set_index('cyl')
dot_plot9 = Dot(df, values='mpg', agg='mean', legend='top_right', title='inferred labels')

output_file("dots_multi.html")

show(vplot(
    hplot(dot_plot, dot_plot2, dot_plot3),
    hplot(dot_plot4, dot_plot5, dot_plot6),
    hplot(dot_plot7, dot_plot8, dot_plot9)
))
コード例 #18
0
                values='mpg',
                agg='mean',
                title="label=['cyl', 'origin'] values='mpg' agg='mean'")

bar_plot6 = Bar(df,
                label='origin',
                values='mpg',
                agg='mean',
                stack='cyl',
                title="label='origin' values='mpg' agg='mean' stack='cyl'",
                legend='top_right')

bar_plot7 = Bar(df,
                label='cyl',
                values='displ',
                agg='mean',
                group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')

# ToDo: negative values
# bar_plot8 = Bar(df, label='cyl', values='neg_displ', agg='mean', group='origin', color='origin',
#                 title="label='cyl' values='displ' agg='mean' group='origin'", legend='top_right')

# collect and display
output_file("bar.html")

show(
    vplot(hplot(bar_plot, bar_plot2, bar_plot3),
          hplot(bar_plot4, bar_plot5, bar_plot6), hplot(bar_plot7)))
コード例 #19
0
ファイル: bar_multi.py プロジェクト: timopek/bokeh
                group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')
bar_plot7.title_text_font_size = '10pt'

bar_plot8 = Bar(df,
                label='cyl',
                values='neg_mpg',
                agg='mean',
                group='origin',
                color='origin',
                legend='top_right',
                title="label='cyl' values='neg_mpg' agg='mean' group='origin'")
bar_plot8.title_text_font_size = '9pt'

# infer labels from index
df = df.set_index('cyl')
bar_plot9 = Bar(df,
                values='mpg',
                agg='mean',
                legend='top_right',
                title='inferred labels')
bar_plot9.title_text_font_size = '10pt'

output_file("bar_multi.html", title="bar_multi.py example")

show(
    vplot(hplot(bar_plot, bar_plot2), hplot(bar_plot3, bar_plot4),
          hplot(bar_plot5, bar_plot6), hplot(bar_plot7, bar_plot8),
          hplot(bar_plot9)))
コード例 #20
0
# specify custom marker for outliers
box_plot6 = BoxPlot(df,
                    label='cyl',
                    values='mpg',
                    marker='cross',
                    title="label='cyl', values='mpg', marker='cross'")

# color whisker by cylinder
box_plot7 = BoxPlot(df,
                    label='cyl',
                    values='mpg',
                    whisker_color='cyl',
                    title="label='cyl', values='mpg', whisker_color='cyl'")

# remove outliers
box_plot8 = BoxPlot(
    df,
    label='cyl',
    values='mpg',
    outliers=False,
    title="label='cyl', values='mpg', outliers=False, tooltips=True",
    tooltips=True)
box_plot8.title_text_font_size = '11pt'

output_file("boxplot_multi.html", title="boxplot_multi.py example")

show(
    vplot(hplot(box_plot, box_plot2), hplot(box_plot3, box_plot4),
          hplot(box_plot5, box_plot6), hplot(box_plot7, box_plot8)))
コード例 #21
0
ファイル: plotting.py プロジェクト: Marrkson/fe65_p2
def scan_pix_hist(h5_file_name, scurve_sel_pix=200):
    with tb.open_file(h5_file_name, 'r') as in_file_h5:
        meta_data = in_file_h5.root.meta_data[:]
        hit_data = in_file_h5.root.hit_data[:]
        en_mask = in_file_h5.root.scan_results.en_mask[:]
        Noise_gauss = in_file_h5.root.Noise_results.Noise_pure.attrs.fitdata_noise
        Noise_pure = in_file_h5.root.Noise_results.Noise_pure[:]
        Thresh_gauss = in_file_h5.root.Thresh_results.Threshold_pure.attrs.fitdata_thresh
        Threshold_pure = in_file_h5.root.Thresh_results.Threshold_pure[:]
        scan_args = yaml.load(in_file_h5.root.meta_data.attrs.kwargs)
        scan_range = scan_args['scan_range']
        scan_range_inx = np.arange(scan_range[0], scan_range[1], scan_range[2])

        # np.set_printoptions(threshold=np.nan)
        param = np.unique(meta_data['scan_param_id'])
        ret = []
        for i in param:
            wh = np.where(hit_data['scan_param_id'] == i)  # this can be faster and multi threaded
            hd = hit_data[wh[0]]
            hits = hd['col'].astype(np.uint16)
            hits = hits * 64
            hits = hits + hd['row']
            value = np.bincount(hits)
            value = np.pad(value, (0, 64 * 64 - value.shape[0]), 'constant')
            if len(ret):
                ret = np.vstack((ret, value))
            else:
                ret = value
        repeat_command = max(ret[-3])
        shape = en_mask.shape
        ges = 1
        for i in range(2):
            ges = ges * shape[i]
        ret_pure = ()
        en_mask = en_mask.reshape(ges)
        for n in range(param[-1]):
            ret_pure1 = ()
            for i in range(ges):
                if (str(en_mask[i]) == 'True'):
                    ret_pure1 = np.append(ret_pure1, ret[n][i])
            if n == 0:
                ret_pure = ret_pure1
                continue
            ret_pure = np.vstack((ret_pure, ret_pure1))

        ret_pure = ret_pure.astype(int)
        s_hist = np.swapaxes(ret_pure, 0, 1)

        pix_scan_hist = np.empty((s_hist.shape[1], repeat_command + 10))
        for param in range(s_hist.shape[1]):
            h_count = np.bincount(s_hist[:, param])
            h_count = h_count[:repeat_command + 10]
            pix_scan_hist[param] = np.pad(h_count, (0, (repeat_command + 10) - h_count.shape[0]), 'constant')

        log_hist = np.log10(pix_scan_hist)
        log_hist[~np.isfinite(log_hist)] = 0
        data = {
            'scan_param': np.ravel(np.indices(pix_scan_hist.shape)[0]),
            'count': np.ravel(np.indices(pix_scan_hist.shape)[1]),
            'value': np.ravel(log_hist)
        }

        x = scan_range_inx
        px = scurve_sel_pix  # 1110 #1539
        single_scan = figure(title="Single pixel scan " + str(px), x_axis_label="Injection[V]", y_axis_label="Hits")
        single_scan.diamond(x=x, y=s_hist[px], size=5, color="#1C9099", line_width=2)
        yf = analysis.scurve(x, 100, Threshold_pure[px], Noise_pure[px])
        single_scan.cross(x=x, y=yf, size=5, color="#E6550D", line_width=2)

        hist, edges = np.histogram(Threshold_pure, density=False, bins=50)#50

        hm1 = HeatMap(data, x='scan_param', y='count', values='value', title='Threshold Heatmap',
                      palette=Spectral11[::-1], stat=None, plot_width=1000)  # , height=4100)
        hm1.extra_x_ranges = {
            "e": Range1d(start=edges[0] * 1000 * analysis.cap_fac(), end=edges[-1] * 1000 * analysis.cap_fac())}

        hm_th = figure(title="Threshold", x_axis_label="pixel #", y_axis_label="threshold [V]",
                       y_range=(scan_range_inx[0], scan_range_inx[-1]), plot_width=1000)
        hm_th.diamond(y=Threshold_pure, x=range(64 * 64), size=1, color="#1C9099", line_width=2)
        hm_th.extra_y_ranges = {"e": Range1d(start=scan_range_inx[0] * 1000 * analysis.cap_fac(),
                                             end=scan_range_inx[-1] * 1000 * analysis.cap_fac())}
        hm_th.add_layout(LinearAxis(y_range_name="e"), 'right')
        plt_th_dist = figure(title='Threshold Distribution ', x_axis_label="threshold [V]", y_axis_label="#Pixel",
                             y_range=(0, 1.1 * np.max(hist[1:])))
        plt_th_dist.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564",
                         line_color="#033649",
                         legend="# {0:d}  mean={1:.2f}  std={2:.2f}".format(int(np.sum(hist[:])), round(
                             Thresh_gauss['mu'] * 1000 * analysis.cap_fac(), 4),
                                                                            round(Thresh_gauss[
                                                                                      'sigma'] * 1000 * analysis.cap_fac(),
                                                                                  4)))
        plt_th_dist.extra_x_ranges = {"e": Range1d(start=edges[0] * 1000 * analysis.cap_fac(),
                                                   end=edges[-1] * 1000 * analysis.cap_fac())}  # better 7.4?
        plt_th_dist.add_layout(LinearAxis(x_range_name="e"), 'above')
        plt_th_dist.line(np.arange(edges[1], edges[-1], 0.0001),
                         analysis.gauss(np.arange(edges[1], edges[-1], 0.0001), Thresh_gauss['height'],
                                        Thresh_gauss['mu'], Thresh_gauss['sigma']), line_color="#D95B43", line_width=8,
                         alpha=0.7)

        hist, edges = np.histogram(Noise_pure, density=False, bins=50) #50
        hm_noise = figure(title="Noise", x_axis_label="pixel #", y_axis_label="noise [V]", y_range=(0, edges[-1]),
                          plot_width=1000)
        hm_noise.diamond(y=Noise_pure, x=range(64 * 64), size=2, color="#1C9099", line_width=2)
        hm_noise.extra_y_ranges = {"e": Range1d(start=0, end=edges[-1] * 1000 * analysis.cap_fac())}  # default 7.6
        hm_noise.add_layout(LinearAxis(y_range_name="e"), 'right')

        plt_noise_dist = figure(title='Noise Distribution ', x_axis_label="noise [V]", y_axis_label="#Pixel",
                                y_range=(0, 1.1 * np.max(hist[1:])))
        plt_noise_dist.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564",
                            line_color="#033649",
                            legend="# {0:d}  mean={1:.2f}  std={2:.2f}".format(int(np.sum(hist[:])), round(
                                Noise_gauss['mu'] * 1000 * analysis.cap_fac(), 4), round(
                                Noise_gauss['sigma'] * 1000 * analysis.cap_fac(), 4)))
        plt_noise_dist.extra_x_ranges = {
            "e": Range1d(start=edges[0] * 1000 * analysis.cap_fac(), end=edges[-1] * 1000 * analysis.cap_fac())}
        plt_noise_dist.add_layout(LinearAxis(x_range_name="e"), 'above')
        plt_noise_dist.line(np.arange(edges[0], edges[-1], 0.0001),
                            analysis.gauss(np.arange(edges[0], edges[-1], 0.0001), Noise_gauss['height'],
                                           Noise_gauss['mu'], Noise_gauss['sigma']), line_color="#D95B43", line_width=8,
                            alpha=0.7)

        return vplot(hplot(hm_th, plt_th_dist), hplot(hm_noise, plt_noise_dist), hplot(hm1, single_scan)), s_hist
コード例 #22
0
ファイル: boxplot_multi.py プロジェクト: 280185386/bokeh
                    title="label='cyl' color='blue'",
                    color='blue')

# color by one dimension and label by two dimensions
box_plot5 = BoxPlot(df, label=['cyl', 'origin'], values='mpg',
                    title="label=['cyl', 'origin'] color='cyl'",
                    color='cyl')

# specify custom marker for outliers
box_plot6 = BoxPlot(df, label='cyl', values='mpg', marker='cross',
                    title="label='cyl', values='mpg', marker='cross'")

# color whisker by cylinder
box_plot7 = BoxPlot(df, label='cyl', values='mpg', whisker_color='cyl',
                    title="label='cyl', values='mpg', whisker_color='cyl'")

# remove outliers
box_plot8 = BoxPlot(df, label='cyl', values='mpg', outliers=False,
                    title="label='cyl', values='mpg', outliers=False, tooltips=True",
                    tooltips=True)
box_plot8.title_text_font_size = '11pt'

output_file("boxplot_multi.html", title="boxplot_multi.py example")

show(vplot(
    hplot(box_plot, box_plot2),
    hplot(box_plot3, box_plot4),
    hplot(box_plot5, box_plot6),
    hplot(box_plot7, box_plot8)
) )
コード例 #23
0
scatter4 = Scatter(
    df, x='mpg', y='hp', color='cyl', marker='origin', title="x='mpg', y='hp', color='cyl', marker='origin'",
    xlabel="Miles Per Gallon", ylabel="Horsepower", legend='top_right')

# Example with nested json/dict like data, which has been pre-aggregated and pivoted
df2 = df_from_json(data)
df2 = df2.sort('total', ascending=False)

df2 = df2.head(10)
df2 = pd.melt(df2, id_vars=['abbr', 'name'])

scatter5 = Scatter(
    df2, x='value', y='name', color='variable', title="x='value', y='name', color='variable'",
    xlabel="Medals", ylabel="Top 10 Countries", legend='bottom_right')


scatter6 = Scatter(flowers, x=blend('petal_length', 'sepal_length', name='length'),
                   y=blend('petal_width', 'sepal_width', name='width'), color='species',
                   title='x=petal_length+sepal_length, y=petal_width+sepal_width, color=species',
                   legend='top_right')

output_file("scatter_multi.html")

show(vplot(
    hplot(scatter0, scatter1),
    hplot(scatter2, scatter3),
    hplot(scatter4, scatter5),
    hplot(scatter6)
))
コード例 #24
0
ファイル: thesisplots.py プロジェクト: Marrkson/fe65_p2
def single_timewalk_plot(h5_filename):
    output_file('/home/mark/Desktop/Stuff/single.html')
    p1, p2, single_scan = plot_timewalk2(h5_filename)
    save(hplot(vplot(p1, p2), single_scan))
コード例 #25
0
ファイル: scatter_multi.py プロジェクト: benjamin0/bokeh
    xlabel="Miles Per Gallon", ylabel="Horsepower", legend='top_right')

scatter4 = Scatter(
    df, x='mpg', y='hp', color='cyl', marker='origin', title="x='mpg', y='hp', color='cyl', marker='origin'",
    xlabel="Miles Per Gallon", ylabel="Horsepower", legend='top_right')

# Example with nested json/dict like data, which has been pre-aggregated and pivoted
df2 = df_from_json(data)
df2 = df2.sort('medals.total', ascending=False)
df2 = df2.head(10)
df2 = pd.melt(df2, id_vars=['abbr', 'name'])

scatter5 = Scatter(
    df2, x='value', y='name', color='variable', title="x='value', y='name', color='variable'",
    xlabel="Medals", ylabel="Top 10 Countries", legend='bottom_right')


scatter6 = Scatter(flowers, x=blend('petal_length', 'sepal_length', name='length'),
                   y=blend('petal_width', 'sepal_width', name='width'), color='species',
                   title='x=petal_length+sepal_length, y=petal_width+sepal_width, color=species',
                   legend='top_right')

output_file("scatter_multi.html")

show(vplot(
    hplot(scatter0, scatter1),
    hplot(scatter2, scatter3),
    hplot(scatter4, scatter5),
    hplot(scatter6)
))
コード例 #26
0
ファイル: bar.py プロジェクト: nkhuyu/bokeh
bar_plot3 = Bar(df, label='cyl', values='mpg', agg='mean',
                title="label='cyl' values='mpg' agg='mean'")

bar_plot4 = Bar(df, label='cyl', title="label='cyl' color='DimGray'", color='dimgray')

# multiple columns
bar_plot5 = Bar(df, label=['cyl', 'origin'], values='mpg', agg='mean',
                title="label=['cyl', 'origin'] values='mpg' agg='mean'")

bar_plot6 = Bar(df, label='origin', values='mpg', agg='mean', stack='cyl',
                title="label='origin' values='mpg' agg='mean' stack='cyl'", legend='top_right')

bar_plot7 = Bar(df, label='cyl', values='displ', agg='mean', group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'", legend='top_right')

# ToDo: negative values
# bar_plot8 = Bar(df, label='cyl', values='neg_displ', agg='mean', group='origin', color='origin',
#                 title="label='cyl' values='displ' agg='mean' group='origin'", legend='top_right')


# collect and display
output_file("bar.html")

show(
    vplot(
        hplot(bar_plot, bar_plot2, bar_plot3),
        hplot(bar_plot4, bar_plot5, bar_plot6),
        hplot(bar_plot7)
    )
)
コード例 #27
0
ファイル: histogram_multi.py プロジェクト: zlxs23/bokeh
from bokeh.charts import Histogram, defaults, vplot, hplot, show, output_file
from bokeh.sampledata.autompg import autompg as df

defaults.plot_width = 400
defaults.plot_height = 350

# input options
hist = Histogram(df['mpg'], title="df['mpg']")
hist2 = Histogram(df, 'displ', title="df, 'displ'")
hist3 = Histogram(df, values='hp', title="df, values='hp'")

hist4 = Histogram(df,
                  values='hp',
                  color='cyl',
                  title="df, values='hp', color='cyl'",
                  legend='top_right')

hist5 = Histogram(df, values='mpg', bins=50, title="df, values='mpg', bins=50")

output_file("histogram_multi.html", title="histogram_multi.py example")

show(vplot(hplot(hist, hist2), hplot(hist3, hist4), hplot(hist5)))
コード例 #28
0
        ("Sample Size", "@count")
    ])

    # Kernel Density plot
    
    p1 = figure(title=ttle+" Distribution",tools="save,box_zoom,reset")

    hist, edges = np.histogram(county_data[var_], density=True, bins=20)
    gkde=gaussian_kde(county_data[var_])
    ind = np.linspace(0,county_data[var_].max(),101)
    kdepdf = gkde.evaluate(ind)
    p1.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:],
     fill_color="#036564", line_color="#033649")
    p1.line(ind, kdepdf, line_color="#D95B43", line_width=4, alpha=1)

    p = hplot(map_,p1)
    show(p)


# ### Scatter plot matrix

# In[5]:

# Read farm level data

farm_data = pd.read_csv("/home/jared/work/milk_hauling_price/data/combined_data.csv")
cwt_data  = pd.read_csv("/home/jared/work/milk_hauling_price/data/raw_data.csv")[['farmerID','CWT Shipped']]


# In[6]:
コード例 #29
0
ファイル: histograms.py プロジェクト: srinathv/bokeh
from bokeh.charts import Histogram
from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import defaults, vplot, hplot, show, output_file

defaults.width = 450
defaults.height = 350

# input options
hist = Histogram(df['mpg'], title="df['mpg']")
hist2 = Histogram(df, 'displ', title="df, 'displ'")
hist3 = Histogram(df, values='hp', title="df, values='hp'")

hist4 = Histogram(df,
                  values='hp',
                  color='cyl',
                  title="df, values='hp', color='cyl'",
                  legend='top_right')

hist5 = Histogram(df, values='mpg', bins=50, title="df, values='mpg', bins=50")

output_file("histograms.html")

show(vplot(hplot(hist, hist2, hist3), hplot(hist4, hist5)))
コード例 #30
0
# In[2]:

from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import Histogram, output_notebook, show, hplot
# print df
output_notebook()


# In[16]:

hist = Histogram(df, values='mpg', title="Auto MPG Histogram", width=400)
hist2 = Histogram(df, values='displ', label='cyl', color='cyl', legend='top_right',
                  title="MPG Histogram by Cylinder Count", width=400)

show(hplot(hist, hist2))


# In[5]:

# Modules needed from Bokeh.
from bokeh.io import output_file, show
from bokeh.plotting import figure
from bokeh.models import LinearAxis, Range1d

# Seting the params for the first figure.
s1 = figure(x_axis_type="datetime",plot_width=1000,
           plot_height=600)

# Setting the second y axis range name and range
s1.extra_y_ranges = {"foo": Range1d(start=-100, end=200)}
コード例 #31
0
ファイル: bar_multi.py プロジェクト: deolsen/bokeh
bar_plot6 = Bar(df, label='origin', values='mpg', agg='mean', stack='cyl',
                title="label='origin' values='mpg' agg='mean' stack='cyl'",
                legend='top_right')
bar_plot6.title_text_font_size = '10pt'

bar_plot7 = Bar(df, label='cyl', values='displ', agg='mean', group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')
bar_plot7.title_text_font_size = '10pt'

bar_plot8 = Bar(df, label='cyl', values='neg_mpg', agg='mean', group='origin',
                color='origin', legend='top_right',
                title="label='cyl' values='neg_mpg' agg='mean' group='origin'")
bar_plot8.title_text_font_size = '9pt'

# infer labels from index
df = df.set_index('cyl')
bar_plot9 = Bar(df, values='mpg', agg='mean', legend='top_right', title='inferred labels')
bar_plot9.title_text_font_size = '10pt'

output_file("bar_multi.html", title="bar_multi.py example")

show(vplot(
    hplot(bar_plot,  bar_plot2),
    hplot(bar_plot3, bar_plot4),
    hplot(bar_plot5, bar_plot6),
    hplot(bar_plot7, bar_plot8),
    hplot(bar_plot9)
))
コード例 #32
0
ファイル: line_multi.py プロジェクト: tommycarpi/py-tracy
    title="Interpreters (x='date', y, dash=['python', 'pypy', 'jython'])",
    ylabel='Duration',
    legend=True)

line3 = Line(
    df,
    x='date',
    y=['python', 'pypy', 'jython'],
    dash=['python', 'pypy', 'jython'],
    color=['python', 'pypy', 'jython'],
    title=
    "Interpreters (x='date', y, dash, color=['python', 'pypy', 'jython'])",
    ylabel='Duration',
    legend=True)

line4 = Line(
    df,
    x='date',
    y=['python', 'pypy', 'jython'],
    dash='test',
    color=['python', 'pypy', 'jython'],
    title=
    "Interpreters (x='date', y, color=['python', 'pypy', 'jython'], dash='test')",
    ylabel='Duration',
    legend=True)

output_file("line_multi.html", title="line examples")

show(vplot(hplot(line), hplot(line0, line1), hplot(line2, line3),
           hplot(line4)))
コード例 #33
0
ファイル: bar.py プロジェクト: CatherineH/bokeh
np_stacked = Bar(
    random, cat=categories, title="Numpy Array input | Stacked",
    ylabel="Random Number", xlabel="", width=width, height=height,
    stacked=True
)

np_negative_grouped = Bar(
    random * -1, cat=categories, title="All negative input | Grouped",
    ylabel="Random Number", width=width, height=height
)

np_custom = Bar(
    mixed, cat=categories, title="Custom range (start=-3, end=0.4)",
    ylabel="Random Number", width=width, height=height,
    continuous_range=Range1d(start=-3, end=0.4)
)

np_mixed_grouped = Bar(
    mixed, cat=categories, title="Mixed-sign input | Grouped",
    ylabel="Random Number", width=width, height=height
)

# collect and display
output_file("bar.html")

show(vplot(
    hplot(dict_stacked, df_grouped),
    hplot(np_stacked, np_negative_grouped),
    hplot(np_mixed_grouped, np_custom),
))
コード例 #34
0
int_vhover.line_policy = 'interp'

iphover = int_point_line.select(HoverTool)
iphover.mode = 'mouse'
iphover.line_policy = 'interp'

tphover = point_line.select(HoverTool)
tphover.mode = 'mouse'

shover = scatter.select(HoverTool)
shover.mode = 'vline'

shoverp = scatter_point.select(HoverTool)
shoverp.mode = 'mouse'

# set up tooltips
int_vhover.tooltips = int_hhover.tooltips = TOOLTIPS
tphover.tooltips = iphover.tooltips = TOOLTIPS
shover.tooltips = shoverp.tooltips = TOOLTIPS
vhover.tooltips = hhover.tooltips = TOOLTIPS

output_file("hover_span.html", title="hover_span.py example")

show(
    vplot(
        hplot(hline, vline),
        hplot(int_hline, int_vline),
        hplot(int_point_line, point_line),
        hplot(scatter_point, scatter),
    ))
コード例 #35
0
ファイル: boxplot.py プロジェクト: JimBoonie/bokeh
from bokeh.charts import BoxPlot, output_file, show
from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import defaults, vplot, hplot

defaults.width = 450
defaults.height = 350

box_plot = BoxPlot(df, label='cyl', values='mpg', title="label='cyl', values='mpg'")

box_plot2 = BoxPlot(df, label=['cyl', 'origin'], values='mpg', title="label=['cyl', 'origin'], values='mpg'")

box_plot3 = BoxPlot(df, label='cyl', values='mpg', agg='mean',
                title="label='cyl' values='mpg' agg='mean'")

box_plot4 = BoxPlot(df, label='cyl', title="label='cyl' color='DimGray'", color='dimgray')

# collect and display
output_file("boxplot.html")

show(
    vplot(
        hplot(box_plot, box_plot2),
        hplot(box_plot3, box_plot4),
    )
)
コード例 #36
0
df2 = df_from_json(data)
df2 = df2.sort('total', ascending=False)

df2 = df2.head(10)
df2 = pd.melt(df2, id_vars=['abbr', 'name'])

scatter5 = Scatter(df2,
                   x='value',
                   y='name',
                   color='variable',
                   title="x='value', y='name', color='variable'",
                   xlabel="Medals",
                   ylabel="Top 10 Countries",
                   legend='bottom_right')

scatter6 = Scatter(
    flowers,
    x=blend('petal_length', 'sepal_length', name='length'),
    y=blend('petal_width', 'sepal_width', name='width'),
    color='species',
    title=
    'x=petal_length+sepal_length, y=petal_width+sepal_width, color=species',
    legend='top_right')
scatter6.title_text_font_size = '10pt'

output_file("scatter_multi.html", title="scatter_multi.py example")

show(
    vplot(hplot(scatter0, scatter1), hplot(scatter2, scatter3),
          hplot(scatter4, scatter5), hplot(scatter6)))
コード例 #37
0
ファイル: xplorny.py プロジェクト: r-hong/AppXplor
def getFeature():
	if request.method == 'GET':
		return render_template('feature.html')
	else:
                bronx=[[2009,'https://data.cityofnewyork.us/resource/en2c-j6tw.json'],[2010,'https://data.cityofnewyork.us/resource/n2s5-fumm.json'],[2011,'https://data.cityofnewyork.us/resource/bawj-6bgn.json'],[2012,'https://data.cityofnewyork.us/resource/3qfc-4tta.json']]
                brooklyn=[[2009,'https://data.cityofnewyork.us/resource/rmv8-86p4.json'],[2010,'https://data.cityofnewyork.us/resource/w6yt-hctp.json'],[2011,'https://data.cityofnewyork.us/resource/5mw2-hzqx.json'],[2012,'https://data.cityofnewyork.us/resource/bss9-579f.json']]
                manhattan=[[2009,'https://data.cityofnewyork.us/resource/956m-xy24.json'],[2010,'https://data.cityofnewyork.us/resource/ad4c-mphb.json'],[2011,'https://data.cityofnewyork.us/resource/ikqj-pyhc.json'],[2012,'https://data.cityofnewyork.us/resource/dvzp-h4k9.json']]
                queens=[[2009,'https://data.cityofnewyork.us/resource/m59i-mqex.json'],[2010,'https://data.cityofnewyork.us/resource/crbs-vur7.json'],[2011,'https://data.cityofnewyork.us/resource/s3zn-tf7c.json'],[2012,'https://data.cityofnewyork.us/resource/jcih-dj9q.json']]
                statenIsland=[[2009,'https://data.cityofnewyork.us/resource/cyfw-hfqk.json'],[2010,'https://data.cityofnewyork.us/resource/wv4q-e75v.json'],[2011,'https://data.cityofnewyork.us/resource/a5qt-5jpu.json'],[2012,'https://data.cityofnewyork.us/resource/tkdy-59zg.json']]
                featureNames=[['comparable_rental_2_market_value_per_sqft',  'Market value per square foot'],['comparable_rental_2_full_market_value',      'Full market value'],['comparable_rental_2_year_built',             'Year Built'],['comparable_rental_2_gross_income_per_sqft', 'Gross income per square foot']]

		#request was a POST (get the var from the form)
		#common feature
		app_xplor.vars['feat'] = request.form['feat']
		#groups A and B
		app_xplor.vars['boA'] = request.form['boA']
		app_xplor.vars['boB'] = request.form['boB']
		app_xplor.vars['yA'] = request.form['yA']
		app_xplor.vars['yB'] = request.form['yB']

		#Translating name of the feature into the name in the original database
		dbFeatureName = convertField(app_xplor.vars['feat'],featureNames)

		#group A
		if  (app_xplor.vars['boA']=='Bronx'):
			queryA = buildQuery(int(app_xplor.vars['yA']),bronx,dbFeatureName)
		elif (app_xplor.vars['boA']=='Brooklyn'):
			queryA = buildQuery(int(app_xplor.vars['yA']),brooklyn,dbFeatureName)
		elif (app_xplor.vars['boA']=='Manhattan'):
			queryA = buildQuery(int(app_xplor.vars['yA']),manhattan,dbFeatureName)
		elif (app_xplor.vars['boA']=='Queens'):
			queryA = buildQuery(int(app_xplor.vars['yA']),queens,dbFeatureName)
		elif (app_xplor.vars['boA']=='Staten Island'):
			queryA = buildQuery(int(app_xplor.vars['yA']),statenIsland,dbFeatureName)
		
                #group B
                if  (app_xplor.vars['boB']=='Bronx'):
                        queryB = buildQuery(int(app_xplor.vars['yB']),bronx,dbFeatureName)
                elif (app_xplor.vars['boB']=='Brooklyn'):
                        queryB = buildQuery(int(app_xplor.vars['yB']),brooklyn,dbFeatureName)
                elif (app_xplor.vars['boB']=='Manhattan'):
                        queryB = buildQuery(int(app_xplor.vars['yB']),manhattan,dbFeatureName)
                elif (app_xplor.vars['boB']=='Queens'):
                        queryB = buildQuery(int(app_xplor.vars['yB']),queens,dbFeatureName)
                elif (app_xplor.vars['boB']=='Staten Island'):
                        queryB = buildQuery(int(app_xplor.vars['yB']),statenIsland,dbFeatureName)

		rawA = pd.read_json(queryA)
		rawB = pd.read_json(queryB)
		allData = pd.concat([rawA, rawB], axis=1)
		cleanData= allData.dropna()
		cleanData.columns=['A','B']
		
		#plot
		defaults.width = 450
		defaults.height = 350
		tA=str(app_xplor.vars['boA'])+'/'+str(app_xplor.vars['yA']) + '/' + str(app_xplor.vars['feat'])
		tB=str(app_xplor.vars['boB'])+'/'+str(app_xplor.vars['yB']) + '/' + str(app_xplor.vars['feat'])
		histA = Histogram(cleanData['A'], title=tA)
		histB = Histogram(cleanData['B'], title=tB)
		output_file("templates/results.html")
		show(
		    vplot(
        		hplot(histA,histB)
		    )
		)
                return redirect('/goFeat')
コード例 #38
0
ファイル: lines.py プロジェクト: nkhuyu/bokeh
line1 = Line(df, x='date', y=['python', 'pypy', 'jython'],
             title="Interpreters (x='date', y=['python', 'pypy', 'jython'])", ylabel='Duration', legend=True)

line2 = Line(df, x='date', y=['python', 'pypy', 'jython'],
             dash=['python', 'pypy', 'jython'],
             title="Interpreters (x='date', y, dash=['python', 'pypy', 'jython'])", ylabel='Duration', legend=True)

line3 = Line(df, x='date', y=['python', 'pypy', 'jython'],
             dash=['python', 'pypy', 'jython'],
             color=['python', 'pypy', 'jython'],
             title="Interpreters (x='date', y, dash, color=['python', 'pypy', 'jython'])", ylabel='Duration', legend=True)

line4 = Line(df, x='date', y=['python', 'pypy', 'jython'],
             dash='test',
             color=['python', 'pypy', 'jython'],
             title="Interpreters (x='date', y, color=['python', 'pypy', 'jython'], dash='test')", ylabel='Duration',
             legend=True)


output_file("lines.html", title="line.py example")


show(
    vplot(
        hplot(line0, line1),
        hplot(line2, line3),
        hplot(line4)
    )
)
コード例 #39
0
                values='displ',
                agg='mean',
                group='origin',
                title="label='cyl' values='displ' agg='mean' group='origin'",
                legend='top_right')

dot_plot8 = Dot(df,
                label='cyl',
                values='neg_mpg',
                agg='mean',
                group='origin',
                color='origin',
                legend='top_right',
                title="label='cyl' values='neg_mpg' agg='mean' group='origin'")
dot_plot8.title_text_font_size = '11pt'

# infer labels from index
df = df.set_index('cyl')
dot_plot9 = Dot(df,
                values='mpg',
                agg='mean',
                legend='top_right',
                title='inferred labels')

output_file("dots_multi.html", title="dots_multi.py example")

show(
    vplot(hplot(dot_plot, dot_plot2), hplot(dot_plot3, dot_plot4),
          hplot(dot_plot5, dot_plot6), hplot(dot_plot7, dot_plot8),
          hplot(dot_plot9)))
コード例 #40
0
ファイル: histograms.py プロジェクト: nkhuyu/bokeh
from bokeh.charts import Histogram
from bokeh.sampledata.autompg import autompg as df
from bokeh.charts import defaults, vplot, hplot, show, output_file

defaults.width = 450
defaults.height = 350

# input options
hist = Histogram(df['mpg'], title="df['mpg']")
hist2 = Histogram(df, 'displ', title="df, 'displ'")
hist3 = Histogram(df, values='hp', title="df, values='hp'")

hist4 = Histogram(df, values='hp', color='cyl',
                  title="df, values='hp', color='cyl'", legend='top_right')

hist5 = Histogram(df, values='mpg', bins=50,
                  title="df, values='mpg', bins=50")

output_file("histograms.html")

show(
    vplot(
        hplot(hist, hist2, hist3),
        hplot(hist4, hist5)
    )
)
コード例 #41
0
def scan_pix_hist(h5_file_name, scurve_sel_pix = 200):
    with tb.open_file(h5_file_name, 'r') as in_file_h5:
        meta_data = in_file_h5.root.meta_data[:]
        hit_data = in_file_h5.root.hit_data[:]

        scan_args = yaml.load(in_file_h5.root.meta_data.attrs.kwargs)
        scan_range = scan_args['scan_range']
        scan_range_inx = np.arange(scan_range[0], scan_range[1], scan_range[2])

        repeat_command = scan_args['repeat_command']

        np.set_printoptions(threshold=np.nan)
        k = 5
        param = np.unique(meta_data['scan_param_id'])
        ret = []
        for i in param:
            wh = np.where(hit_data['scan_param_id'] == i) #this can be faster and multi threaded
            hd = hit_data[wh[0]]
            hits = hd['col'].astype(np.uint16)
            hits = hits * 64
            hits = hits + hd['row']
            value = np.bincount(hits)
            value = np.pad(value, (0, 64*64 - value.shape[0]), 'constant')
            if len(ret):
                ret = np.vstack((ret, value))
            else:
                ret = value

        s_hist = np.swapaxes(ret,0,1)
        indices = np.indices(s_hist.shape)

        param_inx = np.ravel(indices[1].astype(np.float64))#*0.05 - 0.6)
        param_inx_string = param_inx.astype('|S5')

        pix_scan_hist = np.empty((s_hist.shape[1],repeat_command + 10))
        for param in range(s_hist.shape[1]):
            h_count = np.bincount(s_hist[:,param])
            h_count = h_count[:repeat_command+10]
            pix_scan_hist[param] = np.pad(h_count, (0, (repeat_command + 10) - h_count.shape[0]), 'constant')

        log_hist = np.log10(pix_scan_hist)
        log_hist[~np.isfinite(log_hist)] = 0
        data = {
            'scan_param': np.ravel(np.indices(pix_scan_hist.shape)[0]),
            'count': np.ravel(np.indices(pix_scan_hist.shape)[1]),
            'value': np.ravel(log_hist)
        }

        hm1 = HeatMap(data, x='scan_param', y='count', values='value', title='s-scans', palette=Spectral11[::-1], stat=None, plot_width=1000) #, height=4100)

        mean = np.empty(64*64)
        noise = np.empty(64*64)
        x = scan_range_inx
        for pix in range (64*64):
            mu, sigma = analysis.fit_scurve(s_hist[pix], x) #this can multi threaded
            mean[pix] = mu
            noise[pix] = sigma

        px = scurve_sel_pix #1110 #1539
        single_scan = figure(title="Single pixel scan " + str(px) )
        single_scan.diamond(x=x, y=s_hist[px], size=5, color="#1C9099", line_width=2)
        yf = analysis.scurve(x, 100, mean[px], noise[px])
        single_scan.cross(x=x, y=yf, size=5, color="#E6550D", line_width=2)

        mean[mean > scan_range_inx[-1]] = 0
        hist, edges = np.histogram(mean, density=True, bins=50)
	#print "sigma:",noise

        hm_th = figure(title="Threshold", x_axis_label = "pixel #", y_axis_label = "threshold [V]", y_range=(scan_range_inx[0], scan_range_inx[-1]), plot_width=1000)
        hm_th.diamond(y=mean, x=range(64*64), size=1, color="#1C9099", line_width=2)
        hm_th.extra_y_ranges = {"e": Range1d(start=scan_range_inx[0]*1000*7.6, end=scan_range_inx[-1]*1000*7.6)}
        hm_th.add_layout(LinearAxis(y_range_name="e"), 'right')
        barray = fit_gauss(edges[2:], hist[1:])
        plt_th_dist = figure(title= 'Threshold Distribution ' + '\sigma = ' + str(round(barray[2],4)) + ' \mu =' + str(round(barray[1],4)), x_axis_label = "threshold [V]", y_range=(0, 1.1*np.max(hist[1:])))
        plt_th_dist.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564", line_color="#033649",)
        plt_th_dist.extra_x_ranges = {"e": Range1d(start=edges[0]*1000*7.6, end=edges[-1]*1000*7.6)}
        plt_th_dist.add_layout(LinearAxis(x_range_name="e"), 'above')
        plt_th_dist.line(np.arange(edges[1], edges[50], 0.0001),
              gauss(np.arange(edges[1], edges[50], 0.0001), barray[0], barray[1], barray[2]), line_color="#D95B43",
              line_width=8, alpha=0.7)

        noise[noise > 0.02] = 0.02  #this should be done based on 6sigma?
        hist, edges = np.histogram(noise, density=True, bins=50)

        hm_noise = figure(title="Noise", x_axis_label = "pixel #", y_axis_label = "noise [V]", y_range=(0, edges[-1]), plot_width=1000)
        hm_noise.diamond(y=noise, x=range(64*64), size=2, color="#1C9099", line_width=2)
        hm_noise.extra_y_ranges = {"e": Range1d(start=0, end=edges[-1]*1000*7.6)}
        hm_noise.add_layout(LinearAxis(y_range_name="e"), 'right')

        gauss_params_noise = fit_gauss(edges[5:], hist[4:])
        plt_noise_dist = figure(title='Noise Distribution ' + '\sigma = ' + str(round(gauss_params_noise[2],4)) + ' \mu = ' + str(round(gauss_params_noise[1],4)) , x_axis_label = "noise [V]", y_range=(0, 1.1*np.max(hist[1:])))
        plt_noise_dist.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564", line_color="#033649",)
        plt_noise_dist.extra_x_ranges = {"e": Range1d(start=edges[0]*1000*7.6, end=edges[-1]*1000*7.6)}
        plt_noise_dist.add_layout(LinearAxis(x_range_name="e"), 'above')
        plt_noise_dist.line(np.arange(edges[1],edges[50],0.0001),gauss(np.arange(edges[1],edges[50],0.0001),gauss_params_noise[0],gauss_params_noise[1],gauss_params_noise[2]),line_color="#D95B43", line_width=8, alpha=0.7)

        return vplot(hplot(hm_th, plt_th_dist), hplot(hm_noise,plt_noise_dist), hplot(hm1, single_scan) ), s_hist
コード例 #42
0
ファイル: hover_span.py プロジェクト: JasonKessler/bokeh
int_vhover.line_policy = 'interp'

iphover = int_point_line.select(dict(type=HoverTool))
iphover.mode = 'mouse'
iphover.line_policy = 'interp'

tphover = point_line.select(dict(type=HoverTool))
tphover.mode = 'mouse'

shover = scatter.select(dict(type=HoverTool))
shover.mode = 'vline'

shoverp = scatter_point.select(dict(type=HoverTool))
shoverp.mode = 'mouse'

int_vhover.tooltips = int_hhover.tooltips = tphover.tooltips = iphover.tooltips = shover.tooltips = shoverp.tooltips = vhover.tooltips = hhover.tooltips = OrderedDict([
    ("y", "$~y"),
    ("x", "$~x"),
    # ("data_x", "$~x"),
    # ("data_y", "$~y"),
])

show(
    vplot(
        hplot(hline, vline),
        hplot(int_hline, int_vline),
        hplot(int_point_line, point_line),
        hplot(scatter_point, scatter),
    )
)
コード例 #43
0
ファイル: plotting.py プロジェクト: SiLab-Bonn/fe65_p2
def scan_pix_hist(h5_file_name, scurve_sel_pix=200):
    with tb.open_file(h5_file_name, 'r') as in_file_h5:
        meta_data = in_file_h5.root.meta_data[:]
        hit_data = in_file_h5.root.hit_data[:]
        en_mask = in_file_h5.root.scan_results.en_mask[:]
        Noise_gauss = in_file_h5.root.Noise_results.Noise_pure.attrs.fitdata_noise
        Noise_pure = in_file_h5.root.Noise_results.Noise_pure[:]
        Thresh_gauss = in_file_h5.root.Thresh_results.Threshold_pure.attrs.fitdata_thresh
        Threshold_pure = in_file_h5.root.Thresh_results.Threshold_pure[:]
        scan_args = yaml.load(in_file_h5.root.meta_data.attrs.kwargs)
        scan_range = scan_args['scan_range']
        scan_range_inx = np.arange(scan_range[0], scan_range[1], scan_range[2])

        # np.set_printoptions(threshold=np.nan)
        param = np.unique(meta_data['scan_param_id'])
        ret = []
        for i in param:
            wh = np.where(hit_data['scan_param_id'] == i)  # this can be faster and multi threaded
            hd = hit_data[wh[0]]
            hits = hd['col'].astype(np.uint16)
            hits = hits * 64
            hits = hits + hd['row']
            value = np.bincount(hits)
            value = np.pad(value, (0, 64 * 64 - value.shape[0]), 'constant')
            if len(ret):
                ret = np.vstack((ret, value))
            else:
                ret = value
        repeat_command = max(ret[-3])
        shape = en_mask.shape
        ges = 1
        for i in range(2):
            ges = ges * shape[i]
        ret_pure = ()
        en_mask = en_mask.reshape(ges)
        for n in range(param[-1]):
            ret_pure1 = ()
            for i in range(ges):
                if (str(en_mask[i]) == 'True'):
                    ret_pure1 = np.append(ret_pure1, ret[n][i])
            if n == 0:
                ret_pure = ret_pure1
                continue
            ret_pure = np.vstack((ret_pure, ret_pure1))

        ret_pure = ret_pure.astype(int)
        s_hist = np.swapaxes(ret_pure, 0, 1)

        pix_scan_hist = np.empty((s_hist.shape[1], repeat_command + 10))
        for param in range(s_hist.shape[1]):
            h_count = np.bincount(s_hist[:, param])
            h_count = h_count[:repeat_command + 10]
            pix_scan_hist[param] = np.pad(h_count, (0, (repeat_command + 10) - h_count.shape[0]), 'constant')

        log_hist = np.log10(pix_scan_hist)
        log_hist[~np.isfinite(log_hist)] = 0
        data = {
            'scan_param': np.ravel(np.indices(pix_scan_hist.shape)[0]),
            'count': np.ravel(np.indices(pix_scan_hist.shape)[1]),
            'value': np.ravel(log_hist)
        }

        x = scan_range_inx
        px = scurve_sel_pix  # 1110 #1539
        single_scan = figure(title="Single pixel scan " + str(px), x_axis_label="Injection[V]", y_axis_label="Hits")
        single_scan.diamond(x=x, y=s_hist[px], size=5, color="#1C9099", line_width=2)
        yf = analysis.scurve(x, 100, Threshold_pure[px], Noise_pure[px])
        single_scan.cross(x=x, y=yf, size=5, color="#E6550D", line_width=2)

        hist, edges = np.histogram(Threshold_pure, density=False, bins=50)

        hm1 = HeatMap(data, x='scan_param', y='count', values='value', title='Threshold Heatmap',
                      palette=Spectral11[::-1], stat=None, plot_width=1000)  # , height=4100)
        hm1.extra_x_ranges = {
            "e": Range1d(start=edges[0] * 1000 * analysis.cap_fac(), end=edges[-1] * 1000 * analysis.cap_fac())}

        hm_th = figure(title="Threshold", x_axis_label="pixel #", y_axis_label="threshold [V]",
                       y_range=(scan_range_inx[0], scan_range_inx[-1]), plot_width=1000)
        hm_th.diamond(y=Threshold_pure, x=range(64 * 64), size=1, color="#1C9099", line_width=2)
        hm_th.extra_y_ranges = {"e": Range1d(start=scan_range_inx[0] * 1000 * analysis.cap_fac(),
                                             end=scan_range_inx[-1] * 1000 * analysis.cap_fac())}
        hm_th.add_layout(LinearAxis(y_range_name="e"), 'right')
        plt_th_dist = figure(title='Threshold Distribution ', x_axis_label="threshold [V]", y_axis_label="#Pixel",
                             y_range=(0, 1.1 * np.max(hist[1:])))
        plt_th_dist.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564",
                         line_color="#033649",
                         legend="# {0:d}  mean={1:.2f}  std={2:.2f}".format(int(np.sum(hist[:])), round(
                             Thresh_gauss['mu'] * 1000 * analysis.cap_fac(), 4),
                                                                            round(Thresh_gauss[
                                                                                      'sigma'] * 1000 * analysis.cap_fac(),
                                                                                  4)))
        plt_th_dist.extra_x_ranges = {"e": Range1d(start=edges[0] * 1000 * analysis.cap_fac(),
                                                   end=edges[-1] * 1000 * analysis.cap_fac())}  # better 7.4?
        plt_th_dist.add_layout(LinearAxis(x_range_name="e"), 'above')
        plt_th_dist.line(np.arange(edges[1], edges[-1], 0.0001),
                         analysis.gauss(np.arange(edges[1], edges[-1], 0.0001), Thresh_gauss['height'],
                                        Thresh_gauss['mu'], Thresh_gauss['sigma']), line_color="#D95B43", line_width=8,
                         alpha=0.7)

        hist, edges = np.histogram(Noise_pure, density=False, bins=50)
        hm_noise = figure(title="Noise", x_axis_label="pixel #", y_axis_label="noise [V]", y_range=(0, edges[-1]),
                          plot_width=1000)
        hm_noise.diamond(y=Noise_pure, x=range(64 * 64), size=2, color="#1C9099", line_width=2)
        hm_noise.extra_y_ranges = {"e": Range1d(start=0, end=edges[-1] * 1000 * analysis.cap_fac())}  # default 7.6
        hm_noise.add_layout(LinearAxis(y_range_name="e"), 'right')

        plt_noise_dist = figure(title='Noise Distribution ', x_axis_label="noise [V]", y_axis_label="#Pixel",
                                y_range=(0, 1.1 * np.max(hist[1:])))
        plt_noise_dist.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564",
                            line_color="#033649",
                            legend="# {0:d}  mean={1:.2f}  std={2:.2f}".format(int(np.sum(hist[:])), round(
                                Noise_gauss['mu'] * 1000 * analysis.cap_fac(), 4), round(
                                Noise_gauss['sigma'] * 1000 * analysis.cap_fac(), 4)))
        plt_noise_dist.extra_x_ranges = {
            "e": Range1d(start=edges[0] * 1000 * analysis.cap_fac(), end=edges[-1] * 1000 * analysis.cap_fac())}
        plt_noise_dist.add_layout(LinearAxis(x_range_name="e"), 'above')
        plt_noise_dist.line(np.arange(edges[0], edges[-1], 0.0001),
                            analysis.gauss(np.arange(edges[0], edges[-1], 0.0001), Noise_gauss['height'],
                                           Noise_gauss['mu'], Noise_gauss['sigma']), line_color="#D95B43", line_width=8,
                            alpha=0.7)

        return vplot(hplot(hm_th, plt_th_dist), hplot(hm_noise, plt_noise_dist), hplot(hm1, single_scan)), s_hist