TLegend Not Displaying Color or Styleized Markers in MultiGraph

Hello,

I’m using TGraph, TMultiGraph, and TLegend. The graphing is behaving well and the legend is 60% working. Unfortunately I can’t get the legend to display the style and color of the Markers in the MultiGraph.

Below I’ve included the .png and the root file of the TGraph showing my problem.


tgraphmulti2.root (10.1 KB)

I’ve also included is a code snippet, controlling the graphing and the legend. Thank you for your help.

legend->SetHeader("The Legend Title","C"); // option "C" allows to center the header
	
g0 = new TGraph( numerator,TGraphStoreEtax1,TGraphStoreEtay1);
g1 = new TGraph( numerator,TGraphStoreEtax2,TGraphStoreEtay2);
g2 = new TGraph( numerator,TGraphStoreEtax3,TGraphStoreEtay3);
g3 = new TGraph( numerator,TGraphStoreEtax4,TGraphStoreEtay4);
g4 = new TGraph( numerator,TGraphStoreEtax5,TGraphStoreEtay5);
g5 = new TGraph( numerator,TGraphStoreEtax6,TGraphStoreEtay6);
g6 = new TGraph( numerator,TGraphStoreEtax7,TGraphStoreEtay7);
g7 = new TGraph( numerator,TGraphStoreEtax8,TGraphStoreEtay8);

	g0->SetLineWidth(4);
	g0->SetMarkerColor(1);
	g0->SetMarkerSize(1.5);
	g0->SetMarkerStyle(45);
	g1->SetLineWidth(4);
	g1->SetMarkerColor(2);
	g1->SetMarkerSize(1.5);
	g1->SetMarkerStyle(46);
	g2->SetLineWidth(4);
	g2->SetMarkerColor(3);
	g2->SetMarkerSize(1.5);
	g2->SetMarkerStyle(47);
	g3->SetLineWidth(4);
	g3->SetMarkerColor(4);
	g3->SetMarkerSize(1.5);
	g3->SetMarkerStyle(48);
	g4->SetLineWidth(4);
	g4->SetMarkerColor(5);
	g4->SetMarkerSize(1.5);
	g4->SetMarkerStyle(49);
	g5->SetLineWidth(4);
	g5->SetMarkerColor(6);
	g5->SetMarkerSize(1.5);
	g5->SetMarkerStyle(50);
	g6->SetLineWidth(4);
	g6->SetMarkerColor(7);
	g6->SetMarkerSize(1.5);
	g6->SetMarkerStyle(51);
	g7->SetLineWidth(4);
	g7->SetMarkerColor(8);
	g7->SetMarkerSize(1.5);
	g7->SetMarkerStyle(52);

mg->Add(g0);
mg->Add(g1);
mg->Add(g2);
mg->Add(g3);
mg->Add(g4);
mg->Add(g5);
/*mg->Add(g6);
mg->Add(g7);*/

mg->Draw("AP");
legend->AddEntry("g0","Graph 0","lep");
legend->AddEntry("g1","Graph 1","lep");
legend->AddEntry("g2","Graph 2","lep");
legend->AddEntry("g3","Graph 3","lep");
legend->AddEntry("g4","Graph 4","lep");
legend->AddEntry("g5","Graph 5","lep");

legend->Draw();
c->Update();
c->SaveAs("tgraphmulti2.root");
c->SaveAs("tgraphmulti2.png");

ROOT Version: 6.12/07
Platform: Linux
Compiler: Not Provided


Your graphs have no names so, try:

legend->AddEntry(g0, "Graph 0", "p");
legend->AddEntry(g1, "Graph 1", "p");
legend->AddEntry(g2, "Graph 2", "p");
legend->AddEntry(g3, "Graph 3", "p");
legend->AddEntry(g4, "Graph 4", "p");
legend->AddEntry(g5, "Graph 5", "p");

Also, marker styles >= 50 do not exist in the current ROOT so, use 1 ... 49.

SOLVED!

Thank you. And good to know I will fix my marker error.

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