Hi:
example:
#include<root/TCanvas.h>
#include<root/TMultiGraph.h>
#include<root/TGraph.h>
#include<root/TAxis.h>
auto graph1(TMultiGraph&graphs)
{
std::vectorpx1{-0.1, 0.05, 0.25, 0.35, 0.5, 0.61,0.7,0.85,0.89,0.95};
std::vectorpy1{-1,-2.9,-5.6,-7.4,-9,-9.6,-8.7,-6.3,-4.5,-1};
auto gr=new TGraph(px1.size(),px1.data(),py1.data());
gr->SetLineColor(kBlue);
graphs.Add(gr);
}
auto f()
{
TMultiGraph mg;
graph1(mg);
mg.DrawClone(“ac”);
mg.GetXaxis()->SetTitle(“X values”);
mg.GetYaxis()->SetTitle(“Y values”);
}
int main()
{
TCanvas canvas;
f();
canvas.Print(“haha.pdf”);
}
because I need to draw a very complex graph, I put the actual draw in the function f().
mg.DrawClone(“ac”); will cause segmentation fault. However, the drawclone of tgraph and tf1 just work ok. So how to use DrawClone of MultiGraph correctly?