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