Hello
I am trying to plot multple graphs with the same x scale and different y scales on one canvas. I am following some excellent advice I got before about using a different Tpad for each graph, and then making the top pads transparent so that the lower ones are visible. The problem is that I can only plot two graphs because once I plot one the regular way and the second using Y+, all the rest of the Y axis labels and such just get put on top of those. What I would like to do is to draw additional graphs and than put the Y axes in different horizontal places so that they don’t get overlaid and look messy. I have tried defining a new axis with TGaxis but I’m not sure how to set the position, and anyway if I try to draw a graph without using the “A” option, it doesn’t set up all the ranges and stuff so the points are not visible. If anyone could give me a very simple example of how to do this, (with some of the y-axes plotted on log scales, because that’s going to be my next question), I would appreciate it.
Here is an example of what I have (actually a modification of a previous example provided by couet):
{
{
const Int_t N1 = 10;
const Int_t N2 = 6;
Int_t NMax, in;
Float_t x1[N1], x2[N2], y1[N1], y2[N2],x3[N1], x4[N2], y3[N1], y4[N2], step, dir;
y1[0] = 5.0;
y2[0] = 0.1;
y3[0] = 2.6;
y4[0] = 0.7;
step = 0.5;
x1[0] = 0.0;
x2[0] = 1.5;
x3[0] = 0.5;
x4[0] = 1.0;
dir = 1.0;
cout<<"Graph1:\n";
for (in=1; in<N1; in++) {
if (in>N1/2) dir = -1.0;
x1[in] = (Float_t) in;
y1[in] = y1[in-1]+(2.0*step*dir);
cout<<"("<<x1[in]<<", "<<y1[in]<<")\n";
}
dir = 1.0;
cout<<"Graph2:\n";
for (in=1; in<N2; in++) {
if (in<N2/2) dir = -1.0;
else dir = 1.0;
x2[in] = in+1.5;
y2[in] = y2[in-1]+(-0.1*step*dir);
cout<<"("<<x2[in]<<", "<<y2[in]<<")\n";
}
dir = 1.0;
cout<<"Graph3:\n";
for (in=1; in<N2; in++) {
if (in<N2/2) dir = -1.0;
else dir = 1.0;
x3[in] = in+2.5;
y3[in] = y3[in-1]+(0.3*step*dir);
cout<<"("<<x2[in]<<", "<<y2[in]<<")\n";
}
dir = 1.0;
cout<<"Graph4:\n";
for (in=1; in<N2; in++) {
if (in<N2/2) dir = -1.0;
else dir = 1.0;
x4[in] = in+3.5;
y4[in] = y4[in-1]+(-0.5*step*dir);
cout<<"("<<x2[in]<<", "<<y2[in]<<")\n";
}
TGraph *inputSpec = new TGraph(N1, x1, y1);
TGraph *inputSpec2 = new TGraph(N2, x2, y2);
TGraph *inputSpec3 = new TGraph(N2, x3, y3);
TGraph *inputSpec4 = new TGraph(N2, x4, y4);
TH1F *h1 = inputSpec->GetHistogram();
h1->Scale(0.1);
h1->SetXTitle("X title");
h1->SetYTitle("Y title");
TCanvas *c1 = new TCanvas("c1", "Intensity of LED 1",0, 0, 800, 600);
TPad *pad1 = new TPad("pad1","",0,0,1,1);
TPad *pad2 = new TPad("pad2","",0,0,1,1);
pad2->SetFillStyle(4000);
// Makes pad2
pad2->SetFrameFillStyle(0);
// transparent.
TPad *pad3 = new TPad("pad3","",0,0,1,1);
pad3->SetFillStyle(4000);
// Makes pad2
pad3->SetFrameFillStyle(0);
// transparent.
TPad *pad4 = new TPad("pad4","",0,0,1,1);
pad4->SetFillStyle(4000);
// Makes pad2
pad4->SetFrameFillStyle(0);
// transparent.
pad1->Draw();
pad1->cd();
inputSpec->SetMarkerStyle(29);
inputSpec->SetMarkerColor(kBlack+2);
inputSpec->SetLineColor(kBlack);
//mg->Add(inputSpec,"LP");
inputSpec->GetXaxis()->SetLimits(0.,9.);
inputSpec->Draw("ALP");
TH1F *h2 = inputSpec2->GetHistogram();
TAxis *Ay2 = h2->GetYaxis();
Ay2->SetRangeUser(0.0, 0.5);
TH1F *h3 = inputSpec3->GetHistogram();
TAxis *Ay3 = h3->GetYaxis();
Ay3->SetRangeUser(0.0, 10);
TH1F *h4 = inputSpec4->GetHistogram();
TAxis *Ay4 = h4->GetYaxis();
Ay4->SetRangeUser(0.0, 5);
pad2->Draw();
pad2->cd();
inputSpec2->SetMarkerStyle(29);
inputSpec2->SetMarkerColor(kRed+2);
inputSpec2->SetLineColor(kRed);
inputSpec2->GetXaxis()->SetLimits(0.,9.);
inputSpec2->GetXaxis()->SetAxisColor(kRed);
inputSpec2->GetXaxis()->SetLabelColor(kRed);
inputSpec2->GetYaxis()->SetAxisColor(kRed);
inputSpec2->GetYaxis()->SetLabelColor(kRed);
inputSpec2->Draw("LPAY+");
pad3->Draw();
pad3->cd();
inputSpec3->SetMarkerStyle(29);
inputSpec3->SetMarkerColor(kGreen+2);
inputSpec3->SetLineColor(kGreen);
//mg2->Add(inputSpec3,"LPY+");
inputSpec3->GetXaxis()->SetLimits(0.,9.);
inputSpec3->GetXaxis()->SetAxisColor(kGreen);
inputSpec3->GetXaxis()->SetLabelColor(kGreen);
inputSpec3->GetYaxis()->SetAxisColor(kGreen);
inputSpec3->GetYaxis()->SetLabelColor(kGreen);
inputSpec3->Draw("LPAY+");
pad4->Draw();
pad4->cd();
inputSpec4->SetMarkerStyle(29);
inputSpec4->SetMarkerColor(kBlue+2);
inputSpec4->SetLineColor(kBlue);
//mg2->Add(inputSpec4,"LPY+");
inputSpec4->GetXaxis()->SetLimits(0.,9.);
inputSpec4->GetXaxis()->SetAxisColor(kBlue);
inputSpec4->GetXaxis()->SetLabelColor(kBlue);
inputSpec4->GetYaxis()->SetAxisColor(kBlue);
inputSpec4->GetYaxis()->SetLabelColor(kBlue);
inputSpec4->Draw("LPAY+");
}
See how the numbers and ticks to the right are all on top of each other? I am hoping that someone can tell me a way to move and recolour the y axis for a single graph, so that it doesn’t look so messy.
Thanks very much.