# Jupyter Lab not plotting canvas

**URL:** <https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190>\
**Category:** ROOT\
**Tags:** python, jupyter\
**Created:** [May 2, 2024, 9:18am UTC](https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190 "2024-05-02T09:18:42Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![mole.luca](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mole.luca/32/25073_2.png) [@mole.luca](https://root-forum.cern.ch/u/mole.luca)\
**Post date:** [May 2, 2024, 9:18am UTC](https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190/1 "2024-05-02T09:18:42Z")

</div>

Hi.  
I am using Jupyter Lab and I cannot see canvases when doing a simple plot as in the code below. I attach the text input file.  
Thank you

```auto
import ROOT
import os, sys
import numpy as np
import pandas as pd

%jsroot on
filename= './spectra/data/240326/240326_HV_0_0_-1700_-2200_amp_0-5us_100x0002.mca'
if os.path.isfile(filename):
  print ("Loading file: "+filename)
else:
  print ("File not found")

np_data= np.loadtxt(filename, delimiter= "\t", skiprows=12, max_rows= 1024)

h0 = ROOT.TH1D( 'h0', 'V2= 0V', 1024, 0, 1023 )

for bin in range(len(np_data)):
  h0.SetBinContent(bin, np_data[bin])

c = ROOT.TCanvas("spectra","G~10^3",800,600)
h0.Draw()

```

[240326\_HV\_0\_0\_-1700\_-2200\_amp\_0-5us\_100x0002.txt](https://root-forum.cern.ch/uploads/short-url/pgdWjnkoeolMuDl2AAUm1VRjayS.txt) (4.6 KB)

ROOT Version: 6.22/06  
Platform: Jupyter Lab on Mac  
Compiler: Python 3.9.1

---

<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:** [May 2, 2024, 10:09am UTC](https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190/2 "2024-05-02T10:09:27Z")

</div>

Try drawing the canvas in addition to the histogram.

```auto
c = ROOT.TCanvas("spectra","G~10^3",800,600)
h0.Draw()
c.Draw()

```

---

<div class="post-metadata">

**Author:** ![linev](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/l/2bfe46/32.png) [@linev](https://root-forum.cern.ch/u/linev)\
**Post date:** [May 2, 2024, 10:32am UTC](https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190/3 "2024-05-02T10:32:36Z")

</div>

Canvas should be drawn after histogram

---

<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:** [May 2, 2024, 10:48am UTC](https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190/4 "2024-05-02T10:48:36Z")

</div>

Drawing the canvas first worked for me, but maybe because it’s a simple case; I edited the code above, if this is the proper way 🙂

---

<div class="post-metadata">

**Author:** ![mole.luca](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mole.luca/32/25073_2.png) [@mole.luca](https://root-forum.cern.ch/u/mole.luca)\
**Post date:** [May 2, 2024, 10:54am UTC](https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190/5 "2024-05-02T10:54:21Z")

</div>

> [@mole.luca](#):
>
> ```auto
> %jsroot on
> filename= './spectra/data/240326/240326_HV_0_0_-1700_-2200_amp_0-5us_100x0002.mca'
> if os.path.isfile(filename):
> print ("Loading file: "+filename)
> else:
> print ("File not found")
> 
> np_data= np.loadtxt(filename, delimiter= "\t", skiprows=12, max_rows= 1024)
> 
> h0 = ROOT.TH1D( 'h0', 'V2= 0V', 1024, 0, 1023 )
> 
> for bin in range(len(np_data)):
> h0.SetBinContent(bin, np_data[bin])
> 
> c = ROOT.TCanvas("spectra","G~10^3",800,600)
> h0.Draw()
> 
> ```

Hi.  
Thank you for your suggestions. This partly worked. Now there is some drawing happening, but the result is a blank space. Any further suggestion?  
Thank you

---

<div class="post-metadata">

**Author:** ![Slicesed](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/cab0a1/32.png) [@Slicesed](https://root-forum.cern.ch/u/Slicesed)\
**Post date:** [May 6, 2024, 9:15am UTC](https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190/6 "2024-05-06T09:15:35Z")

</div>

Did you find any solution?

---

<div class="post-metadata">

**Author:** ![vpadulan](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/vpadulan/32/25315_2.png) [@vpadulan](https://root-forum.cern.ch/u/vpadulan)\
**Post date:** [May 6, 2024, 9:23am UTC](https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190/7 "2024-05-06T09:23:25Z")

</div>

EDIT: I realized my answer is exactly the same as @dastudillo 's, that is drawing the canvas after the histogram. Yet in your latest post that is not shown. Did you try it in the end?

One other thing to try would be `histo.DrawClone` instead of `Draw`

Cheers,  
Vincenzo

---

<div class="post-metadata">

**Author:** ![mole.luca](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mole.luca/32/25073_2.png) [@mole.luca](https://root-forum.cern.ch/u/mole.luca)\
**Post date:** [May 6, 2024, 11:36am UTC](https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190/8 "2024-05-06T11:36:23Z")

</div>

Hi. Thank you for following up.  
Unfortunately I did not find a solution. The suggested things did not change the situation. I tried all the combinations of `Draw` and `DrawClone` and exchanging the order of `Canvas` and `Histo`. Still getting only blank space.  
Cheers  
Luca

---

<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:** [May 6, 2024, 11:41am UTC](https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190/9 "2024-05-06T11:41:49Z")

</div>

For me it worked as I mentioned, so if it doesn’t for you, maybe the issue is not in ROOT. By the way, your code tries to read a file with extension .mca but the data file is .txt; are you reading the correct file (and location)?

 ![image](https://root-forum.cern.ch/uploads/default/original/3X/8/3/8316fb51a7bf807eb0d64759c6b7f975212bc80a.png)

---

<div class="post-metadata">

**Author:** ![mole.luca](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mole.luca/32/25073_2.png) [@mole.luca](https://root-forum.cern.ch/u/mole.luca)\
**Post date:** [May 6, 2024, 12:18pm UTC](https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190/10 "2024-05-06T12:18:05Z")

</div>

Thank you, then the problem might not be ROOT indeed… any idea what else could I check?  
Yes, the file is correct.  
Cheers

---

<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:** [May 20, 2024, 12:18pm UTC](https://root-forum.cern.ch/t/jupyter-lab-not-plotting-canvas/59190/11 "2024-05-20T12:18:08Z")

</div>

Closed on May 20, 2024, 12:18pm UTC

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