Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Web) graphics does not work from PyROOT #14943

Open
1 task done
jblomer opened this issue Mar 12, 2024 · 9 comments · May be fixed by #17587
Open
1 task done

(Web) graphics does not work from PyROOT #14943

jblomer opened this issue Mar 12, 2024 · 9 comments · May be fixed by #17587

Comments

@jblomer
Copy link
Contributor

jblomer commented Mar 12, 2024

Check duplicate issues.

  • Checked for duplicates

Description

When using Python in interactive mode, the web window does not launch properly (see screenshot). It works from a C++ macro. One can also save canvas contents in ROOT batch mode.

image

Reproducer

import ROOT
import numpy as np

def main():
    voltages = np.array([1,2,3], dtype=np.uint32)
    capacitances = np.array([4,5,6], dtype=np.float32)

    #ROOT.gROOT.SetBatch(True)
    df = ROOT.RDF.FromNumpy({'voltages': voltages, 'capacitances': capacitances})
    df = df.Define('inv', '1/(capacitances*capacitances)')

    c = ROOT.TCanvas()
    graph = df.Graph('voltages', 'inv')
    graph.Draw('APL')

    c.SaveAs("graph.pdf")

if __name__ == "__main__":
    main()

Output:

$ python3 -i repro.py 
Info in <THttpEngine::Create>: Starting HTTP server on port 127.0.0.1:9449
Opening in existing browser session.
[102887:102898:0312/160727.268507:ERROR:object_proxy.cc(576)] Failed to call method: org.freedesktop.DBus.Properties.Get: object_path= /org/freedesktop/portal/desktop: org.freedesktop.DBus.Error.InvalidArgs: No such interface “org.freedesktop.portal.FileChooser”
[102887:102898:0312/160727.268546:ERROR:select_file_dialog_linux_portal.cc(285)] Failed to read portal version property
[102887:102887:0312/160727.306050:ERROR:policy_logger.cc(156)] :components/enterprise/browser/controller/chrome_browser_cloud_management_controller.cc(161) Cloud management controller initialization aborted as CBCM is not enabled. Please use the `--enable-chrome-browser-cloud-management` command line flag to enable it if you are not using the official Google Chrome build.
13986 bytes written to file /home/jakob/Documents/CERN/ROOT/demo/graph.pdf
Info in <ProduceImage>: PDF file graph.pdf with 1 pages has been created
>>> 

ROOT version

master

Installation method

From sources

Operating system

Linux

Additional context

No response

@jblomer
Copy link
Contributor Author

jblomer commented Mar 12, 2024

(Hold on, mixed up the reproducer, fixing...)

@linev
Copy link
Member

linev commented Mar 12, 2024

Can you add ROOT.gROOT.SetWebDisplay("chrome") to the macro?

For me it works ok.

@jblomer
Copy link
Contributor Author

jblomer commented Mar 12, 2024

Ok, now the reproducer is the correct one. Adding SetWebDisplay("chrome") doesn't help (also it is already on Chrome).

@linev
Copy link
Member

linev commented Mar 12, 2024

It also does not work with SetWebDisplay("off").

Canvas destroyed before it can be drawn.

I have idea to provide special TCanvas::Draw() handling for python - but never find time for this.

@jblomer jblomer removed the in:WebGui label Mar 12, 2024
@jblomer jblomer changed the title Web graphics does not work from PyROOT (Web) graphics does not work from PyROOT Mar 12, 2024
@dpiparo
Copy link
Member

dpiparo commented Mar 14, 2024

This is a blocker for the web graphics.

@linev
Copy link
Member

linev commented Mar 14, 2024

This is a blocker for the web graphics.

It is not.

Normal graphics is also not working with this macro.
TCanvas just destroyed at the end of the function

@jblomer
Copy link
Contributor Author

jblomer commented Mar 18, 2024

Right, thanks for pointing this out!

I suggest a change to the documentation (e.g., this page: https://root.cern/manual/python/#interactive-graphics) that mentions that the canvas is better not in function-local scope but in global scope.

@linev
Copy link
Member

linev commented Jun 13, 2024

One can use ROOT.SetOwnership(c, False) at the end of such function - as in tutorials/dataframe/df103_NanoAODHiggsAnalysis.py. This prevent PyROOT from canvas destroying at the end

@Pratz2005
Copy link

Can I work on this issue?

@linev linev linked a pull request Jan 31, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants