Actual source code: ex9.c
2: static char help[] = "Makes a simple histogram.\n";
4: #include <petscsys.h>
5: #include <petscdraw.h>
7: int main(int argc, char **argv)
8: {
9: PetscDraw draw;
10: PetscDrawHG hist;
11: PetscDrawAxis axis;
12: int n = 20, i, x = 0, y = 0, width = 400, height = 300, bins = 8;
13: PetscInt w = 400, h = 300, nn = 20, b = 8, c = PETSC_DRAW_GREEN;
14: int color = PETSC_DRAW_GREEN;
15: const char *xlabel, *ylabel, *toplabel;
16: PetscReal xd;
17: PetscBool flg;
19: xlabel = "X-axis Label";
20: toplabel = "Top Label";
21: ylabel = "Y-axis Label";
24: PetscInitialize(&argc, &argv, NULL, help);
25: PetscOptionsGetInt(NULL, NULL, "-width", &w, NULL);
26: PetscOptionsGetInt(NULL, NULL, "-height", &h, NULL);
27: PetscOptionsGetInt(NULL, NULL, "-n", &nn, NULL);
28: PetscOptionsGetInt(NULL, NULL, "-bins", &b, NULL);
29: PetscOptionsGetInt(NULL, NULL, "-color", &c, NULL);
30: PetscOptionsHasName(NULL, NULL, "-nolabels", &flg);
31: width = (int)w;
32: height = (int)h;
33: n = (int)nn;
34: bins = (int)b;
35: color = (int)c;
36: if (flg) {
37: xlabel = NULL;
38: ylabel = NULL;
39: toplabel = NULL;
40: }
42: PetscDrawCreate(PETSC_COMM_WORLD, 0, "Title", x, y, width, height, &draw);
43: PetscDrawSetFromOptions(draw);
44: PetscDrawHGCreate(draw, bins, &hist);
45: PetscDrawHGSetColor(hist, color);
46: PetscDrawHGGetAxis(hist, &axis);
47: PetscDrawAxisSetColors(axis, PETSC_DRAW_BLACK, PETSC_DRAW_RED, PETSC_DRAW_BLUE);
48: PetscDrawAxisSetLabels(axis, toplabel, xlabel, ylabel);
49: /* PetscDrawHGSetFromOptions(hist); */
51: for (i = 0; i < n; i++) {
52: xd = (PetscReal)(i - 5);
53: PetscDrawHGAddValue(hist, xd * xd);
54: }
55: PetscDrawHGDraw(hist);
56: PetscDrawHGSave(hist);
58: PetscDrawHGDestroy(&hist);
59: PetscDrawDestroy(&draw);
60: PetscFinalize();
61: return 0;
62: }
64: /*TEST
66: build:
67: requires: x
69: test:
70: output_file: output/ex1_1.out
72: TEST*/