Actual source code: ex12.c

petsc-3.6.1 2015-08-06
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};

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

 22:   PetscInitialize(&argc,&argv,(char*)0,help);
 23:   PetscDrawCreate(PETSC_COMM_SELF,0,"Title",PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,PETSC_DECIDE,&draw);
 24:   PetscDrawSetFromOptions(draw);
 25:   PetscDrawBarCreate(draw,&bar);
 26:   PetscDrawBarGetAxis(bar,&axis);
 27:   PetscDrawAxisSetColors(axis,PETSC_DRAW_BLACK,PETSC_DRAW_RED,PETSC_DRAW_BLUE);
 28:   PetscDrawAxisSetLabels(axis,toplabel,xlabel,ylabel);

 30:   PetscDrawBarSetColor(bar,color);
 31:   PetscDrawBarSetData(bar,4,values,labels);
 32:   PetscDrawBarSetFromOptions(bar);
 33:   PetscDrawBarDraw(bar);
 34:   PetscDrawFlush(draw);

 36:   PetscDrawBarDestroy(&bar);
 37:   PetscDrawDestroy(&draw);
 38:   PetscFinalize();
 39:   return 0;
 40: }