Hello,
I’m attempting to plot multiple TGraphErrors on a single plot. I am able to do this. I then am trying to build a legend. Again, I am successful, to a certain extent. I will attach the plot I am getting as an image, and dislay at bottom of post.
The problem is, when I attempt to draw the legend, both labels show up, however they both show a generic “square” and “black” point or line, depending on what option I choose. If I try to use a gr->SetFillColor(2), then ask it to show the “Fill” option, it just draws a box that is tranparent to the Legend Fill Color. Thus, I’m unable to use the legend to distinguish the different data sets. My ROOT version is 5.34.09 (built from source today), on Ubuntu 13.1 (x86_64).
Here is the relevant part of my code:
[code]
/// Invoke Canvas, Draw Frame, Set Titles, etc
TCanvas *c1 = new TCanvas(“c1”,“Graph Title”,200,10,700,500);
TH1F *hr = c1->DrawFrame(95,0,305,2.5);
hr->SetXTitle(“Incoming Neutron Energy (MeV)”);
hr->SetYTitle(“Cross-Section (barns)”);
hr->SetTitle(“U-238 n,Fiss Cross-Section”);
hr->GetXaxis()->CenterTitle(1);
hr->GetYaxis()->CenterTitle(1);
c1->GetFrame()->SetFillColor(kWhite);
c1->GetFrame()->SetBorderSize(12);
/// Define Data Sets into plottable functions, set draw options
TGraphErrors *grK = new TGraphErrors(j-1,xK,yK,dxK,dyK);
TGraphErrors *gr = new TGraphErrors(i-1,x,y,dx,dy);
gr->SetMarkerStyle(20);
gr->SetMarkerSize(1);
gr->SetLineColor(2);
gr->SetMarkerColor(2);
gr->SetFillColor(2);
gr->SetTitle(“U-238 n,fiss Cross-Section”);
grK->SetMarkerStyle(22);
grK->SetMarkerSize(1);
grK->SetMarkerColor(4);
grK->SetLineColor(4);
grK->SetFillColor(4);
gr->Draw(“p”);
grK->Draw(“p”);
/// Define Legend, Set Options, etc
TLegend *leg = new TLegend(0.12,0.75,0.3,0.9);
leg->AddEntry(“gr”,“UKy Prelim Data”,“l”);
leg->AddEntry(“grK”,“World Data (EXFOR)”,“l”);
leg->SetFillColor(kWhite);
leg->Draw();
c1->Update();[/code]
I’m unsure why the information is not passing the specifics of the points. grK should be a blue triangle, gr should be a red dot. Both show in the legend as a black square. Any ideas?
Thanks,
Zach