Hi,
I am trying to plot two TF1s on the same plot with different axis. I managed to do it almost fine, but I am experiencing a few issues which occur especially in log scale.
Here is a simple macro reproducing the problems :
[code]void plot_test()
{
double xmax = 100;
TF1* a = new TF1("a","x",0,xmax);
// TF1* b = new TF1(“b”,“TMath::Abs(1-x/10)”,0,xmax);
TF1* b = new TF1(“b”,“TMath::Exp(-x/10)”,0,xmax);
TCanvas *c = new TCanvas();
TPad *pad1 = new TPad("pad1","",0,0,1,1);
TPad *pad2 = new TPad("pad2","",0,0,1,1);
pad2 -> SetFillStyle(4000); // Makes pad2 transparent
pad1 -> SetLogy(1);
pad1 -> Draw();
pad1 -> cd();
a -> Draw();
a -> GetYaxis()->SetRangeUser(.1,100);
// compute the pad range with suitable margins
Double_t xmin = 0;
Double_t dx = (xmax-xmin)/0.8; //10 per cent margins left and right
Double_t ymin = 0.001;
Double_t ymax = 1;
// For linear scale
// Double_t dy = (ymax-ymin)/0.8; //10 per cent margins top and bottom
// pad2->Range(xmin-0.1dx, ymin-0.1dy, xmax+0.1dx, ymax+0.1dy);
// For log scale
Double_t dy = (log10(ymax)-log10(ymin))/0.8; //10 per cent margins top and bottom
Double_t Ymin = log10(ymin)-0.1*dy;
Double_t Ymax = log10(ymax)+0.1*dy;
pad2 -> Range(xmin-0.1*dx, Ymin, xmax+0.1*dx, Ymax);
pad2 -> SetLogy(1);
pad2 -> Draw();
pad2 -> cd();
b -> SetLineColor(2);
b -> SetNpx(10000);
b -> Draw("same");
// draw axis on the right side of the pad
TGaxis *axis = new TGaxis(xmax, ymin, xmax, ymax, ymin, ymax, 50510, "+GL");
axis -> SetLabelColor(kRed);
axis -> Draw();
}
[/code]
1/ The issue that bothers me the most is that the second TF1 (b) is not correctly drawn. As you can see on figure 1 (red curve), it is truncated at 0.1.
2/ For some expressions the second curve will go out of the frame, as illustrated in figure 2 for b as
TF1* b = new TF1("b","TMath::Abs(1-x/10)",0,xmax);
(in addition to the issue notified in the first point).
3/ Finally, if you want to edit any of the drawn objects using the GUI editor the following issue occurs : you have “click access” to nothing but the second pad and the last drawn object (in this example the additional axis, but if you don’t draw it the second TF1, etc.).
Any suggestion or comment ? Thanks.
PS : I’m using ROOT 5.26/00, trunk@31882.