11.73 Sample ‘legend

Example of legend styles.

MGL code:

addlegend 'sin(\pi {x^2})' 'b':addlegend 'sin(\pi x)' 'g*'
addlegend 'sin(\pi \sqrt{x})' 'rd':addlegend 'jsut text' ' ':addlegend 'no indent for this' ''
subplot 2 2 0 '':title 'Legend (default)':box:legend
legend 1 0.5 '^':text 0.49 0.88 'Style "\^"' 'A:L'
legend 3 'A#':text 0.75 0.65 'Absolute position' 'A'
subplot 2 2 2 '':title 'coloring':box:legend 0 'r#':legend 1 'Wb#':legend 2 'ygr#'
subplot 2 2 3 '':title 'manual position':box
legend 0.5 1:text 0.5 0.5 'at x=0.5, y=1' 'a'
legend 1 '#-':text 0.75 0.25 'Horizontal legend' 'a'

C++ code:

void smgl_legend(mglGraph *gr)
{
	gr->AddLegend("sin(\\pi {x^2})","b");
	gr->AddLegend("sin(\\pi x)","g*");
	gr->AddLegend("sin(\\pi \\sqrt{x})","rd");
	gr->AddLegend("just text"," ");
	gr->AddLegend("no indent for this","");
	if(big!=3)	{gr->SubPlot(2,2,0,"");	gr->Title("Legend (default)");}
	gr->Box();	gr->Legend();
	if(big==3)	return;
	gr->Legend(1,0.5,"^");	gr->Puts(0.49, 0.88, "Style '\\^'","A:L");
	gr->Legend(3,"A#");
	gr->Puts(mglPoint(0.75,0.65),"Absolute position","A");
	gr->SubPlot(2,2,2,"");	gr->Title("coloring");	gr->Box();
	gr->Legend(0,"r#");	gr->Legend(1,"Wb#");	gr->Legend(2,"ygr#");
	gr->SubPlot(2,2,3,"");	gr->Title("manual position");	gr->Box();
	gr->Legend(0.5,1);
	gr->Puts(mglPoint(0.5,0.5),"at x=0.5, y=1","a");
	gr->Legend(1,"#-");
	gr->Puts(mglPoint(0.75,0.25),"Horizontal legend","a");
}
Sample legend