Skip to content

ROOT.TColor.DefinedColors(1) problematic in jupyter notebooks #20018

@andrzejnovak

Description

@andrzejnovak

Check duplicate issues.

  • Checked for duplicates

Description

The following code runs fine as a script but throws an error in jupyter notebook. The issue is seemingly caused by the first line ROOT.TColor.DefinedColors(1). Thanks to @oglez for tracking it down.

Reproducer

import ROOT
# Create a canvas
ROOT.TColor.DefinedColors(1)
c = ROOT.TCanvas("c", "Basic ROOT Plot", 800, 600)

# Create a histogram with 100 bins from 0 to 10
h = ROOT.TH1F("h", "Example Histogram;X axis;Entries", 100, 0, 10)

# Fill histogram with random Gaussian numbers
for _ in range(10000):
    h.Fill(ROOT.gRandom.Gaus(5, 1))

# Draw the histogram
h.Draw()

# Show canvas inline in Jupyter
c.Draw()

ROOT version

6.34 (also .32 and .36) as reportedly

Installation method

conda

Operating system

Windows (WSL)

Additional context

Trace
---------------------------------------------------------------------------
SegmentationViolation                     Traceback (most recent call last)
File ~/software/miniforge3/envs/def/lib/python3.12/site-packages/JupyROOT/helpers/utils.py:471, in CaptureDrawnPrimitives._post_execute(self)
    470 def _post_execute(self):
--> 471     NotebookDraw()

File ~/software/miniforge3/envs/def/lib/python3.12/site-packages/JupyROOT/helpers/utils.py:460, in NotebookDraw()
    458 def NotebookDraw():
    459     DrawGeometry()
--> 460     DrawCanvases()
    461     DrawRCanvases()

File ~/software/miniforge3/envs/def/lib/python3.12/site-packages/JupyROOT/helpers/utils.py:451, in DrawCanvases()
    449 drawers = GetCanvasDrawers()
    450 for drawer in drawers:
--> 451     drawer.Draw()

File ~/software/miniforge3/envs/def/lib/python3.12/site-packages/JupyROOT/helpers/utils.py:647, in NotebookDrawer.Draw(self)
    646 def Draw(self):
--> 647     self._display()
    648     return 0

File ~/software/miniforge3/envs/def/lib/python3.12/site-packages/JupyROOT/helpers/utils.py:633, in NotebookDrawer._display(self)
    631 else:
    632   if self._canJsDisplay():
--> 633      self._jsDisplay()
    634   else:
    635      self._pngDisplay()

File ~/software/miniforge3/envs/def/lib/python3.12/site-packages/JupyROOT/helpers/utils.py:597, in NotebookDrawer._jsDisplay(self)
    595 name = self._getDrawId()
    596 updated = self._getUpdated()
--> 597 jsdiv = self._getJsDiv()
    598 if name and (name in _canvasHandles) and updated:
    599     _canvasHandles[name].update(jsdiv)

File ~/software/miniforge3/envs/def/lib/python3.12/site-packages/JupyROOT/helpers/utils.py:576, in NotebookDrawer._getJsDiv(self)
    575 def _getJsDiv(self):
--> 576     return display.HTML(self._getJsCode())

File ~/software/miniforge3/envs/def/lib/python3.12/site-packages/JupyROOT/helpers/utils.py:550, in NotebookDrawer._getJsCode(self)
    548     json = self.drawableObject.CreateJSON()
    549 else:
--> 550     json = produceCanvasJson(self.drawableObject).Data()
    552 divId = self._getUniqueDivId()
    554 width = _jsCanvasWidth

File ~/software/miniforge3/envs/def/lib/python3.12/site-packages/JupyROOT/helpers/utils.py:302, in produceCanvasJson(canvas)
    299     canvas.Draw()
    301 if TWebCanvasAvailable():
--> 302     return ROOT.TWebCanvas.CreateCanvasJSON(canvas, 23, True)
    304 # Add extra primitives to canvas with custom colors, palette, gStyle
    306 prim = canvas.GetListOfPrimitives()

SegmentationViolation: static TString TWebCanvas::CreateCanvasJSON(TCanvas* c, Int_t json_compression = 0, Bool_t batchmode = kFALSE) =>
    SegmentationViolation: segfault in C++; program state was reset

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions