#include "TF1.h"
#include "TApplication.h"
#include "TCanvas.h"
#include "TRootCanvas.h"
#include "TGraph.h"
#include "TLegend.h"
#include "TGFont.h"
#include "TPad.h"
void plotlines() {
auto c = new TCanvas("c1", "Demo example");
TString dir = gROOT->GetTutorialDir();
TGraph gr(dir+"\\plotdata1.txt");
gr.SetTitle("Demo data");
gr.SetMarkerStyle(20);
gr.Draw("APL");
return 0;
}
and run it in the root interpreter by
.L plotlines.C
plotlines()
I get a window with the title bar labelled “Demo example” but no plot.
Both the plotlines.C and the plotdata1.txt files are in the same directory: the tutorials directory, and root was launched from that directory.
_ROOT Version: 6.26.10
_Platform: Windows 10
_Compiler: root interpreter
I had already tried that. That isn’t the problem.
The files are in C:\root_v6.26.10\tutorials and even using that absolute path, the data are not shown. However, using the absolute path works fine in compiled C++ code in Visual Studio.
I got it working. I exited the root interpreter and entered it again with
root > .x plotlines.c
and that worked.
Now everything works even if I exit and re-enter directly. It must be some weird initialization problem. Anyway, it works every way I try now. Thank you for your suggestions.