Actual source code: ex12.c
petsc-3.14.6 2021-03-30
2: static char help[] = "Makes a simple bar graph.\n";
4: #include <petscsys.h>
5: #include <petscdraw.h>
7: int main(int argc,char **argv)
8: {
9: PetscDraw draw;
10: PetscDrawBar bar;
11: PetscDrawAxis axis;
12: PetscErrorCode ierr;
13: int color = PETSC_DRAW_ROTATE;
14: const char *xlabel,*ylabel,*toplabel;
15: const PetscReal values[] = {.3, .5, .05, .11};
16: const char *const labels[] = {"A","B","C","D",NULL};
17: PetscReal limits[2] = {0,0.55}; PetscInt nlimits = 2;
18: PetscBool nolabels,setlimits;
20: xlabel = "X-axis Label"; toplabel = "Top Label"; ylabel = "Y-axis Label";
22: PetscInitialize(&argc,&argv,NULL,help);if (ierr) return ierr;
23: PetscOptionsHasName(NULL,NULL,"-nolabels",&nolabels);
24: if (nolabels) { xlabel = NULL; ylabel = NULL; toplabel = NULL; }
25: PetscOptionsGetRealArray(NULL,NULL,"-limits",limits,&nlimits,&setlimits);
27: PetscDrawCreate(PETSC_COMM_WORLD,NULL,"Title",PETSC_DECIDE,PETSC_DECIDE,400,300,&draw);
28: PetscDrawSetFromOptions(draw);
29: PetscDrawBarCreate(draw,&bar);
31: PetscDrawBarGetAxis(bar,&axis);
32: PetscDrawAxisSetColors(axis,PETSC_DRAW_BLACK,PETSC_DRAW_RED,PETSC_DRAW_BLUE);
33: PetscDrawAxisSetLabels(axis,toplabel,xlabel,ylabel);
34: PetscDrawBarSetColor(bar,color);
35: PetscDrawBarSetFromOptions(bar);
37: if (setlimits) {PetscDrawBarSetLimits(bar,limits[0],limits[1]);}
38: PetscDrawBarSetData(bar,4,values,labels);
39: PetscDrawBarDraw(bar);
40: PetscDrawBarSave(bar);
42: PetscDrawBarDestroy(&bar);
43: PetscDrawDestroy(&draw);
44: PetscFinalize();
45: return ierr;
46: }
50: /*TEST
52: build:
53: requires: x
55: test:
56: output_file: output/ex1_1.out
58: TEST*/