Jupyter Lab not plotting canvas

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

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 (4.6 KB)

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

Try drawing the canvas in addition to the histogram.

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

Canvas should be drawn after histogram

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 :slight_smile:

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

Did you find any solution?

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

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

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)?

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

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