Putting legend for a histogram

Hello,
I want to put legend in macro and to give different colors to the different distributions. I did like
TH1F *mylegend = new TLegend(.7,.75,.89,.89);
mylegend->SetFillColor(0);
mylegend->SetBorderSize(0);
mylegend->SetTextSize(0.030);
mylegend->AddEntry(myhist_1,“bjet1Eta_official_code”,“l”);
mylegend->Draw();
Also please suggest me about colors.


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


TH1F *mylegend = new TLegend(.7,.75,.89,.89);

That’s really weird …

Sorry if I miss understood I wrote exactly like that as you wrote.

For every ROOT class that you want to use, you need an appropriate #include statement, e.g.:

#include "TLegend.h"
1 Like

That’s my point, I quoted your code. You define a pointer to a TH1F and you assign it to a new TLegend … I guess you mean:

TLegend *mylegend = new TLegend(.7,.75,.89,.89);
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.