Hi,
classic ROOT lifetime problems!
The TGraph goes out of scope (“dies”) at the end of the macro, so it disappears from the canvas (not a very friendly behavior, admittedly).
Using a TGraph* graph = new TGraph("P.txt"); and letting it live after macro has finished executing should fix the problem. ROOT will take care of properly deleting the TGraph at exit.
Cheers,
Enrico