Hi Jacek,
On Mon, 18 Feb 2002, Jacek M. Holeczek wrote:
> Question One :
> I create some TGraphs in a subroutine.
> By default these TGraphs are not owned by anything. As soon as I exit the
> subroutine they are lost (in principle this generates a "memory leak").
> In order to be able to FindObject("MyGraph") from outside of my subroutine
> I gROOT->Append(MyGraph") in my subroutine. This almost works. I am able
> to find these TGraphs by "Name", but ... as soon as I MyGraph->Draw() and
> then gPAD->Clear() they are lost again. Is there any easy way to protect
> MyGraph from this (the MyGraph->ResetBit(kCanDelete) does not help) ?
>
I do not understand this problem. You do not need to reset the bit
kCanDelete (unless you have used DrawGraph). gPad->Clear() should not
delete your graph.
> Question Two :
> I have a couple of TGraphs. Two of them are MinValue and MaxValue.
> Now I would like to draw a "gray band" in my TCanvas between MinValue and
> MaxValue (and then the rest of my graphs would be drawn on "top" of it.)
> How can I draw such a "gray band" ?
Here is an example
void grshade() {
TCanvas *c1 = new TCanvas("c1","A Simple Graph
Example",200,10,700,500);
c1->SetGrid();
c1->DrawFrame(0,0,2.2,12);
const Int_t n = 20;
Double_t x[n], ymin[n], ymax[n];
Int_t i;
for (i=0;i<n;i++) {
x[i] = 0.1+i*0.1;
ymax[i] = 10*sin(x[i]+0.2);
ymin[i] = 8*sin(x[i]+0.1);
y[i] = 9*sin(x[i]+0.15);
}
TGraph *grmin = new TGraph(n,x,ymin);
TGraph *grmax = new TGraph(n,x,ymax);
TGraph *gr = new TGraph(n,x,y);
TGraph *grshade = new TGraph(2*n);
for (i=0;i<n;i++) {
grshade->SetPoint(i,x[i],ymax[i]);
grshade->SetPoint(n+i,x[n-i-1],ymin[n-i-1]);
}
grshade->SetFillStyle(3013);
grshade->SetFillColor(16);
grshade->Draw("f");
grmin->Draw("l");
grmax->Draw("l");
gr->SetLineWidth(4);
gr->SetMarkerColor(4);
gr->SetMarkerStyle(21);
gr->Draw("CP");
}
Rene Brun
>
> Thanks in advance,
> Jacek.
>
This archive was generated by hypermail 2b29 : Sat Jan 04 2003 - 23:50:42 MET