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


3.5.15 Error sample

Function error draw error boxes around the points. You can draw default boxes or semi-transparent symbol (like marker, see Line styles). Also you can set individual color for each box. The sample code is:

int sample(mglGraph *gr)
{
  mglData y;  mgls_prepare1d(&y);
  mglData x0(10), y0(10), ex0(10), ey0(10);
  mreal x;
  for(int i=0;i<10;i++)
  {
    x = i/9.;
    x0.a[i] = 2*x-1 + 0.1*mgl_rnd()-0.05;
    y0.a[i] = 0.7*sin(2*M_PI*x)+0.5*cos(3*M_PI*x)+0.2*sin(M_PI*x)+0.2*mgl_rnd()-0.1;
    ey0.a[i]=0.2; ex0.a[i]=0.1;
  }

  gr->SubPlot(2,2,0,"");  gr->Title("Error plot (default)");
  gr->Box();  gr->Plot(y.SubData(-1,0));  gr->Error(x0,y0,ex0,ey0,"ko");

  gr->SubPlot(2,2,1,"");  gr->Title("'!' style; no e_x");
  gr->Box();  gr->Plot(y.SubData(-1,0));  gr->Error(x0,y0,ey0,"o!rgb");

  gr->SubPlot(2,2,2,"");  gr->Title("'\\@' style");
  gr->Box();  gr->Plot(y.SubData(-1,0));  gr->Error(x0,y0,ex0,ey0,"@","alpha 0.5");

  gr->SubPlot(2,2,3); gr->Title("3d variant");  gr->Rotate(50,60);
  for(int i=0;i<10;i++)
    gr->Error(mglPoint(2*mgl_rnd()-1,2*mgl_rnd()-1,2*mgl_rnd()-1),
              mglPoint(0.2,0.2,0.2),"bo");
  gr->Axis();
  return 0;
}
Example of Error()

Additionally, you can use solid large "marks" instead of error boxes by selecting proper style.

int sample(mglGraph *gr)
{
  mglData x0(10), y0(10), ex(10), ey(10);
  for(int i=0;i<10;i++)
  {  x0.a[i] = mgl_rnd(); y0.a[i] = mgl_rnd(); ey.a[i] = ex.a[i] = 0.1; }
  gr->SetRanges(0,1,0,1); gr->Alpha(true);
  gr->SubPlot(4,3,0,"");  gr->Box(); gr->Error(x0,y0,ex,ey,"#+@");
  gr->SubPlot(4,3,1,"");  gr->Box(); gr->Error(x0,y0,ex,ey,"#x@");
  gr->SubPlot(4,3,2,"");  gr->Box(); gr->Error(x0,y0,ex,ey,"#s@","alpha 0.5");
  gr->SubPlot(4,3,3,"");  gr->Box(); gr->Error(x0,y0,ex,ey,"s@");
  gr->SubPlot(4,3,4,"");  gr->Box(); gr->Error(x0,y0,ex,ey,"d@");
  gr->SubPlot(4,3,5,"");  gr->Box(); gr->Error(x0,y0,ex,ey,"#d@","alpha 0.5");
  gr->SubPlot(4,3,6,"");  gr->Box(); gr->Error(x0,y0,ex,ey,"+@");
  gr->SubPlot(4,3,7,"");  gr->Box(); gr->Error(x0,y0,ex,ey,"x@");
  gr->SubPlot(4,3,8,"");  gr->Box(); gr->Error(x0,y0,ex,ey,"o@");
  gr->SubPlot(4,3,9,"");  gr->Box(); gr->Error(x0,y0,ex,ey,"#o@","alpha 0.5");
  gr->SubPlot(4,3,10,""); gr->Box(); gr->Error(x0,y0,ex,ey,"#.@");
  gr->SubPlot(4,3,11,""); gr->Box(); gr->Error(x0,y0,ex,ey);
}
Example of Error() with marks




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