Actual source code: ex9.c
2: static char help[] = "Makes a simple histogram.\n";
4: #include <petscsys.h>
5: #include <petscdraw.h>
7: int main(int argc,char **argv)
8: {
9: PetscDraw draw;
10: PetscDrawHG hist;
11: PetscDrawAxis axis;
12: int n = 20,i,x = 0,y = 0,width = 400,height = 300,bins = 8;
13: PetscInt w = 400,h = 300,nn = 20,b = 8,c = PETSC_DRAW_GREEN;
14: int color = PETSC_DRAW_GREEN;
15: const char *xlabel,*ylabel,*toplabel;
16: PetscReal xd;
17: PetscBool flg;
19: xlabel = "X-axis Label"; toplabel = "Top Label"; ylabel = "Y-axis Label";
21: PetscInitialize(&argc,&argv,NULL,help);
22: PetscOptionsGetInt(NULL,NULL,"-width",&w,NULL);
23: PetscOptionsGetInt(NULL,NULL,"-height",&h,NULL);
24: PetscOptionsGetInt(NULL,NULL,"-n",&nn,NULL);
25: PetscOptionsGetInt(NULL,NULL,"-bins",&b,NULL);
26: PetscOptionsGetInt(NULL,NULL,"-color",&c,NULL);
27: PetscOptionsHasName(NULL,NULL,"-nolabels",&flg);
28: width = (int) w; height = (int)h; n = (int)nn; bins = (int) b; color = (int) c;
29: if (flg) { xlabel = NULL; ylabel = NULL; toplabel = NULL; }
31: PetscDrawCreate(PETSC_COMM_WORLD,0,"Title",x,y,width,height,&draw);
32: PetscDrawSetFromOptions(draw);
33: PetscDrawHGCreate(draw,bins,&hist);
34: PetscDrawHGSetColor(hist,color);
35: PetscDrawHGGetAxis(hist,&axis);
36: PetscDrawAxisSetColors(axis,PETSC_DRAW_BLACK,PETSC_DRAW_RED,PETSC_DRAW_BLUE);
37: PetscDrawAxisSetLabels(axis,toplabel,xlabel,ylabel);
38: /*PetscDrawHGSetFromOptions(hist);*/
40: for (i=0; i<n; i++) {
41: xd = (PetscReal)(i - 5);
42: PetscDrawHGAddValue(hist,xd*xd);
43: }
44: PetscDrawHGDraw(hist);
45: PetscDrawHGSave(hist);
47: PetscDrawHGDestroy(&hist);
48: PetscDrawDestroy(&draw);
49: PetscFinalize();
50: return 0;
51: }
53: /*TEST
55: build:
56: requires: x
58: test:
59: output_file: output/ex1_1.out
61: TEST*/