setTitle xaxis/yaxis for a TMultiGraph object

Hi
I am trying to set the title when I am piling up my TGraphs objects in a TMultiGraph object, but honestly, I do not have clear how to set up the tiltel of the output plot.
This is a chucnk of my code and then at the end you will see what I tried to set up the title. How should I do it?

Cristian

TMultiGraph *mg = new TMultiGraph();

for (Int_t ii=1;ii<PK_A;ii=ii+3){
for (Int_t jj=1;jj<=cplots;jj++){
if (x[jj]!=0){
y[jj] = fitResults[jj][ii];
volts[jj]=x[jj];
}
}
gr=new TGraph(cplots,volts,y);
mg->Add(gr);
}
//nothing happens
xaxis = gr->GetXaxis();
xaxis->SetTitle(“Voltage [kV]”);
yaxis = mg->GetYaxis();
gr->SetTitle(“Peak position”);

mg->Draw(“ap*l”)

after the Draw() of mg do:

mg->GetXaxis()->SetTitle("aaa");

If you want to change the top title simply do:

mg->SetTitle("AAA");

Hi

I did it after draw():
mg->GetXaxis()->SetTitle(“aaa”);
but it did not work. Do I have to Update? How do I do that?
Thxs,
Cristian

Put gPad->Update() just after mg->Draw()

I was trying this:
TH1F *h2 = mg->getHistogram();
since TH1F inherits TH1 then I was thinking I could do this:
h2->SetXTitle(“aaaaa”);
but it does not work. It says the class or structure does not exist.

Please note at the end of the post I copy a chunk of the doc related to the TMultiGraph object. In the last line they mention how to get axis to the axis of the object, and it is this te reason of my first few lines of my post. However it did not work? Any idea how can I get axis to the protected data fHistogram?
Cristian

--------------------------ROOT documents from the web
----------------http://www.slac.stanford.edu/comp/unix/package/cernroot/30106/TMultiGraph.html#TMultiGraph:TMultiGraph

class TMultiGraph : public TNamed

private:


public:

      TMultiGraph TMultiGraph()
      TMultiGraph TMultiGraph(const char* name, const char* title)
      TMultiGraph TMultiGraph(TMultiGraph&)
     virtual void ~TMultiGraph()
     virtual void Add(TGraph* graph)
     virtual void Browse(TBrowser* b)
   static TClass* Class()
    virtual Int_t DistancetoPrimitive(Int_t px, Int_t py)
     virtual void Draw(Option_t* chopt)
            TH1F* GetHistogram() const
           TList* GetListOfGraphs() const
           TAxis* GetXaxis() const
           TAxis* GetYaxis() const
  virtual TClass* IsA() const
     virtual void Paint(Option_t* chopt)
     virtual void Print(Option_t* chopt) const
     virtual void SavePrimitive(ofstream& out, Option_t* option)
     virtual void SetMaximum(Double_t maximum = -1111)
     virtual void SetMinimum(Double_t minimum = -1111)
     virtual void ShowMembers(TMemberInspector& insp, char* parent)
     virtual void Streamer(TBuffer& b)
             void StreamerNVirtual(TBuffer& b)

Data Members

private:


protected:

    TList* fGraphs     Pointer to list of TGraphs
     [b]TH1F* fHistogram  Pointer to histogram used for drawing axis[/b]

Sorry, this did not work either. Going for lunch… ttyl.
Cristian

ok this works:

{
   c1 = new TCanvas("c1","multigraph",200,10,700,500);

   TMultiGraph *mg = new TMultiGraph();

   // create first graph
   Int_t n1 = 10;
   Double_t x1[]  = {-0.1, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
   Double_t y1[]  = {-1,2.9,5.6,7.4,9,9.6,8.7,6.3,4.5,1};
   Double_t ex1[] = {.05,.1,.07,.07,.04,.05,.06,.07,.08,.05};
   Double_t ey1[] = {.8,.7,.6,.5,.4,.4,.5,.6,.7,.8};
   gr1 = new TGraphErrors(n1,x1,y1,ex1,ey1);
   gr1->SetMarkerColor(kBlue);
   gr1->SetMarkerStyle(21);
   gr1->Fit("pol6","q");
   mg->Add(gr1);

   // create second graph
   Int_t n2 = 10;
   Float_t x2[]  = {-0.28, 0.005, 0.19, 0.29, 0.45, 0.56,0.65,0.80,0.90,1.01};
   Float_t y2[]  = {2.1,3.86,7,9,10,10.55,9.64,7.26,5.42,2};
   Float_t ex2[] = {.04,.12,.08,.06,.05,.04,.07,.06,.08,.04};
   Float_t ey2[] = {.6,.8,.7,.4,.3,.3,.4,.5,.6,.7};
   gr2 = new TGraphErrors(n2,x2,y2,ex2,ey2);
   gr2->SetMarkerColor(kRed);
   gr2->SetMarkerStyle(20);
   gr2->Fit("pol5","q");

   mg->Add(gr2);

   mg->Draw("ap");

     //force drawing of canvas to generate the fit TPaveStats
   mg->GetXaxis()->SetTitle("X axis title");
   gPad->Modified();
}

For some reason now it works. Thxs!
Cristian