Next: , Previous: , Up: 1D samples   [Contents][Index]


3.5.8 Bars sample

Function bars draw vertical bars. It have a lot of options: bar-above-bar (‘a’ style), fall like (‘f’ style), 2 colors for positive and negative values, wired bars (‘#’ style), 3D variant. The sample code is:

int sample(mglGraph *gr)
{
  mglData ys(10,3); ys.Modify("0.8*sin(pi*(2*x+y/2))+0.2*rnd");
  gr->SetOrigin(0,0,0);
  gr->SubPlot(3,2,0,"");  gr->Title("Bars plot (default)");
  gr->Box();  gr->Bars(ys);

  gr->SubPlot(3,2,1,"");  gr->Title("2 colors");
  gr->Box();  gr->Bars(ys,"cbgGyr");

  gr->SubPlot(3,2,4,"");  gr->Title("'\\#' style");
  gr->Box();  gr->Bars(ys,"#");

  gr->SubPlot(3,2,5); gr->Title("3d variant");
  gr->Rotate(50,60);  gr->Box();
  mglData yc(30), xc(30), z(30);  z.Modify("2*x-1");
  yc.Modify("sin(pi*(2*x-1))"); xc.Modify("cos(pi*2*x-pi)");
  gr->Bars(xc,yc,z,"r");

  gr->SetRanges(-1,1,-3,3);
  gr->SubPlot(3,2,2,"");  gr->Title("'a' style");
  gr->Box();  gr->Bars(ys,"a");

  gr->SubPlot(3,2,3,"");  gr->Title("'f' style");
  gr->Box();  gr->Bars(ys,"f");
  return 0;
}

Example of Bars()