How to draw TMultiGraph object more then one time

Hi Rooters,

I have the problem with TMultiGraph class. If I add new TGraph object to the TMultiGraph, which was drawn then when TMultiGraph is drawn next time the new TGraph may be out of screen partly. I believe that it calculates the axis limits during the first drawing and does not change them in the second drawing. As I understood correctly if TMultiGraph will be deleted then added TGraph objects will be deleted also. Then I can not simply recreate this object and add all TGraph objects when the new TGraph is created.
What can be recommended?
Thanks in advance.
Andrey

A short running script showing the problem would be better than 1000 words ::slight_smile:

Rene

Of course I checked how it works in the macro before use it in the code. All worked. I have this problem when it is used in the standalone code with GUI. I attached header file of my class and method that create new TGraph and add it to the TMultiGraph. The method is called in answer on key push. In the first call it draws the correct graph. In the second call it draws the first graph and only part of the second graph. If I changed the order of graph ploting and draw the second graph in the first call it will be correct.
ExecDrawadd24().cpp (608 Bytes)
GG_MainFrame.h (2.16 KB)

One more comment. If in the standalone code I save additional copies of my TGraph objects and fill TMultiGraph using them all works. What I means.

class A
{
private:
TGraph *pGR[10];
TGraph *pGRsave[10];
TMultiGraph *pMGR;
int iGR;
};
A:A()
{
iGR = 0;
}
void A::AddGR()
{
if(iGR == 10) return;
int n =1000;
double x[1000],y[1000];
if(pMGR)
{
delete pMGR;
pMGR = NULL;
}
Calc(n,x,y); //== Some code filling x and y arrays
pMGR = new TMultiGraph();
pGRsave[iGR++] = new TGraph(n,x,y);

for(i=0; i < iGR; ++i)

{
pGR = new TGraph(*pGRsave[i]);
pMGR->Add(pGR[i]);
}
pMGR->Draw();
}

but if I create TMultiGraph object in the construction and add TGraph by one like the next example it does not work

class B
{
private:
TGraph *pGR[10];
TMultiGraph *pMGR;
int iGR;
};
B:B()
{
pMGR = new TMultiGraph();
iGR = 0;
}
void B::AddGR()
{
if(iGR == 10) return;
int n =1000;
double x[1000],y[1000];
Calc(n,x,y); //== Some code filling x and y arrays

pGR[iGR] = new TGraph(n,x,y);
pMGR->Add(pGR[iGR++]);
pMGR->Draw();

}

More correctly it works like it was described in the previous message.

Andrey

Hi Andrey,

To understand your problem please attach the macro that works and does what you want in interactive mode (but its code cannot be run in your standalone application with the GUI). In addition, tell us how your method ExecDrawadd24() is connected to respond to the user interaction (to answer on key push).

Cheers, Ilka

Hi Ilka,

I wrote a short macro that makes the same as my standalone code with the same bad result.

Method “ExecDrawadd24()” is called using TGTextButton class.

In the class header I have:
TGTextButton *fTBdraw24;

In the class constructor I have:
fTBdraw24 = new TGTextButton(fVDH2,“DRAW A2/A4”);
fTBdraw24->Connect(“Clicked()”,“GG_MainFrame”, this, “ExecDrawadd24()”);

Best regards,
Andrey
testa.c (105 Bytes)
a.cpp (541 Bytes)

Hi Andrey,

Thank you for the provided example. From the point of GUI, I will suggest to set the widget ID in the TGTextButton constructor (the third parameter). This way you have control to check from which widget a signal is emitted. For example: TGButton *btn = (TGButton *) gTQSender; id = btn->WidgetId(); if (id ==kMyButton) { // do something because the signal is set from my button }
For the rest my colleague will investigate further.

Cheers, Ilka

Try this:
testa.c (99 Bytes)
a.cpp (588 Bytes)

Hi Couet,

Your example is not correct. In the full code I would like to see the first plot after that change some parameters and draw the second plot. Your example equals to
TMultiGraph *pMG = new TMultiGraph();
TGraph *pG1 = new TGraph(n,x,y1);
TGraph *pG1 = new TGraph(n,x,y2);
pMG->Add(pG1);
pMG->Add(pG2);
pMG->Draw(“LA”);
and it is a usual using of TMultiGraph class.
Thus it is not an answer.
More simple try to use the next commands wth my class
.L a.cpp
A a
a.d1(0)
//== here I see the first plot
a.d1(10)
//== and more interesting
a.d1(2) //== you will see part of the second plot

Best regards,
Andrey

Ok I see. I will check this more closely. I think your way does not work because when you do some intermediate plot it creates internally an histo (with some coordinates) which is not deleted when new graphs are added. And I think it should be in order to cope with the new coordinates which may end up when a graph has been added. I will have a closer look. I’ll let you know.

Let me make a small comment may be it will help. The problem arise when TMultiGraph is used in the class. Look on the attached example it works. But I can not use this variant in the standalone code, where TMultiGraph is a member of my class.

In principal I solved this problem using the copies of all TGraph objects. Then when it is necessary to add a new graph I delete TMultiGraph object, create new one and add all graphs to it in one place then they are drawing Ok. But it seems not very good to delete and create object more often then it is necessary and to save copies of TGraph objects.
The copies are necessary because as I understood from the manual correctly TMultiGraph delete all TGraph added to it. Is it correct? If it is not so then I can exclude copy of TGraph objects from the code.

Andrey
d1test.c (198 Bytes)
d1.cpp (236 Bytes)