ROOT Version: 6.20/00
Hi,
I am trying to plot a graph using logarithmic scale, I have seen few related posts, but I cannot find the problem.
I would like to Draw pad1->cd(1) in logarithmic and pad1->cd(2) linear.
It is strange, I cannot upload the file, it tells me the file contents are empty. So I copy/paste it here.
TCanvas* GraphLogTest() {
TCanvas* canv = new TCanvas("canv", "", 1600, 600);
canv->SetLogy(1);
TPad* pad1 = new TPad("pad1", "This is pad1", 0.01, 0.02, 0.99, 0.97);
pad1->Divide(3, 1);
pad1->Draw();
std::vector<TGraph*> graphs;
std::vector<double> aRange = {0, 5};
std::vector<double> lambdas = {0.3, 1, 2};
for (int n = 0; n < lambdas.size(); n++) {
TGraph* gr = new TGraph();
for (double a = aRange[0]; a <= aRange[1]; a += (aRange[1] - aRange[0]) / 100.) {
gr->SetPoint(gr->GetN(), a, TMath::Exp(-lambdas[n] * a));
}
graphs.push_back(gr);
}
graphs[0]->GetXaxis()->SetLimits(aRange[0], aRange[1]);
graphs[0]->GetHistogram()->SetMaximum(1);
graphs[0]->GetHistogram()->SetMinimum(1.e-3);
graphs[0]->GetXaxis()->SetTitle("X-label");
graphs[0]->GetXaxis()->SetTitleSize(0.05);
graphs[0]->GetXaxis()->SetLabelSize(0.05);
graphs[0]->GetYaxis()->SetTitle("Y-label");
graphs[0]->GetYaxis()->SetTitleOffset(1.3);
graphs[0]->GetYaxis()->SetTitleSize(0.05);
graphs[0]->GetYaxis()->SetLabelSize(0.05);
pad1->cd(1);
pad1->SetLogy(1);
graphs[0]->SetLineColor(33);
graphs[0]->SetLineWidth(4);
graphs[0]->Draw("AL");
for (int n = 1; n < lambdas.size(); n++) {
graphs[n]->SetLineWidth(4);
graphs[n]->SetLineColor(33 + 2 * n);
graphs[n]->Draw("L");
}
pad1->cd(2);
pad1->SetLogy(0);
graphs[0]->SetLineColor(33);
graphs[0]->SetLineWidth(4);
graphs[0]->Draw("AL");
for (int n = 1; n < lambdas.size(); n++) {
graphs[n]->SetLineWidth(4);
graphs[n]->SetLineColor(33 + 2 * n);
graphs[n]->Draw("L");
}
return canv;
}
Any idea is welcome. Thank you!