Set TCanvas size in batch mode

I am trying to run root in batch mode, and save TCanvas in a .root file. What I notice though is that when I save the Canvas in batch mode, it doesn’t preserve the size I created it with, but at some default value. I attach a small running example macro.
Could you please let me know what the workaround is? I am using root version 5.19.04
test.C (1012 Bytes)

I see what you mean. I have no workaround yet. I will investigate.

Hi all,

I have the same problem, quite annoying for me since I have to run a script producing plots quite often and messing up the screen all the time because I need the Canvas in the right size. Is there some fix for this meanwhile?


Actually, seems to me, this problem as been fixed.
I executed the macro provided in this thread in batch mode.
Then I restarted ROOT in interactive mode and displayed the saved canvas.
The saved canvas has the same size has the original one when the macro is executed in interactive mode.
I am using trunk version of ROOT.


strange…it’s been a while since the topic came up the first time. I am using ROOT 5-27 and it doesn’t seem to work. Perhaps the change has been very recent. I will try again. Thank you again!


Hm, unfortunately it still does not work for me. I alternatively try to set the size correctly after getting it from file like:

but this leads to a seg fault…


Are we doing the same thing ? I did that:

Sorry that it took me a while to reply.

Well, it looks to me like we are doing the same thing (ROOT 5.27/06)…Did you change the canvas size to some non-standard dimensions before saving it to file? I also could not do:

TFile f("myfile.root"); MyCanvas.Draw();

directly but had to do:

but this cannot be it…right?


I did nothing special. Just ran the macro test.c given in the first post. This macro generates a non standard canvas size (portrait oriented). I ran it in batch to create the file plot.root (see previous posts). Then I ran root again in interactive mode, attached the file plot.root (see again the previous posts), plot the saved canvas (see one more the previous posts) and I get the same portrait oriented canvas size.

Hi again,

I overlooked the test.C file in the first post somehow, I am sorry. I tested it with this file but it still does not work for me :wink: The canvas size changes…so probably this was fixed quite recently and I should upgrade to a more recent version of ROOT.


Yes that’s is what I am thinking. I do not thing I can do a mistake saying the size is kept because the portrait layout is not standard therefore it is clearly identifiable.