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