xref: /petsc/src/sys/classes/draw/utils/hists.c (revision 5b6bfdb9644f185dbf5e5a09b808ec241507e1e7)
1 
2 /*
3   Contains the data structure for plotting a histogram in a window with an axis.
4 */
5 #include <petscdraw.h>         /*I "petscdraw.h" I*/
6 #include <petsc/private/petscimpl.h>         /*I "petscsys.h" I*/
7 #include <petscviewer.h>         /*I "petscviewer.h" I*/
8 
9 PetscClassId PETSC_DRAWHG_CLASSID = 0;
10 
11 struct _p_PetscDrawHG {
12   PETSCHEADER(int);
13   PetscErrorCode (*destroy)(PetscDrawSP);
14   PetscErrorCode (*view)(PetscDrawSP,PetscViewer);
15   PetscDraw      win;
16   PetscDrawAxis  axis;
17   PetscReal      xmin,xmax;
18   PetscReal      ymin,ymax;
19   int            numBins;
20   int            maxBins;
21   PetscReal      *bins;
22   int            numValues;
23   int            maxValues;
24   PetscReal      *values;
25   int            color;
26   PetscBool      calcStats;
27   PetscBool      integerBins;
28 };
29 
30 #define CHUNKSIZE 100
31 
32 /*@C
33    PetscDrawHGCreate - Creates a histogram data structure.
34 
35    Collective on PetscDraw
36 
37    Input Parameters:
38 +  draw  - The window where the graph will be made
39 -  bins - The number of bins to use
40 
41    Output Parameters:
42 .  hist - The histogram context
43 
44    Notes: The difference between a bar chart, PetscDrawBar, and a histogram, PetscDrawHG, is explained here http://stattrek.com/statistics/charts/histogram.aspx?Tutorial=AP
45 
46    The histogram is only displayed when PetscDrawHGDraw() is called.
47 
48    The MPI communicator that owns the PetscDraw owns this PetscDrawHG, but the calls to set options and add data are ignored on all processes except the
49    zeroth MPI process in the communicator. All MPI processes in the communicator must call PetscDrawHGDraw() to display the updated graph.
50 
51    Level: intermediate
52 
53    Concepts: histogram^creating
54 
55 .seealso: PetscDrawHGDestroy(), PetscDrawHG, PetscDrawBarCreate(), PetscDrawBar, PetscDrawLGCreate(), PetscDrawLG, PetscDrawSPCreate(), PetscDrawSP,
56           PetscDrawHGSetNumberBins(), PetscDrawHGReset(), PetscDrawHGAddValue(), PetscDrawHGDraw(), PetscDrawHGSave(), PetscDrawHGView(), PetscDrawHGSetColor(),
57           PetscDrawHGSetLimits(), PetscDrawHGCalcStats(), PetscDrawHGIntegerBins(), PetscDrawHGGetAxis(), PetscDrawAxis, PetscDrawHGGetDraw()
58 
59 @*/
60 PetscErrorCode  PetscDrawHGCreate(PetscDraw draw,int bins,PetscDrawHG *hist)
61 {
62   PetscDrawHG    h;
63   PetscErrorCode ierr;
64 
65   PetscFunctionBegin;
66   PetscValidHeaderSpecific(draw, PETSC_DRAW_CLASSID,1);
67   PetscValidLogicalCollectiveInt(draw,bins,2);
68   PetscValidPointer(hist,3);
69 
70   ierr = PetscHeaderCreate(h,PETSC_DRAWHG_CLASSID,"DrawHG","Histogram","Draw",PetscObjectComm((PetscObject)draw),PetscDrawHGDestroy,NULL);CHKERRQ(ierr);
71   ierr = PetscLogObjectParent((PetscObject)draw,(PetscObject)h);CHKERRQ(ierr);
72 
73   ierr = PetscObjectReference((PetscObject)draw);CHKERRQ(ierr);
74   h->win = draw;
75 
76   h->view        = NULL;
77   h->destroy     = NULL;
78   h->color       = PETSC_DRAW_GREEN;
79   h->xmin        = PETSC_MAX_REAL;
80   h->xmax        = PETSC_MIN_REAL;
81   h->ymin        = 0.;
82   h->ymax        = 1.;
83   h->numBins     = bins;
84   h->maxBins     = bins;
85 
86   ierr = PetscMalloc1(h->maxBins,&h->bins);CHKERRQ(ierr);
87 
88   h->numValues   = 0;
89   h->maxValues   = CHUNKSIZE;
90   h->calcStats   = PETSC_FALSE;
91   h->integerBins = PETSC_FALSE;
92 
93   ierr = PetscMalloc1(h->maxValues,&h->values);CHKERRQ(ierr);
94   ierr = PetscLogObjectMemory((PetscObject)h,(h->maxBins + h->maxValues)*sizeof(PetscReal));CHKERRQ(ierr);
95 
96   ierr = PetscDrawAxisCreate(draw,&h->axis);CHKERRQ(ierr);
97   ierr = PetscLogObjectParent((PetscObject)h,(PetscObject)h->axis);CHKERRQ(ierr);
98 
99   *hist = h;
100   PetscFunctionReturn(0);
101 }
102 
103 /*@
104    PetscDrawHGSetNumberBins - Change the number of bins that are to be drawn.
105 
106    Logically Collective on PetscDrawHG
107 
108    Input Parameter:
109 +  hist - The histogram context.
110 -  bins  - The number of bins.
111 
112    Level: intermediate
113 
114    Concepts: histogram^setting number of bins
115 
116 .seealso: PetscDrawHGCreate(), PetscDrawHG, PetscDrawHGDraw(), PetscDrawHGIntegerBins()
117 
118 @*/
119 PetscErrorCode  PetscDrawHGSetNumberBins(PetscDrawHG hist, int bins)
120 {
121   PetscErrorCode ierr;
122 
123   PetscFunctionBegin;
124   PetscValidHeaderSpecific(hist,PETSC_DRAWHG_CLASSID,1);
125   PetscValidLogicalCollectiveInt(hist,bins,2);
126 
127   if (hist->maxBins < bins) {
128     ierr = PetscFree(hist->bins);CHKERRQ(ierr);
129     ierr = PetscMalloc1(bins, &hist->bins);CHKERRQ(ierr);
130     ierr = PetscLogObjectMemory((PetscObject)hist, (bins - hist->maxBins) * sizeof(PetscReal));CHKERRQ(ierr);
131     hist->maxBins = bins;
132   }
133   hist->numBins = bins;
134   PetscFunctionReturn(0);
135 }
136 
137 /*@
138   PetscDrawHGReset - Clears histogram to allow for reuse with new data.
139 
140   Logically Collective on PetscDrawHG
141 
142   Input Parameter:
143 . hist - The histogram context.
144 
145   Level: intermediate
146 
147   Concepts: histogram^resetting
148 
149 .seealso: PetscDrawHGCreate(), PetscDrawHG, PetscDrawHGDraw(), PetscDrawHGAddValue()
150 
151 @*/
152 PetscErrorCode  PetscDrawHGReset(PetscDrawHG hist)
153 {
154   PetscFunctionBegin;
155   PetscValidHeaderSpecific(hist,PETSC_DRAWHG_CLASSID,1);
156 
157   hist->xmin      = PETSC_MAX_REAL;
158   hist->xmax      = PETSC_MIN_REAL;
159   hist->ymin      = 0.0;
160   hist->ymax      = 0.0;
161   hist->numValues = 0;
162   PetscFunctionReturn(0);
163 }
164 
165 /*@C
166   PetscDrawHGDestroy - Frees all space taken up by histogram data structure.
167 
168   Collective on PetscDrawHG
169 
170   Input Parameter:
171 . hist - The histogram context
172 
173   Level: intermediate
174 
175 .seealso:  PetscDrawHGCreate(), PetscDrawHG
176 @*/
177 PetscErrorCode  PetscDrawHGDestroy(PetscDrawHG *hist)
178 {
179   PetscErrorCode ierr;
180 
181   PetscFunctionBegin;
182   if (!*hist) PetscFunctionReturn(0);
183   PetscValidHeaderSpecific(*hist,PETSC_DRAWHG_CLASSID,1);
184   if (--((PetscObject)(*hist))->refct > 0) {*hist = NULL; PetscFunctionReturn(0);}
185 
186   ierr = PetscFree((*hist)->bins);CHKERRQ(ierr);
187   ierr = PetscFree((*hist)->values);CHKERRQ(ierr);
188   ierr = PetscDrawAxisDestroy(&(*hist)->axis);CHKERRQ(ierr);
189   ierr = PetscDrawDestroy(&(*hist)->win);CHKERRQ(ierr);
190   ierr = PetscHeaderDestroy(hist);CHKERRQ(ierr);
191   PetscFunctionReturn(0);
192 }
193 
194 /*@
195   PetscDrawHGAddValue - Adds another value to the histogram.
196 
197   Logically Collective on PetscDrawHG
198 
199   Input Parameters:
200 + hist  - The histogram
201 - value - The value
202 
203   Level: intermediate
204 
205   Concepts: histogram^adding values
206 
207 .seealso: PetscDrawHGCreate(), PetscDrawHG, PetscDrawHGDraw(), PetscDrawHGAddValue(), PetscDrawHGReset()
208 @*/
209 PetscErrorCode  PetscDrawHGAddValue(PetscDrawHG hist, PetscReal value)
210 {
211   PetscFunctionBegin;
212   PetscValidHeaderSpecific(hist,PETSC_DRAWHG_CLASSID,1);
213 
214   /* Allocate more memory if necessary */
215   if (hist->numValues >= hist->maxValues) {
216     PetscReal      *tmp;
217     PetscErrorCode ierr;
218 
219     ierr = PetscMalloc1(hist->maxValues+CHUNKSIZE, &tmp);CHKERRQ(ierr);
220     ierr = PetscLogObjectMemory((PetscObject)hist, CHUNKSIZE * sizeof(PetscReal));CHKERRQ(ierr);
221     ierr = PetscMemcpy(tmp, hist->values, hist->maxValues * sizeof(PetscReal));CHKERRQ(ierr);
222     ierr = PetscFree(hist->values);CHKERRQ(ierr);
223 
224     hist->values     = tmp;
225     hist->maxValues += CHUNKSIZE;
226   }
227   /* I disagree with the original Petsc implementation here. There should be no overshoot, but rather the
228      stated convention of using half-open intervals (always the way to go) */
229   if (!hist->numValues) {
230     hist->xmin = value;
231     hist->xmax = value;
232 #if 1
233   } else {
234     /* Update limits */
235     if (value > hist->xmax) hist->xmax = value;
236     if (value < hist->xmin) hist->xmin = value;
237 #else
238   } else if (hist->numValues == 1) {
239     /* Update limits -- We need to overshoot the largest value somewhat */
240     if (value > hist->xmax) hist->xmax = value + 0.001*(value - hist->xmin)/hist->numBins;
241     if (value < hist->xmin) {
242       hist->xmin = value;
243       hist->xmax = hist->xmax + 0.001*(hist->xmax - hist->xmin)/hist->numBins;
244     }
245   } else {
246     /* Update limits -- We need to overshoot the largest value somewhat */
247     if (value > hist->xmax) hist->xmax = value + 0.001*(hist->xmax - hist->xmin)/hist->numBins;
248     if (value < hist->xmin) hist->xmin = value;
249 #endif
250   }
251 
252   hist->values[hist->numValues++] = value;
253   PetscFunctionReturn(0);
254 }
255 
256 /*@
257   PetscDrawHGDraw - Redraws a histogram.
258 
259   Collective on PetscDrawHG
260 
261   Input Parameter:
262 . hist - The histogram context
263 
264   Level: intermediate
265 
266 .seealso: PetscDrawHGCreate(), PetscDrawHG, PetscDrawHGDraw(), PetscDrawHGAddValue(), PetscDrawHGReset()
267 
268 @*/
269 PetscErrorCode  PetscDrawHGDraw(PetscDrawHG hist)
270 {
271   PetscDraw      draw;
272   PetscBool      isnull;
273   PetscReal      xmin,xmax,ymin,ymax,*bins,*values,binSize,binLeft,binRight,maxHeight,mean,var;
274   char           title[256];
275   char           xlabel[256];
276   PetscInt       numBins,numBinsOld,numValues,initSize,i,p,bcolor,color;
277   PetscMPIInt    rank;
278   PetscErrorCode ierr;
279 
280   PetscFunctionBegin;
281   PetscValidHeaderSpecific(hist,PETSC_DRAWHG_CLASSID,1);
282   ierr = PetscDrawIsNull(hist->win,&isnull);CHKERRQ(ierr);
283   if (isnull) PetscFunctionReturn(0);
284   ierr = MPI_Comm_rank(PetscObjectComm((PetscObject)hist),&rank);CHKERRQ(ierr);
285 
286   if ((hist->xmin >= hist->xmax) || (hist->ymin >= hist->ymax)) PetscFunctionReturn(0);
287   if (hist->numValues < 1) PetscFunctionReturn(0);
288 
289   color = hist->color;
290   if (color == PETSC_DRAW_ROTATE) bcolor = PETSC_DRAW_BLACK+1;
291   else bcolor = color;
292 
293   xmin      = hist->xmin;
294   xmax      = hist->xmax;
295   ymin      = hist->ymin;
296   ymax      = hist->ymax;
297   numValues = hist->numValues;
298   values    = hist->values;
299   mean      = 0.0;
300   var       = 0.0;
301 
302   draw = hist->win;
303   ierr = PetscDrawCheckResizedWindow(draw);CHKERRQ(ierr);
304   ierr = PetscDrawClear(draw);CHKERRQ(ierr);
305 
306   if (xmin == xmax) {
307     /* Calculate number of points in each bin */
308     bins    = hist->bins;
309     bins[0] = 0.;
310     for (p = 0; p < numValues; p++) {
311       if (values[p] == xmin) bins[0]++;
312       mean += values[p];
313       var  += values[p]*values[p];
314     }
315     maxHeight = bins[0];
316     if (maxHeight > ymax) ymax = hist->ymax = maxHeight;
317     xmax = xmin + 1;
318     ierr = PetscDrawAxisSetLimits(hist->axis, xmin, xmax, ymin, ymax);CHKERRQ(ierr);
319     if (hist->calcStats) {
320       mean /= numValues;
321       if (numValues > 1) var = (var - numValues*mean*mean) / (numValues-1);
322       else var = 0.0;
323       ierr = PetscSNPrintf(title, 256, "Mean: %g  Var: %g", (double)mean, (double)var);CHKERRQ(ierr);
324       ierr = PetscSNPrintf(xlabel,256, "Total: %D", numValues);CHKERRQ(ierr);
325       ierr = PetscDrawAxisSetLabels(hist->axis, title, xlabel, NULL);CHKERRQ(ierr);
326     }
327     ierr = PetscDrawAxisDraw(hist->axis);CHKERRQ(ierr);
328     ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr);
329     if (!rank) { /* Draw bins */
330       binLeft  = xmin;
331       binRight = xmax;
332       ierr = PetscDrawRectangle(draw,binLeft,ymin,binRight,bins[0],bcolor,bcolor,bcolor,bcolor);CHKERRQ(ierr);
333       ierr = PetscDrawLine(draw,binLeft,ymin,binLeft,bins[0],PETSC_DRAW_BLACK);CHKERRQ(ierr);
334       ierr = PetscDrawLine(draw,binRight,ymin,binRight,bins[0],PETSC_DRAW_BLACK);CHKERRQ(ierr);
335       ierr = PetscDrawLine(draw,binLeft,bins[0],binRight,bins[0],PETSC_DRAW_BLACK);CHKERRQ(ierr);
336     }
337     ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr);
338   } else {
339     numBins    = hist->numBins;
340     numBinsOld = hist->numBins;
341     if (hist->integerBins && (((int) xmax - xmin) + 1.0e-05 > xmax - xmin)) {
342       initSize = (int) ((int) xmax - xmin)/numBins;
343       while (initSize*numBins != (int) xmax - xmin) {
344         initSize = PetscMax(initSize - 1, 1);
345         numBins  = (int) ((int) xmax - xmin)/initSize;
346         ierr     = PetscDrawHGSetNumberBins(hist, numBins);CHKERRQ(ierr);
347       }
348     }
349     binSize = (xmax - xmin)/numBins;
350     bins    = hist->bins;
351 
352     ierr = PetscMemzero(bins, numBins * sizeof(PetscReal));CHKERRQ(ierr);
353 
354     maxHeight = 0.0;
355     for (i = 0; i < numBins; i++) {
356       binLeft  = xmin + binSize*i;
357       binRight = xmin + binSize*(i+1);
358       for (p = 0; p < numValues; p++) {
359         if ((values[p] >= binLeft) && (values[p] < binRight)) bins[i]++;
360         /* Handle last bin separately */
361         if ((i == numBins-1) && (values[p] == binRight)) bins[i]++;
362         if (!i) {
363           mean += values[p];
364           var  += values[p]*values[p];
365         }
366       }
367       maxHeight = PetscMax(maxHeight, bins[i]);
368     }
369     if (maxHeight > ymax) ymax = hist->ymax = maxHeight;
370 
371     ierr = PetscDrawAxisSetLimits(hist->axis, xmin, xmax, ymin, ymax);CHKERRQ(ierr);
372     if (hist->calcStats) {
373       mean /= numValues;
374       if (numValues > 1) var = (var - numValues*mean*mean) / (numValues-1);
375       else var = 0.0;
376       ierr = PetscSNPrintf(title, 256,"Mean: %g  Var: %g", (double)mean, (double)var);CHKERRQ(ierr);
377       ierr = PetscSNPrintf(xlabel,256, "Total: %D", numValues);CHKERRQ(ierr);
378       ierr = PetscDrawAxisSetLabels(hist->axis, title, xlabel, NULL);CHKERRQ(ierr);
379     }
380     ierr = PetscDrawAxisDraw(hist->axis);CHKERRQ(ierr);
381     ierr = PetscDrawCollectiveBegin(draw);CHKERRQ(ierr);
382     if (!rank) { /* Draw bins */
383       for (i = 0; i < numBins; i++) {
384         binLeft  = xmin + binSize*i;
385         binRight = xmin + binSize*(i+1);
386         ierr = PetscDrawRectangle(draw,binLeft,ymin,binRight,bins[i],bcolor,bcolor,bcolor,bcolor);CHKERRQ(ierr);
387         ierr = PetscDrawLine(draw,binLeft,ymin,binLeft,bins[i],PETSC_DRAW_BLACK);CHKERRQ(ierr);
388         ierr = PetscDrawLine(draw,binRight,ymin,binRight,bins[i],PETSC_DRAW_BLACK);CHKERRQ(ierr);
389         ierr = PetscDrawLine(draw,binLeft,bins[i],binRight,bins[i],PETSC_DRAW_BLACK);CHKERRQ(ierr);
390         if (color == PETSC_DRAW_ROTATE && bins[i]) bcolor++;
391         if (bcolor > PETSC_DRAW_BASIC_COLORS-1) bcolor = PETSC_DRAW_BLACK+1;
392       }
393     }
394     ierr = PetscDrawCollectiveEnd(draw);CHKERRQ(ierr);
395     ierr = PetscDrawHGSetNumberBins(hist,numBinsOld);CHKERRQ(ierr);
396   }
397 
398   ierr = PetscDrawFlush(draw);CHKERRQ(ierr);
399   ierr = PetscDrawPause(draw);CHKERRQ(ierr);
400   PetscFunctionReturn(0);
401 }
402 
403 /*@
404   PetscDrawHGSave - Saves a drawn image
405 
406   Collective on PetscDrawHG
407 
408   Input Parameter:
409 . hist - The histogram context
410 
411   Level: intermediate
412 
413   Concepts: histogram^saving
414 
415 .seealso:  PetscDrawHGCreate(), PetscDrawHGGetDraw(), PetscDrawSetSave(), PetscDrawSave(), PetscDrawHGDraw()
416 @*/
417 PetscErrorCode  PetscDrawHGSave(PetscDrawHG hg)
418 {
419   PetscErrorCode ierr;
420 
421   PetscFunctionBegin;
422   PetscValidHeaderSpecific(hg,PETSC_DRAWHG_CLASSID,1);
423   ierr = PetscDrawSave(hg->win);CHKERRQ(ierr);
424   PetscFunctionReturn(0);
425 }
426 
427 /*@
428   PetscDrawHGView - Prints the histogram information.
429 
430   Not collective
431 
432   Input Parameter:
433 . hist - The histogram context
434 
435   Level: beginner
436 
437 .seealso:  PetscDrawHGCreate(), PetscDrawHGGetDraw(), PetscDrawSetSave(), PetscDrawSave(), PetscDrawHGDraw()
438 
439 .keywords:  draw, histogram
440 @*/
441 PetscErrorCode  PetscDrawHGView(PetscDrawHG hist,PetscViewer viewer)
442 {
443   PetscReal      xmax,xmin,*bins,*values,binSize,binLeft,binRight,mean,var;
444   PetscErrorCode ierr;
445   PetscInt       numBins,numBinsOld,numValues,initSize,i,p;
446 
447   PetscFunctionBegin;
448   PetscValidHeaderSpecific(hist,PETSC_DRAWHG_CLASSID,1);
449 
450   if ((hist->xmin > hist->xmax) || (hist->ymin >= hist->ymax)) PetscFunctionReturn(0);
451   if (hist->numValues < 1) PetscFunctionReturn(0);
452 
453   if (!viewer){
454     ierr = PetscViewerASCIIGetStdout(PetscObjectComm((PetscObject)hist),&viewer);CHKERRQ(ierr);
455   }
456   ierr = PetscObjectPrintClassNamePrefixType((PetscObject)hist,viewer);CHKERRQ(ierr);
457   xmax      = hist->xmax;
458   xmin      = hist->xmin;
459   numValues = hist->numValues;
460   values    = hist->values;
461   mean      = 0.0;
462   var       = 0.0;
463   if (xmax == xmin) {
464     /* Calculate number of points in the bin */
465     bins    = hist->bins;
466     bins[0] = 0.;
467     for (p = 0; p < numValues; p++) {
468       if (values[p] == xmin) bins[0]++;
469       mean += values[p];
470       var  += values[p]*values[p];
471     }
472     /* Draw bins */
473     ierr = PetscViewerASCIIPrintf(viewer, "Bin %2d (%6.2g - %6.2g): %.0g\n", 0, (double)xmin, (double)xmax, (double)bins[0]);CHKERRQ(ierr);
474   } else {
475     numBins    = hist->numBins;
476     numBinsOld = hist->numBins;
477     if (hist->integerBins && (((int) xmax - xmin) + 1.0e-05 > xmax - xmin)) {
478       initSize = (int) ((int) xmax - xmin)/numBins;
479       while (initSize*numBins != (int) xmax - xmin) {
480         initSize = PetscMax(initSize - 1, 1);
481         numBins  = (int) ((int) xmax - xmin)/initSize;
482         ierr     = PetscDrawHGSetNumberBins(hist, numBins);CHKERRQ(ierr);
483       }
484     }
485     binSize = (xmax - xmin)/numBins;
486     bins    = hist->bins;
487 
488     /* Calculate number of points in each bin */
489     ierr = PetscMemzero(bins, numBins * sizeof(PetscReal));CHKERRQ(ierr);
490     for (i = 0; i < numBins; i++) {
491       binLeft  = xmin + binSize*i;
492       binRight = xmin + binSize*(i+1);
493       for (p = 0; p < numValues; p++) {
494         if ((values[p] >= binLeft) && (values[p] < binRight)) bins[i]++;
495         /* Handle last bin separately */
496         if ((i == numBins-1) && (values[p] == binRight)) bins[i]++;
497         if (!i) {
498           mean += values[p];
499           var  += values[p]*values[p];
500         }
501       }
502     }
503     /* Draw bins */
504     for (i = 0; i < numBins; i++) {
505       binLeft  = xmin + binSize*i;
506       binRight = xmin + binSize*(i+1);
507       ierr = PetscViewerASCIIPrintf(viewer, "Bin %2d (%6.2g - %6.2g): %.0g\n", (int)i, (double)binLeft, (double)binRight, (double)bins[i]);CHKERRQ(ierr);
508     }
509     ierr = PetscDrawHGSetNumberBins(hist, numBinsOld);CHKERRQ(ierr);
510   }
511 
512   if (hist->calcStats) {
513     mean /= numValues;
514     if (numValues > 1) var = (var - numValues*mean*mean) / (numValues-1);
515     else var = 0.0;
516     ierr = PetscViewerASCIIPrintf(viewer, "Mean: %g  Var: %g\n", (double)mean, (double)var);CHKERRQ(ierr);
517     ierr = PetscViewerASCIIPrintf(viewer, "Total: %D\n", numValues);CHKERRQ(ierr);
518   }
519   PetscFunctionReturn(0);
520 }
521 
522 /*@
523   PetscDrawHGSetColor - Sets the color the bars will be drawn with.
524 
525   Logically Collective on PetscDrawHG
526 
527   Input Parameters:
528 + hist - The histogram context
529 - color - one of the colors defined in petscdraw.h or PETSC_DRAW_ROTATE to make each bar a
530           different color
531 
532   Level: intermediate
533 
534 .seealso:  PetscDrawHGCreate(), PetscDrawHGGetDraw(), PetscDrawSetSave(), PetscDrawSave(), PetscDrawHGDraw(), PetscDrawHGGetAxis()
535 
536 @*/
537 PetscErrorCode  PetscDrawHGSetColor(PetscDrawHG hist,int color)
538 {
539   PetscFunctionBegin;
540   PetscValidHeaderSpecific(hist,PETSC_DRAWHG_CLASSID,1);
541 
542   hist->color = color;
543   PetscFunctionReturn(0);
544 }
545 
546 /*@
547   PetscDrawHGSetLimits - Sets the axis limits for a histogram. If more
548   points are added after this call, the limits will be adjusted to
549   include those additional points.
550 
551   Logically Collective on PetscDrawHG
552 
553   Input Parameters:
554 + hist - The histogram context
555 - x_min,x_max,y_min,y_max - The limits
556 
557   Level: intermediate
558 
559   Concepts: histogram^setting axis
560 
561 .seealso:  PetscDrawHGCreate(), PetscDrawHGGetDraw(), PetscDrawSetSave(), PetscDrawSave(), PetscDrawHGDraw(), PetscDrawHGGetAxis()
562 
563 @*/
564 PetscErrorCode  PetscDrawHGSetLimits(PetscDrawHG hist, PetscReal x_min, PetscReal x_max, int y_min, int y_max)
565 {
566   PetscFunctionBegin;
567   PetscValidHeaderSpecific(hist,PETSC_DRAWHG_CLASSID,1);
568 
569   hist->xmin = x_min;
570   hist->xmax = x_max;
571   hist->ymin = y_min;
572   hist->ymax = y_max;
573   PetscFunctionReturn(0);
574 }
575 
576 /*@
577   PetscDrawHGCalcStats - Turns on calculation of descriptive statistics
578 
579   Not collective
580 
581   Input Parameters:
582 + hist - The histogram context
583 - calc - Flag for calculation
584 
585   Level: intermediate
586 
587 .keywords:  draw, histogram, statistics
588 
589 .seealso:  PetscDrawHGCreate(), PetscDrawHGAddValue(), PetscDrawHGView(), PetscDrawHGDraw()
590 
591 @*/
592 PetscErrorCode  PetscDrawHGCalcStats(PetscDrawHG hist, PetscBool calc)
593 {
594   PetscFunctionBegin;
595   PetscValidHeaderSpecific(hist,PETSC_DRAWHG_CLASSID,1);
596 
597   hist->calcStats = calc;
598   PetscFunctionReturn(0);
599 }
600 
601 /*@
602   PetscDrawHGIntegerBins - Turns on integer width bins
603 
604   Not collective
605 
606   Input Parameters:
607 + hist - The histogram context
608 - ints - Flag for integer width bins
609 
610   Level: intermediate
611 
612 .keywords:  draw, histogram, statistics
613 
614 .seealso:  PetscDrawHGCreate(), PetscDrawHGAddValue(), PetscDrawHGView(), PetscDrawHGDraw(), PetscDrawHGSetColor()
615 
616 @*/
617 PetscErrorCode  PetscDrawHGIntegerBins(PetscDrawHG hist, PetscBool ints)
618 {
619   PetscFunctionBegin;
620   PetscValidHeaderSpecific(hist,PETSC_DRAWHG_CLASSID,1);
621 
622   hist->integerBins = ints;
623   PetscFunctionReturn(0);
624 }
625 
626 /*@C
627   PetscDrawHGGetAxis - Gets the axis context associated with a histogram.
628   This is useful if one wants to change some axis property, such as
629   labels, color, etc. The axis context should not be destroyed by the
630   application code.
631 
632   Not Collective, PetscDrawAxis is parallel if PetscDrawHG is parallel
633 
634   Input Parameter:
635 . hist - The histogram context
636 
637   Output Parameter:
638 . axis - The axis context
639 
640   Level: intermediate
641 
642 .seealso:  PetscDrawHGCreate(), PetscDrawHGAddValue(), PetscDrawHGView(), PetscDrawHGDraw(), PetscDrawHGSetColor(), PetscDrawAxis, PetscDrawHGSetLimits()
643 
644 @*/
645 PetscErrorCode  PetscDrawHGGetAxis(PetscDrawHG hist,PetscDrawAxis *axis)
646 {
647   PetscFunctionBegin;
648   PetscValidHeaderSpecific(hist,PETSC_DRAWHG_CLASSID,1);
649   PetscValidPointer(axis,2);
650   *axis = hist->axis;
651   PetscFunctionReturn(0);
652 }
653 
654 /*@C
655   PetscDrawHGGetDraw - Gets the draw context associated with a histogram.
656 
657   Not Collective, PetscDraw is parallel if PetscDrawHG is parallel
658 
659   Input Parameter:
660 . hist - The histogram context
661 
662   Output Parameter:
663 . draw  - The draw context
664 
665   Level: intermediate
666 
667 .seealso:  PetscDrawHGCreate(), PetscDrawHGAddValue(), PetscDrawHGView(), PetscDrawHGDraw(), PetscDrawHGSetColor(), PetscDrawAxis, PetscDrawHGSetLimits()
668 
669 @*/
670 PetscErrorCode  PetscDrawHGGetDraw(PetscDrawHG hist,PetscDraw *draw)
671 {
672   PetscFunctionBegin;
673   PetscValidHeaderSpecific(hist,PETSC_DRAWHG_CLASSID,1);
674   PetscValidPointer(draw,2);
675   *draw = hist->win;
676   PetscFunctionReturn(0);
677 }
678 
679