Plots some TH1 in 1 canvas

Dears,
I’m trying to plot some TH1 in the same canvas. I have some TH1 into some different root files. I need to automatize the process to plot in 1 canvas all the TH1 from different root files. So for each legend name, root has to take the histogram from the input file and plot it in the final canvas. Here a piece of the code:

lenged_list=["gr1","gr2"]	 

n_graph= len(lenged_list)						
graph_list=[]						
graph_index=1						
for legend in range(1,n_graph+1):			
	graph_list.append("gr"+str(graph_index))	
	graph_index=graph_index+1			
list_rootfile= glob.glob('*.root') 		

canvas = TCanvas("canvas","canvas", 600, 600)

index_graph=0					
for file_in in list_rootfile:			
		input_root = TFile(file_in)		
	graph_list[index_graph]= input_root.Get("Beam_Profile")
	graph_list[index_graph].Draw("SAME")
	index_graph= index_graph +1				
	canvas.Update()
	
canvas.Update()
canvas.SaveAs("test.png")
	

But it doesn’t works. Some one can help me?
Thanks a lot in advance :slight_smile:

Call TH1.AddDirectory(0) before reading the histograms. Otherwise the file owns and deletes the histogram.

Axel

Thanks a lot Axel !!! :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.