I am using ipython and ipython notebook with rootnotes.py.
I have set the Xs, so I can see my plots in the Xs, and I am also saving them in png format.
Png saved files are fine, and also visible from ipython notebook running the commands:
from IPython.core.display import Image
Image(filename=‘test.png’)
However, the plots vanish from the Xs after few seconds and just the axis and the title axis remain (no data points, neither legends nor plot title).
I would like to have this fixed, basically because the plots that remain at the ipython notebook browser() are empty, I can not see them if I do not run lines above.
can you post the code you use? The common reason for canvases to come and go, is if the variable referencing them is going out of scope (e.g. when the code is executed from within a function body).
[quote=“arodrig”]the canvas is indeed within a function body, but I am returning that canvas (return canvas).[/quote]but where is it subsequently going? I.e. what is holding a reference to it?
[quote]Is there any way to avoid the freing of that object?[/quote]Yes, using ROOT.SetOwnership(canvas, False). But make sure that someone deletes it at all, or the canvases will stay around until shutdown (at which point they’ll be cleaned up by the TROOT destructor).
sorry, I can’t make sense of that: if the ownership is not on the python side, definitely python is not removing the canvas. Likewise, it is still not clear to me what would hold a return value from that function.
Maybe I’m misreading your initial post and it is not the canvas that disappears, but the data points? I.e. what is called “dataG” in the original code and to which the “plot” dictionary holds a reference whereas in your case it is removed as it is not returned after your change.
indeed, you were not misreading the initial post, I just explained it wrong.
With your last post, you made me notice the difference.
Now I keep the whole plot dictionary in the object.