Dears,
I tried to plot 2 graph with 2 different scale in 1 canvas. The data example to plot are:
1 1 1000
2 2 2000
3 2 3000
4 4 4000
5 4 5000
Following the examples I produced the follow script:
gROOT.Reset();
c1 = TCanvas("c1","c1",600,600);
pad = TPad("pad","pad",0,0,1,1);
pad.SetGrid();
pad.Draw();
pad.cd();
pad.SetTopMargin(.1)
pad.SetRightMargin(0.15)
pad.SetBottomMargin(0.13)
pad.SetLeftMargin(0.16)
pad.SetBorderSize(5)
pad.SetFrameFillStyle(0);
pad.SetFrameBorderMode(0);
pad.SetFrameFillStyle(0);
pad.SetFrameBorderMode(0);
# draw a frame to define the range
hr = c1.DrawFrame(0,0,5,5);
hr.SetTitle("title");
hr.SetXTitle("X title");
hr.SetYTitle("Y title");
hr.GetXaxis().SetTitleFont(43)
hr.GetYaxis().SetTitleFont(43)
hr.GetXaxis().SetTitleSize(20)
hr.GetYaxis().SetTitleSize(20)
hr.GetXaxis().SetTitleOffset(1)
hr.GetYaxis().SetTitleOffset(1.4)
hr.GetXaxis().SetLabelFont(43)
hr.GetYaxis().SetLabelFont(43)
hr.GetXaxis().SetLabelSize(20)
hr.GetYaxis().SetLabelSize(20)
hr.GetXaxis().SetLabelOffset(0.005)
hr.GetYaxis().SetLabelOffset(.015)
pad.GetFrame().SetBorderSize(12);
# create first graph
gr = TGraph( name_file ,"%lg %lg" )
gr.SetLineStyle(1)
gr.SetLineColor(2)
gr.SetLineWidth(2)
gr.SetMarkerStyle(8)
gr.SetMarkerSize(1.5)
gr.SetMarkerColor(2)
gr.Draw("LP");
# create second graph
gr2 = TGraph( name_file ,"%lg %*s %lg" )
gr2.SetLineStyle(1)
gr2.SetLineColor(3)
gr2.SetLineWidth(3)
gr2.SetMarkerStyle(21)
gr2.SetMarkerSize(1.5)
gr2.SetMarkerColor(3)
#create a transparent pad drawn on top of the main pad
c1.cd();
overlay = TPad("overlay","overlay",0,0,1,1);
overlay.SetFillStyle(4000);
overlay.SetFillColor(0);
overlay.SetFrameFillStyle(4000);
overlay.Draw();
overlay.cd();
overlay.SetTopMargin(.1)
overlay.SetRightMargin(0.15)
overlay.SetBottomMargin(0.13)
overlay.SetLeftMargin(0.16)
overlay.SetBorderSize(5)
overlay.SetFrameFillStyle(0);
overlay.SetFrameBorderMode(0);
overlay.SetFrameFillStyle(0);
overlay.SetFrameBorderMode(0);
xmin = pad.GetUxmin();
xmax = pad.GetUxmax();
ymin = 0;
ymax = 5000;
hframe = overlay.DrawFrame(xmin,ymin,xmax,ymax);
hframe.GetXaxis().SetLabelOffset(99);
hframe.GetYaxis().SetLabelOffset(99);
gr2.Draw("LP");
#Draw an axis on the right side
axis = TGaxis(xmax,ymin,xmax,ymax,ymin,ymax,510,"+L");
axis.SetTitle("Y2 Title")
axis.SetTitleFont(43)
axis.SetTitleSize(20)
axis.SetTitleOffset(2)
axis.SetLabelFont(43)
axis.SetLabelSize(20)
axis.SetLabelOffset(.015)
axis.Draw();
c1.Update()
c1.SaveAs("P.png")
All works fine, but I would like that the ymax to set for the 2nd pad, which now I setted by hand (ymax = 5000;) I would like set it in automatic way… So I tried with gr2.GetMaximum() but it seams that doesn’t work. Any suggestions?
Thanks a lot in advance