-
Notifications
You must be signed in to change notification settings - Fork 0
/
graph.cpp
78 lines (66 loc) · 2.02 KB
/
graph.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
void setStyle() {
gROOT->SetStyle("Plain");
gStyle->SetPalette(20);
gStyle->SetOptTitle(0);
}
void graph() {
// CANVAS
TCanvas *c = new TCanvas("c", "SEIRD", 700, 500);
TMultiGraph *mg = new TMultiGraph();
// GRAPH
Int_t MarkerStyle = 1;
TGraph *graphS = new TGraph("data.dat", "%lg %lg"); // Suscettibili
graphS->SetMarkerStyle(MarkerStyle);
graphS->SetMarkerColor(kBlue);
graphS->SetLineColor(kBlue);
mg->Add(graphS);
TGraph *graphE = new TGraph("data.dat", "%lg %*lg %lg"); // Esposti
graphE->SetMarkerStyle(MarkerStyle);
graphE->SetMarkerColor(kOrange + 10);
graphE->SetLineColor(kOrange + 10);
mg->Add(graphE);
TGraph *graphI = new TGraph("data.dat", "%lg %*lg %*lg %lg"); // Infetti
graphI->SetMarkerStyle(MarkerStyle);
graphI->SetMarkerColor(kMagenta);
graphI->SetLineColor(kMagenta);
mg->Add(graphI);
TGraph *graphR = new TGraph("data.dat", "%lg %*lg %*lg %*lg %lg"); // Guariti
graphR->SetMarkerStyle(MarkerStyle);
graphR->SetMarkerColor(kGreen);
graphR->SetLineColor(kGreen);
mg->Add(graphR);
TGraph *graphD =
new TGraph("data.dat", "%lg %*lg %*lg %*lg %*lg %lg"); // Morti
graphD->SetMarkerStyle(MarkerStyle);
graphD->SetMarkerColor(kOrange);
graphD->SetLineColor(kOrange);
mg->Add(graphD);
// LINES
std::ifstream input_file("threshold.dat");
double thr;
input_file >> thr;
std::ifstream input_file1("population.dat");
int pop;
input_file1 >> pop;
TLine *line = new TLine(thr, 0, thr, pop);
line->SetLineWidth(2);
line->SetLineStyle(kDashed);
// AXIS
mg->GetXaxis()->SetTitle("Days");
mg->GetYaxis()->SetTitle("People");
mg->Draw("APL");
// LEGEND
TLegend *leg = new TLegend(0.9, 0.7, 1, 1, "Legend");
leg->SetFillColor(0);
leg->AddEntry(graphS, "Susceptible");
leg->AddEntry(graphE, "Exposed");
leg->AddEntry(graphI, "Infectious");
leg->AddEntry(graphR, "Recovered");
leg->AddEntry(graphD, "Dead");
leg->AddEntry(line, "Threshold");
leg->Draw("SAME");
if (thr != 0) {
line->Draw("same");
}
c->Print("SEIRD.pdf");
}