| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This section is devoted to visualization of 2D data arrays. 2D means the data which depend on 2 indexes (parameters) like matrix z(i,j)=z(x(i),y(j)), i=1...n, j=1...m or in parametric form {x(i,j),y(i,j),z(i,j)}. Most of samples will use the same data for plotting. So, I put its initialization in separate function
void mgls_prepare2d(mglData *a, mglData *b=0, mglData *v=0)
{
register long i,j,n=50,m=40,i0;
if(a) a->Create(n,m); if(b) b->Create(n,m);
if(v) { v->Create(9); v->Fill(-1,1); }
float x,y;
for(i=0;i<n;i++) for(j=0;j<m;j++)
{
x = i/(n-1.); y = j/(m-1.); i0 = i+n*j;
if(a) a->a[i0] = 0.6*sin(2*M_PI*x)*sin(3*M_PI*y)+0.4*cos(3*M_PI*x*y);
if(b) b->a[i0] = 0.6*cos(2*M_PI*x)*cos(3*M_PI*y)+0.4*cos(3*M_PI*x*y);
}
}
or using C functions
void mgls_prepare2d(HMDT a, HMDT b=0, HMDT v=0)
{
register long i,j,n=50,m=40,i0;
if(a) mgl_data_create(a,n,m,1);
if(b) mgl_data_create(b,n,m,1);
if(v) { mgl_data_create(v,9,1,1); mgl_data_fill(v,-1,1,'x'); }
float x,y;
for(i=0;i<n;i++) for(j=0;j<m;j++)
{
x = i/(n-1.); y = j/(m-1.); i0 = i+n*j;
if(a) mgl_data_set_value(a, 0.6*sin(2*M_PI*x)*sin(3*M_PI*y)+0.4*cos(3*M_PI*x*y), i,j,0);
if(b) mgl_data_set_value(b, 0.6*cos(2*M_PI*x)*cos(3*M_PI*y)+0.4*cos(3*M_PI*x*y), i,j,0);
}
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Surf is most standard way to visualize 2D data array. Surf use color scheme for coloring (see Color scheme). You can use ‘#’ style for drawing black meshes on the surface. The sample code is:
int sample(mglGraph *gr)
{
mglData a; mgls_prepare2d(&a);
gr->SubPlot(2,2,0); gr->Title("Surf plot (default)");
gr->Light(true); gr->Rotate(50,60); gr->Box(); gr->Surf(a);
gr->SubPlot(2,2,1); gr->Title("'\\#' style; meshnum 10");
gr->Rotate(50,60); gr->Box(); gr->Surf(a,"#","meshnum 10");
gr->SubPlot(2,2,2); gr->Title("'|' style");
gr->Rotate(50,60); gr->Box(); gr->Surf(a,"|");
gr->SubPlot(2,2,3); gr->Title("parametric form");
mglData x(50,40),y(50,40),z(50,40);
gr->Fill(x,"0.8*sin(pi*x)*sin(pi*(y+1)/2)");
gr->Fill(y,"0.8*cos(pi*x)*sin(pi*(y+1)/2)");
gr->Fill(z,"0.8*cos(pi*(y+1)/2)");
gr->Rotate(50,60); gr->Box(); gr->Surf(x,y,z,"BbwrR");
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SurfC is similar to Surf but its coloring is determined by another data. The sample code is:
int sample(mglGraph *gr)
{
mglData a,b; mgls_prepare2d(&a,&b);
gr->Title("SurfC plot"); gr->Rotate(50,60);
gr->Light(true); gr->Box(); gr->SurfC(a,b);
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
SurfA is similar to Surf but its transparency is determined by another data. The sample code is:
int sample(mglGraph *gr)
{
mglData a,b; mgls_prepare2d(&a,&b);
gr->Title("SurfA plot"); gr->Rotate(50,60);
gr->Alpha(true); gr->Light(true);
gr->Box(); gr->SurfA(a,b);
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Mesh draw wired surface. You can use SetMeshNum for changing number of lines to be drawn. The sample code is:
int sample(mglGraph *gr)
{
mglData a; mgls_prepare2d(&a);
gr->Title("Mesh plot"); gr->Rotate(50,60);
gr->Box(); gr->Mesh(a);
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Fall draw waterfall surface. You can use SetMeshNum for changing number of lines to be drawn. Also you can use ‘x’ style for drawing lines in other direction. The sample code is:
int sample(mglGraph *gr)
{
mglData a; mgls_prepare2d(&a);
gr->Title("Fall plot"); gr->Rotate(50,60);
gr->Box(); gr->Fall(a);
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Belt draw surface by belts. You can use ‘x’ style for drawing lines in other direction. The sample code is:
int sample(mglGraph *gr)
{
mglData a; mgls_prepare2d(&a);
gr->Title("Belt plot"); gr->Rotate(50,60);
gr->Box(); gr->Belt(a);
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Boxs draw surface by boxes. You can use ‘#’ for drawing wire plot. The sample code is:
int sample(mglGraph *gr)
{
mglData a; mgls_prepare2d(&a);
gr->SetOrigin(0,0,0); gr->Light(true);
gr->SubPlot(2,2,0); gr->Title("Boxs plot (default)");
gr->Rotate(40,60); gr->Box(); gr->Boxs(a);
gr->SubPlot(2,2,1); gr->Title("'\\@' style");
gr->Rotate(50,60); gr->Box(); gr->Boxs(a,"@");
gr->SubPlot(2,2,2); gr->Title("'\\#' style");
gr->Rotate(50,60); gr->Box(); gr->Boxs(a,"#");
gr->SubPlot(2,2,3); gr->Title("compare with Tile");
gr->Rotate(50,60); gr->Box(); gr->Tile(a);
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Tile draw surface by tiles. The sample code is:
int sample(mglGraph *gr)
{
mglData a; mgls_prepare2d(&a);
gr->Title("Tile plot");
gr->Rotate(40,60); gr->Box(); gr->Tile(a);
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
TileS is similar to Tile but tile sizes is determined by another data. This allows one to simulate transparency of the plot. The sample code is:
int sample(mglGraph *gr)
{
mglData a,b; mgls_prepare2d(&a,&b);
gr->SubPlot(1,1,0,""); gr->Title("TileS plot");
gr->Box(); gr->TileS(a,b);
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Dens draw density plot for surface. The sample code is:
int sample(mglGraph *gr)
{
mglData a,a1(30,40,3); mgls_prepare2d(&a);
gr->Fill(a1,"0.6*sin(2*pi*x+pi*(z+1)/2)*sin(3*pi*y+pi*z) + 0.4*cos(3*pi*(x*y)+pi*(z+1)^2/2)");
gr->SubPlot(2,2,0,""); gr->Title("Dens plot (default)");
gr->Box(); gr->Dens(a);
gr->SubPlot(2,2,1); gr->Title("3d variant");
gr->Rotate(50,60); gr->Box(); gr->Dens(a);
gr->SubPlot(2,2,2,""); gr->Title("'\\#' style; meshnum 10");
gr->Box(); gr->Dens(a,"#","meshnum 10");
gr->SubPlot(2,2,3); gr->Title("several slices");
gr->Rotate(50,60); gr->Box(); gr->Dens(a1);
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Cont draw contour lines for surface. You can select automatic (default) or manual levels for contours, print contour labels, draw it on the surface (default) or at plane (as Dens). The sample code is:
int sample(mglGraph *gr)
{
mglData a,v(5); mgls_prepare2d(&a); v.a[0]=-0.5; v.a[1]=-0.15; v.a[2]=0; v.a[3]=0.15; v.a[4]=0.5;
gr->SubPlot(2,2,0); gr->Title("Cont plot (default)");
gr->Rotate(50,60); gr->Box(); gr->Cont(a);
gr->SubPlot(2,2,1); gr->Title("manual levels");
gr->Rotate(50,60); gr->Box(); gr->Cont(v,a);
gr->SubPlot(2,2,2); gr->Title("'\\_' style");
gr->Rotate(50,60); gr->Box(); gr->Cont(a,"_");
gr->SubPlot(2,2,3,""); gr->Title("'t' style");
gr->Box(); gr->Cont(a,"t");
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
ContF draw filled contours. You can select automatic (default) or manual levels for contours. The sample code is:
int sample(mglGraph *gr)
{
mglData a,v(5),a1(30,40,3); mgls_prepare2d(&a); v.a[0]=-0.5;
v.a[1]=-0.15; v.a[2]=0; v.a[3]=0.15; v.a[4]=0.5;
gr->SubPlot(2,2,0); gr->Title("ContF plot (default)");
gr->Rotate(50,60); gr->Box(); gr->ContF(a);
gr->SubPlot(2,2,1); gr->Title("manual levels");
gr->Rotate(50,60); gr->Box(); gr->ContF(v,a);
gr->SubPlot(2,2,2); gr->Title("'\\_' style");
gr->Rotate(50,60); gr->Box(); gr->ContF(a,"_");
gr->Fill(a1,"0.6*sin(2*pi*x+pi*(z+1)/2)*sin(3*pi*y+pi*z) + 0.4*cos(3*pi*(x*y)+pi*(z+1)^2/2)");
gr->SubPlot(2,2,3); gr->Title("several slices");
gr->Rotate(50,60); gr->Box(); gr->ContF(a1);
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
ContD is similar to ContF but with manual contour colors. The sample code is:
int sample(mglGraph *gr)
{
mglData a,v(5),a1(30,40,3); mgls_prepare2d(&a); v.a[0]=-0.5;
v.a[1]=-0.15; v.a[2]=0; v.a[3]=0.15; v.a[4]=0.5;
gr->SubPlot(2,2,0); gr->Title("ContD plot (default)");
gr->Rotate(50,60); gr->Box(); gr->ContD(a);
gr->SubPlot(2,2,1); gr->Title("manual levels");
gr->Rotate(50,60); gr->Box(); gr->ContD(v,a);
gr->SubPlot(2,2,2); gr->Title("'\\_' style");
gr->Rotate(50,60); gr->Box(); gr->ContD(a,"_");
gr->Fill(a1,"0.6*sin(2*pi*x+pi*(z+1)/2)*sin(3*pi*y+pi*z) + 0.4*cos(3*pi*(x*y)+pi*(z+1)^2/2)");
gr->SubPlot(2,2,3); gr->Title("several slices");
gr->Rotate(50,60); gr->Box(); gr->ContD(a1);
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
ContV draw vertical cylinders (belts) at contour lines. The sample code is:
int sample(mglGraph *gr)
{
mglData a,v(5); mgls_prepare2d(&a); v.a[0]=-0.5;
v.a[1]=-0.15; v.a[2]=0; v.a[3]=0.15; v.a[4]=0.5;
gr->SubPlot(2,2,0); gr->Title("ContV plot (default)");
gr->Rotate(50,60); gr->Box(); gr->ContV(a);
gr->SubPlot(2,2,1); gr->Title("manual levels");
gr->Rotate(50,60); gr->Box(); gr->ContV(v,a);
gr->SubPlot(2,2,2); gr->Title("'\\_' style");
gr->Rotate(50,60); gr->Box(); gr->ContV(a,"_");
gr->SubPlot(2,2,3); gr->Title("ContV and ContF");
gr->Rotate(50,60); gr->Box(); gr->Light(true);
gr->ContV(a); gr->ContF(a); gr->Cont(a,"k");
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Axial draw surfaces of rotation for contour lines. You can draw wire surfaces (‘#’ style) or ones rotated in other directions (‘x’, ‘z’ styles). The sample code is:
int sample(mglGraph *gr)
{
mglData a; mgls_prepare2d(&a);
gr->SubPlot(2,2,0); gr->Title("Axial plot (default)");
gr->Light(true); gr->Alpha(true); gr->Rotate(50,60);
gr->Box(); gr->Axial(a);
gr->SubPlot(2,2,1); gr->Title("'x' style"); gr->Rotate(50,60);
gr->Box(); gr->Axial(a,"x");
gr->SubPlot(2,2,2); gr->Title("'z' style"); gr->Rotate(50,60);
gr->Box(); gr->Axial(a,"z");
gr->SubPlot(2,2,3); gr->Title("'\\#' style"); gr->Rotate(50,60);
gr->Box(); gr->Axial(a,"#");
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
Grad draw gradient lines for matrix. The sample code is:
int sample(mglGraph *gr)
{
mglData a; mgls_prepare2d(&a);
gr->SubPlot(1,1,0,""); gr->Title("Grad plot");
gr->Box(); gr->Grad(a); gr->Dens(a,"{u8}w{q8}");
return 0;
}
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] |
This document was generated by Autobuild on July 16, 2012 using texi2html 1.82.