Getting list of primitives for TH2F on canvas

Consider following code:

import ROOT
h = ROOT.TH2F("", "", 100, 0.0, 1.0, 100, 0.0, 1.0)
r = ROOT.TRandom()

for _ in xrange(100000):
    h.Fill(r.Gaus(0.7,0.05), r.Gaus(0.1, 0.03))


c = ROOT.TCanvas()
h.Draw("colz")
print list(c.GetListOfPrimitives())

It will print out [<ROOT.TH2F object at 0x3a81a20>], so the only primitive in canvas is TH2F itself.

Question: is it possible to dig deeper and get primitives for drawn TH2F? I want to get list which consists of primitives like TBox, TText, TLine.

No … they will not appear as such … they are painted but not drawn. They are not in the list of primitives of the TH2

Maybe it is possible to at least listen to drawing calls on gVirtualX or TCanvas?

No … They are not available as such … you can save the canvas as an SVG file … I guess that’s the best you can do to have this very low level list. Any way that’s a strange request. What is your final goal ? may be there is a better way to achieve it …

I want to draw arbitrary TCanvas which contains histograms as well as some other graphics in web browser, rendering list of low-level primitives seem to be easy and guarantee 1:1 ROOT graphics resemblence.

Thanks for SVG tip, will look into it.

do not reinvent the wheel … it exists already:
https://root.cern.ch/root/htmldoc/guides/JSROOT/JSROOT.html

and the SVG files generated by ROOT can be displayed in a web browser

See also https://root.cern.ch/js/

Cheers, Bertrand.

We switched from D3 to Bokeh in order to avoid js development as much as possible. JSROOT would involve js development, plus I’m not sure it supports all custom stuff we need(i.e. plotting TCanvas on top of TH2F).

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