How do I save a graph to a png without having the canvas pop up anywhere?

I have some code that generates a TCanvas, draws a histogram, and then Print()'s the canvas to a .png file.
The TCanvas pops up on the screen which makes the application look unprofessional. I would like to create a .png without the TCanvas popping up on the screen. Can this be done?

ROOT Version: 6.28.04
Platform: Ubuntu 22
Compiler: GCC

You can use batch mode. Just run:

root -b your_macro.C -q

I still want a GUI, I just don’t want loads of random popups everywhere. Is it all or nothing?

You can set batch mode only while you create canvas and store png file:

auto c1 = new TCanvas("c1","c1", 500, 500);
// draw all your objects here
delete c1;

Or maybe try TCanvas::SetBatch()

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