Hi!
Run this:
const int histNumber = 8; // total number of histograms
void hists () {
TCanvas * c = new TCanvas("a", "b", 800, 380);
c->SetMargin(0.1, 0.036, 0.1, 0.03);
TH1D * hist;
TLegend * legend = new TLegend(0.60, 0.80, 0.98, 0.96);
legend->SetHeader("something");
legend->SetNColumns(histNumber/2);
gStyle->SetOptStat(false);
for (int i = 0; i < histNumber; i++) {
hist = new TH1D(Form("%d", i), "", 100, -3, 3);
hist->FillRandom("gaus", 1E+4);
hist->SetLineStyle(((i + 1) % 2) +1);
hist->SetLineColor((i + 1) / 2 + 1);
legend->AddEntry(hist, "a", "lep");
hist->Draw("HIST E0 same");
}
legend->Draw();
TText * text1 = new TText(0.10, 0.2, "Label1");
text1->SetTextAlign(22);
text1->Draw();
TText * text2 = new TText(0.40, 0.1, "Label2");
text2->SetTextAlign(22);
text2->Draw();
return;
}
It will produce a messy legend. What I want is something like this:
where the tiny coloured boxes should be + instead, each having the color of a histogram. Additionally, they should have the same “LineFillStyle”.
I think I’m not far from what I want, but I have some trouble with the Ttext coordinates. Furthermore, I’d like to have the same line-separators as shown in the picture.
May I get some help?