hammiu
1
I want to draw 2 functions in the same canvas. I used option “same”, but it didn’t work properly. Could you help me, please? Here is my code:
void B_Z()
{
TCanvas *c = new TCanvas("B(Z)", "B(Z) linear", 800, 600);
c->SetGrid();
c->SetTicks();
TF1 *f1 = new TF1("f1", "0.088807", 6, 21);
f1->SetLineColor(kRed-4);
f1->Draw();
TF1 *f2 = new TF1("f2", "0.08356", 21, 26);
f2->SetLineColor(kAzure);
f2->Draw("same");
couet
2
The range on X is imposed by the first function and the second fonction is outside that range.
A possible solution is:
void B_Z()
{
TCanvas *c = new TCanvas("B(Z)", "B(Z) linear", 800, 600);
c->SetGrid();
c->SetTicks();
c->DrawFrame(6,0,26,0.2);
TF1 *f1 = new TF1("f1", "0.088807", 6, 21);
f1->SetLineColor(kRed-4);
f1->Draw("same");
TF1 *f2 = new TF1("f2", "0.08356", 21, 26);
f2->SetLineColor(kAzure);
f2->Draw("same");
}
hammiu
3
Thanks a lot. It works fine.
hammiu
4
I have problem with titles of X, Y axis. I can not set titles for X and Y axis. I used the command.
f1->GetXaxis()->SetTitle("Z");
f1->GetYaxis()->SetTitle("B(Z)");
couet
5
void B_Z()
{
TCanvas *c = new TCanvas("B(Z)", "B(Z) linear", 800, 600);
c->SetGrid();
c->SetTicks();
TH1F *f = c->DrawFrame(6,0,26,0.2);
f->GetXaxis()->SetTitle("Z");
f->GetYaxis()->SetTitle("B(Z)");
TF1 *f1 = new TF1("f1", "0.088807", 6, 21);
f1->SetLineColor(kRed-4);
f1->Draw("same");
TF1 *f2 = new TF1("f2", "0.08356", 21, 26);
f2->SetLineColor(kAzure);
f2->Draw("same");
}
1 Like