# Histogram not displaying after program finishes running

**URL:** <https://root-forum.cern.ch/t/histogram-not-displaying-after-program-finishes-running/58453>\
**Category:** ROOT\
**Tags:** graphics, hist\
**Created:** [March 9, 2024, 2:21pm UTC](https://root-forum.cern.ch/t/histogram-not-displaying-after-program-finishes-running/58453 "2024-03-09T14:21:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hoang\_Nguyen](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/hoang_nguyen/32/35879_2.png) [@Hoang\_Nguyen](https://root-forum.cern.ch/u/Hoang_Nguyen)\
**Post date:** [March 9, 2024, 2:21pm UTC](https://root-forum.cern.ch/t/histogram-not-displaying-after-program-finishes-running/58453/1 "2024-03-09T14:21:51Z")

</div>

```cpp
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#define pi 3.14159
using namespace std;
void bai1()
 {
    double x1, y1, x2, y2, z2, r1, r2, r3, theta, phi, r;
    double z1 = 0;    

    TH3F* h1 = new TH3F("h1", "1a", 50, -5, 5, 50, -5, 5, 50, -5, 5 );
    TH3F* h2 = new TH3F("h2", "1b", 100, -5, 5, 100, -5, 5, 100, -5, 5 );

    srand(time(NULL)); //Hàm khởi tạo số ngẫu nhiên
    
    int a = -1;
    int b = 1;
    
   for(int i=1;i<10000;i++)
    { 

      r1 = double(rand())/RAND_MAX;
      r2 = double(rand())/RAND_MAX;
      r3 = double(rand())/RAND_MAX;
      
      // a,
      x1 = r1*(b-a) + a;
      y1 = r2*(b-a) + a;
      if(x1*x1 + y1*y1< 1)
        {
          h1->Fill(x1, y1, z1);
        }

      // b,
      r = r1;
      theta = r2*pi;
      phi = r3*2*pi;
      
      x2 = r * sin(theta) * cos(phi);
      y2 = r * sin(theta) * sin(phi);
      z2 = r * cos(theta);

      h2->Fill(x2,y2,z2);

    }
      
    TCanvas *c1 = new TCanvas("c1", "bai1 a", 800, 700);
    h1->Draw();
    TCanvas *c2 = new TCanvas("c2", "bai1 b", 800, 700);  
    h2->Draw(); 
 }

```

Thats my code, when I run `root bai1.C`, it just says it’s done and doesn’t show any histograms. (I’m running through WSL)\*\*

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [March 9, 2024, 3:06pm UTC](https://root-forum.cern.ch/t/histogram-not-displaying-after-program-finishes-running/58453/2 "2024-03-09T15:06:26Z")

</div>

Dear Hoang,

Thanks for the post and welcome to the ROOT community!

I ran the macro with this command `root -l ba1.C` as well as copied-pasted the code in the root prompt and I see a nice 3D plot. How do you execute the code ?

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![Hoang\_Nguyen](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/hoang_nguyen/32/35879_2.png) [@Hoang\_Nguyen](https://root-forum.cern.ch/u/Hoang_Nguyen)\
**Post date:** [March 10, 2024, 3:07pm UTC](https://root-forum.cern.ch/t/histogram-not-displaying-after-program-finishes-running/58453/3 "2024-03-10T15:07:41Z")

</div>

**Dear Danilo,**

I apologize if my English is not very good. I know that my code runs well and has no errors. However, I would like to ask if there is something wrong with the software, because it cannot run “geometry” such as TCanvas or histograms.

I have tried uninstalling and reinstalling Ubuntu, ROOT, and WSL to fix this problem, but still have not been successful. Could you please help me solve this problem?

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/6/a/6ab3a713820fedd595b9ef7011aa1b17d4705fb9.jpeg)

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [March 10, 2024, 5:02pm UTC](https://root-forum.cern.ch/t/histogram-not-displaying-after-program-finishes-running/58453/4 "2024-03-10T17:02:29Z")

</div>

Dear Hoang,

No worries for your English: it’s very clear!!  
I missed this is WSL. I add @bellenot in the loop given his consolidated expertise with the Windows OS.

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![dastudillo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/dastudillo/32/17280_2.png) [@dastudillo](https://root-forum.cern.ch/u/dastudillo)\
**Post date:** [March 11, 2024, 6:29am UTC](https://root-forum.cern.ch/t/histogram-not-displaying-after-program-finishes-running/58453/5 "2024-03-11T06:29:03Z")

</div>

Are you running an Xserver? Try this:

> [@Root Installation on WSL Ubuntu](https://root-forum.cern.ch/t/root-installation-on-wsl-ubuntu/42634/6):
>
> WSL does not have a graphics server. You need to install (and keep running) an X server like Xming or [VcXsrv](https://sourceforge.net/projects/vcxsrv/), and add this line at the end of your ~/.bashrc export DISPLAY=localhost:0

(the X server has to be running before you open a WSL terminal).  
More here:

> [@ROOT on Windows 11 WSL2 / WSLg](https://root-forum.cern.ch/t/root-on-windows-11-wsl2-wslg/48348):
>
> Dear experts/developers, I installed the latest ROOT (6.24/06) on a Windows 11 with WSL2 (which has native GUI support) and found a weird problem with graphics. Some details: It is not a fresh Windows, but updated from W10, although it did not have WSL installed before, so it is a fresh WSL install. As per the recommended ROOT instructions with this post from @James-Carroll and MicroSoft’s instructions for WSL, I did this (with reboots where needed): Turned on these Windows features: “…

---

<div class="post-metadata">

**Author:** ![Hoang\_Nguyen](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/hoang_nguyen/32/35879_2.png) [@Hoang\_Nguyen](https://root-forum.cern.ch/u/Hoang_Nguyen)\
**Post date:** [March 12, 2024, 3:17pm UTC](https://root-forum.cern.ch/t/histogram-not-displaying-after-program-finishes-running/58453/6 "2024-03-12T15:17:51Z")

</div>

Thank you, I tried installing vcXsrv and it really works.

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [March 26, 2024, 3:18pm UTC](https://root-forum.cern.ch/t/histogram-not-displaying-after-program-finishes-running/58453/7 "2024-03-26T15:18:00Z")

</div>

Closed on March 26, 2024, 3:18pm UTC

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
