Actual source code: ex12.c

petsc-3.7.3 2016-08-01
Report Typos and Errors
  2: static char help[] = "Makes a simple bar graph.\n";

  4: #include <petscsys.h>
  5: #include <petscdraw.h>

  9: int main(int argc,char **argv)
 10: {
 11:   PetscDraw         draw;
 12:   PetscDrawBar      bar;
 13:   PetscDrawAxis     axis;
 14:   PetscErrorCode    ierr;
 15:   int               color = PETSC_DRAW_ROTATE;
 16:   const char        *xlabel,*ylabel,*toplabel;
 17:   const PetscReal   values[] = {.3, .5, .05, .11};
 18:   const char *const labels[] = {"A","B","C","D",NULL};
 19:   PetscReal         limits[2] = {0,0.55}; PetscInt nlimits = 2;
 20:   PetscBool         nolabels,setlimits;

 22:   xlabel = "X-axis Label"; toplabel = "Top Label"; ylabel = "Y-axis Label";

 24:   PetscInitialize(&argc,&argv,NULL,help);
 25:   PetscOptionsHasName(NULL,NULL,"-nolabels",&nolabels);
 26:   if (nolabels) { xlabel = NULL; ylabel = NULL; toplabel = NULL; }
 27:   PetscOptionsGetRealArray(NULL,NULL,"-limits",limits,&nlimits,&setlimits);

 29:   PetscDrawCreate(PETSC_COMM_WORLD,NULL,"Title",PETSC_DECIDE,PETSC_DECIDE,400,300,&draw);
 30:   PetscDrawSetFromOptions(draw);
 31:   PetscDrawBarCreate(draw,&bar);

 33:   PetscDrawBarGetAxis(bar,&axis);
 34:   PetscDrawAxisSetColors(axis,PETSC_DRAW_BLACK,PETSC_DRAW_RED,PETSC_DRAW_BLUE);
 35:   PetscDrawAxisSetLabels(axis,toplabel,xlabel,ylabel);
 36:   PetscDrawBarSetColor(bar,color);
 37:   PetscDrawBarSetFromOptions(bar);

 39:   if (setlimits) {PetscDrawBarSetLimits(bar,limits[0],limits[1]);}
 40:   PetscDrawBarSetData(bar,4,values,labels);
 41:   PetscDrawBarDraw(bar);
 42:   PetscDrawBarSave(bar);

 44:   PetscDrawBarDestroy(&bar);
 45:   PetscDrawDestroy(&draw);
 46:   PetscFinalize();
 47:   return 0;
 48: }