Hi experts,
I write a script to draw a scatter picture and write the picture to a root file, but the picture in the root file is not a scatter picture but a broken line graph.
Could you please give me some advice?
0 #include "TCanvas.h"
1 #include "TGraph.h"
2 #include "TFile.h"
3
4 int main(int argc, char* argv[]) {
5
6 TFile *f2 = new TFile("scatter_plot.root","RECREATE");
7 TCanvas *c1 = new TCanvas("c1", "Scatter Plot", 800, 600);
8
9 Double_t x[] = {1.0, 2.0, 3.0, 4.0, 5.0};
10 Double_t y[] = {2.0, 3.0, 1.0, 4.0, 5.0};
11
12 TGraph *scatterPlot = new TGraph(5, x, y);
13 scatterPlot->SetMarkerStyle(20);
14 scatterPlot->SetMarkerColor(kBlue);
15
16 scatterPlot->Draw("AP");
17 c1->Draw();
18 c1->SaveAs("123.pdf");
19 scatterPlot->Write();
20 f2->Close();
21
22
23 return 0;
24 }