The size of a TCanvas is not persisted in the new object after calling Clone().
I’m using pyROOT with batch mode set to True and ROOT version 6.06/00. I have attached some demonstration code which shows that the canvasses saved before and after cloning have different widths and heights. preserveCanvas.py (633 Bytes)
In my code I make plots and Draw them onto TCanvases, constructed with:
c = TCanvas('c','c',600,640) #these look like portrait orientation
I append each TCanvas to a list. The canvases have the same names. I found that the code seg faults if I try to print any of the canvases. I found that copying or cloning the canvases before adding them to the list solves the problem. I can then print the canvases to a PDF and all the correct plots are printed. However, the size of the canvases are not persisted but return to the default size, which looks like a square or landsacpe orientation. I also noticed that the GetWindowWidth and GetWindowHeight functions return different values before and after cloning:
I am not sure what your script is supposed to show. I did:
$ python preserveCanvas.py
Info in <TCanvas::Print>: pdf file ./temp_before_0.pdf has been created
TCanvas::Constructor:0: RuntimeWarning: Deleting canvas with same name: c
Info in <TCanvas::Print>: pdf file ./temp_before_1.pdf has been created
TCanvas::Constructor:0: RuntimeWarning: Deleting canvas with same name: c
Info in <TCanvas::Print>: pdf file ./temp_before_2.pdf has been created
Info in <TCanvas::Print>: pdf file ./temp_after_0.pdf has been created
Info in <TCanvas::Print>: pdf file ./temp_after_1.pdf has been created
it gives me 5 white pdf files having the same size.
I see now … do you get the same with using this list ? …
i am not familiar with python and would like to translate it in C++ to see if this issue is due to python,.
Thanks for your input. I have tried to convert your program into a .C macro and ran it in interactive mode with ROOT 6. But I get a crash. I then tried to simplified it (with a array of canvas) and it still crashes. I am investigating.
Can you look at my original email again? The issue is that when I put these canvases into a list, then overwrite the variable, say “cnew”, that refers to the pointer, the pointer in the list also gets changed so that the canvases in the list are all the same.
My issue is how to add canvases into a list in a generic way, so that I can do addCanvas( mycanvas ), and then later on I can do canvasList[index].Print(’…’) . My solution to this in the second piece of code I posted was to Clone the canvas so that it was a different object, then add it to the list. But this doesn’t work.
Info in <TCanvas::Print>: pdf file ./temp_before_0.pdf has been created
600, 100
600, 100
Info in <TCanvas::Print>: pdf file ./temp_after_0.pdf has been created
BUT the canvases are not the same size. The window sizes are the same, but the second canvas, “temp_after_0.pdf” has a smaller y-value than “temp_before_0.pdf”. See the attached screenshot.
Info in <TCanvas::Print>: pdf file ./temp_before_0.pdf has been created
600, 100
596, 72
600, 100
592, 44
Info in <TCanvas::Print>: pdf file ./temp_after_0.pdf has been created
I implemented your fix in my python framework. It seems that the aspect ratios of the canvases are (almost) preserved when using your solution. This is completely adequet for my purposes, thanks!
Although it’s still quite strange that the canvas changes size.