Add second axis

Dears,

I have 2 Tgraph in one Multigraph, but the values of these 2 graph are different (an order of difference), so the values of one graph are good and the values of other graph, which are lower, appear almost to zero… so what I would like to do is “rescale” the 2nd graph and ad a second y2 axis on right (with the real values of y2). I already checked the guide and other posts in the forum but I didn’t found what I nedd…

Below an example of data in inpunt and the code which I tried to write…

data example:

1	10	200
2	20	300
3	30	400
4	40	500
tree1= TTree ("tree1","tree1")		
tree1.ReadFile("myfile.csv","a/I:b/I:c/I",'\t') 


def slopevsTime(gap):
	canvas = TCanvas("canvas","canvas", 600, 600)
	gPad.SetGrid()
	canvas.SetTopMargin(.08)
	canvas.SetRightMargin(0.05)
	canvas.SetBottomMargin(0.13)
	canvas.SetLeftMargin(0.16)
	canvas.SetBorderSize(2)
	canvas.SetFrameFillStyle(0);
	canvas.SetFrameBorderMode(0);
	canvas.SetFrameFillStyle(0);
	canvas.SetFrameBorderMode(0);
  
	gr1= TMultiGraph()					
	gr1.Draw( 'AP' )

######## 

	n=tree1.Draw("a:b:c","","goff")
	x= tree1.GetV1()	
	y= tree1.GetV2()
	grR= TGraph(n,x,y)	

	grR.SetMarkerStyle(4)
	grR.SetMarkerSize(0.9)
	grR.SetMarkerColor(2)
	grR.SetLineColor(2)
	grR.Draw( 'AP' )

	gr1.Add(grR)				

######## 2 plot 
	
	x2= tree1.GetV1()	
	y2= tree1.GetV3()
	grI= TGraphErrors(n,x2,y2)			#inizializza grafico

	grI.SetMarkerStyle(26)
	grI.SetMarkerSize(0.9)
	grI.SetMarkerColor(4)
	grI.SetLineColor(4)
	grI.Draw( 'AP' )

	gr1.Add(grI)					

########  TMultigraph

	gr1.Draw("AP")

Thanks a lot in advance for your help!! :slight_smile:

Hi,
you can try look at this https://root.cern.ch/root/html/tutorials/hist/twoscales.C.html

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