# Plots NOT being displayed through evolving data sets

**URL:** <https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716>\
**Category:** Newbie\
**Created:** [June 2, 2020, 1:12am UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716 "2020-06-02T01:12:19Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![rraut](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/eb9ed0/32.png) [@rraut](https://root-forum.cern.ch/u/rraut)\
**Post date:** [June 2, 2020, 1:12am UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/1 "2020-06-02T01:12:20Z")

</div>

I’m a complete novice in ROOT and I apologize if the following query  
happens to be a misplaced one.

I’m trying to read/calculate data points for three plots in one canvas.  
(Actually, the data points are directly read from the inout file for one plot  
and the data points for the other two are calculated therefrom.)

The data points in the input file are arranged in individual sets.

The plots do show up fine for the first set. Thereafter when I ask the  
code to go back reading/calculating the data points for the next set,  
the old plots, expectedly, vanish but the new plots do not display.  
However, I have indicators to show that the data points  
are being read and calculated for the subsequent sets as well  
but the display shows only a blank canvas.

This continues through the subsequent sets of data points until  
I opt out of reading another set and then the last read/calculated set  
of plots show up.

The snippet of the code, in a schematic way, is included herewith.

readdata:

```auto
// READING/CALCULATING ONE SET OF DATA POINTS CORRESPONDING TO THREE PLOTS.

// DONE WITH READING/CALCULATING ONE SET OF DATA POINTS

//PLOTTING IN ROOT

TCanvas* draw_trace = new TCanvas("draw_trace","TRACE OF THE PULSE",200,10,600,400);
draw_trace->Divide(1,3);

TGraph* raw_trace = new TGraph(nlines,x,y);
TGraph* ff_trace = new TGraph(nlines1,xff,yff);
TGraph* cfd_trace = new TGraph(nlines2,xcfd,ycfd);

draw_trace->cd(2);
raw_trace -> SetMarkerStyle(7);
raw_trace -> SetMarkerSize(5.0);
raw_trace -> SetMarkerColor(4);
raw_trace -> Draw("AP");

draw_trace->cd(1);
ff_trace -> SetMarkerStyle(7);
ff_trace -> SetMarkerSize(5.0);
ff_trace -> SetMarkerColor(4);
ff_trace -> Draw("AP");

draw_trace->cd(3);
cfd_trace -> SetMarkerStyle(7);
cfd_trace -> SetMarkerSize(5.0);
cfd_trace -> SetMarkerColor(4);
cfd_trace -> Draw("AP");

gPad->Modified();
gPad->Update();

//ASKING THE USER IF ANOTHER SET OF DATA POINTS ARE TO BE READ/CALCULATED

printf("Do you want to read another trace ?\n"); scanf("%d", &optread);
if(optread == 1)
           {
            goto readdata;
           }

//IF THE ANSWER IS IN AFFIRMATIVE, WE GO BACK TO READ THE NEXT SET OF DATA POINTS

```

I’m using ROOT Version 6.14/04.

I shall gratefully appreciate any guidance from this community.

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [June 2, 2020, 2:31pm UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/2 "2020-06-02T14:31:54Z")

</div>

@couet can you give a hand with this? Thanks!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 2, 2020, 2:46pm UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/3 "2020-06-02T14:46:35Z")

</div>

On which platform ?

try to update the full canvas:

```auto
draw_trace->Modified();
draw_trace->Update();

```

---

<div class="post-metadata">

**Author:** ![rraut](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/eb9ed0/32.png) [@rraut](https://root-forum.cern.ch/u/rraut)\
**Post date:** [June 2, 2020, 6:19pm UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/4 "2020-06-02T18:19:17Z")

</div>

Thank you very much for your suggestion. However, I’m afraid, the problem persists even after implementing the change.

I’m working on Linux Fedora 25.

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 3, 2020, 6:29am UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/5 "2020-06-03T06:29:48Z")

</div>

Can you provide a small reproducer ?

---

<div class="post-metadata">

**Author:** ![rraut](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/eb9ed0/32.png) [@rraut](https://root-forum.cern.ch/u/rraut)\
**Post date:** [June 3, 2020, 7:09pm UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/6 "2020-06-03T19:09:53Z")

</div>

![rraut_code1](https://root-forum.cern.ch/uploads/default/original/3X/c/d/cd90f06e1d435c714a7d88e04b6ea57e0ad9c5db.png)

I realize that I might not be providing sufficient info to facilitate a solution and do apologize for the same. The data files on which the code works are inconveniently sized for sharing.

In the absence of such options, I’m uploading the screenshots that might represent the problem. The upper panel corresponds to the display and the command window after the first set of data points are read/calculated while the lower panel corresponds to the (blank) display and the command window that I see on trying to plot the second set.

May I also mention that I’m compiling this code with,

g++ -o trace6 trace6.cpp `root-config --cflags --libs`

and using it thereafter.

Please let me know if I should provide additional info in order to enable a solution. Deeply appreciating your inputs.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 3, 2020, 7:13pm UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/7 "2020-06-03T19:13:30Z")

</div>

> [@Drawing histograms on a TCanvas in a Loop](https://root-forum.cern.ch/t/drawing-histograms-on-a-tcanvas-in-a-loop/38050):
>
> Hi I’m trying to compare 2 histograms visually. When drawing single histograms on a single canvas (or different canvases also) I have no problem. However, if I try to do it in a loop (try to change histograms through the time) - there is a problem: I can’t close the canvas with ‘x’ There is no ‘menu bar’ I can’t zoom in / zoom out Basically, I can do nothing - there is just picture of histograms I can change method and try not to use for and while loop, but is there a way to fix this? Als…

---

<div class="post-metadata">

**Author:** ![rraut](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/eb9ed0/32.png) [@rraut](https://root-forum.cern.ch/u/rraut)\
**Post date:** [June 4, 2020, 12:56am UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/8 "2020-06-04T00:56:33Z")

</div>

I’m extremely sorry but I could not make this fit in the context of my problem. This is owing to my own deficiencies in this domain and I remain apologetic for the same.

Could you please elaborate on the solution ?

And I shall also remain eager to see what @couet has to say.

Gratitude !

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 4, 2020, 7:09am UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/9 "2020-06-04T07:09:29Z")

</div>

I think the link @Wile_E_Coyote sent you might allow you to draw this histograms in a loop.  
Have you tried to use your code in ROOT interpreted ?  
When I asked you for a 'reproducer" it was just a small macro we could run interactively reproducing the logic of your code. The one you sent initially cannot be used as it is (there is a lot missing).

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 4, 2020, 8:34am UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/10 "2020-06-04T08:34:11Z")

</div>

@couet It seems to me that this is a classical problem of "blocking I/O” (the same as in [the thread I mentioned in my previous post](https://root-forum.cern.ch/t/drawing-histograms-on-a-tcanvas-in-a-loop/38050)).

@rraut If you do not want to solve it properly, you can try a “brutal fix” (which may or may not work) … after the last “Update” call (and / or before you start to wait for user’s input), add:

```cpp
gSystem->ProcessEvents(); gSystem->Sleep(100); gSystem->ProcessEvents(); gSystem->Sleep(100); gSystem->ProcessEvents();

```

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [June 4, 2020, 8:45am UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/11 "2020-06-04T08:45:50Z")

</div>

@Wile_E_Coyote seems to me also.

---

<div class="post-metadata">

**Author:** ![rraut](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/eb9ed0/32.png) [@rraut](https://root-forum.cern.ch/u/rraut)\
**Post date:** [June 5, 2020, 1:52am UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/12 "2020-06-05T01:52:51Z")

</div>

[trace6\_forum.cpp](https://root-forum.cern.ch/uploads/short-url/114FyhVL4BteJe8yrPZGmlP1V9d.cpp) (9.9 KB)

Thank you very much for your kind inputs and observations. I’m grateful !

I did use the ROOT interpreter but that did not help.

I was sort of hesitant to upload the code since the same, owing to my very modest programming caliber, might look too naive in this forum.

I’m uploading the entire code (including the “brutal fix”, as suggested by @Wile_E_Coyote) herewith.  
There are a lot of additional variables inside the code that are not being used. This is because the code is edited from a different (and more elaborate) one.

The “brutal fix” suggested by @[Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote) did work to a large extent. However, it did not allow me to operate (zoom etc.) on the graphics window until I opted out of doing another data set.

Thank you very much for everything.

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [June 5, 2020, 3:21pm UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/13 "2020-06-05T15:21:31Z")

</div>

The “proper fix” would be to create a GUI button or a new menu entry (e.g. added to your canvas) which the user could “click” on demand (in any case, you must not use any “blocking I/O”). Maybe @bellenot has some example how to do it.

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 5, 2020, 3:33pm UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/14 "2020-06-05T15:33:48Z")

</div>

One cannot add menu buttons or menu entries in an existing canvas, but maybe using [`TPad::WaitPrimitive()`](https://root.cern.ch/doc/master/classTPad.html#ab46ccbf6950adac842fed22cd4eb7e46) could help? (maybe @couet knows better if it can work…)  
Otherwise you could also create your own GUI with embedded canvas(es)

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 5, 2020, 3:35pm UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/15 "2020-06-05T15:35:56Z")

</div>

Well, maybe there is another solution, something like the [customContextMenu.C](https://root.cern/doc/master/customContextMenu_8C.html) tutorial

---

<div class="post-metadata">

**Author:** ![bellenot](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/bellenot/32/29217_2.png) [@bellenot](https://root-forum.cern.ch/u/bellenot)\
**Post date:** [June 5, 2020, 4:04pm UTC](https://root-forum.cern.ch/t/plots-not-being-displayed-through-evolving-data-sets/39716/16 "2020-06-05T16:04:57Z")

</div>

Sorry, I was wrong (but I tried anyway). Here is how to add a custom menu entry on a Canvas’ menu bar:

```auto
void menu_slot(Int_t id)
{
   if (id == 1001)
      new TGMsgBox(gClient->GetRoot(), gClient->GetRoot(), "menu_slot",
                   "Received a signal from the menu entry with id 1001",
                   kMBIconExclamation, kMBOk);
}

TCanvas *test_addmenu()
{
   TCanvas *c = new TCanvas("c", "c");
   TRootCanvas *rcanvas = (TRootCanvas *)c->GetCanvasImp();
   TGMenuBar *menubar = rcanvas->GetMenuBar();
   TGPopupMenu *myMenu = new TGPopupMenu(gClient->GetRoot());
   myMenu->AddEntry("My &Custom Action", 1001);
   myMenu->Connect("Activated(Int_t)", 0, 0, "menu_slot(Int_t)");
   menubar->AddPopup("&My Custom Menu", myMenu, new TGLayoutHints());
   menubar->Layout();
   return c;
}

```
