Bar chart demo

Image obtained by using pbm driver and then converted to png.

 1 #pragma _ipath "./"
 2 #include "plcdemos.h"
 3 
 4 void
 5 plfbox(PLFLT x0, PLFLT y0);
 6 
 7 
 8 int
 9 main(int argc, char *argv[])
10 {
11     int i;
12     char string[20];
13     PLFLT y0[10];
14 
15 
16     (void) plParseOpts(&argc, argv, PL_PARSE_FULL);
17 
18 
19     plinit();
20 
21     pladv(0);
22     plvsta();
23     plwind(1980.0, 1990.0, 0.0, 35.0);
24     plbox("bc", 1.0, 0, "bcnv", 10.0, 0);
25     plcol0(2);
26     pllab("Year", "Widget Sales (millions)", "#frPLplot Example 12");
27 
28     y0[0] = 5;
29     y0[1] = 15;
30     y0[2] = 12;
31     y0[3] = 24;
32     y0[4] = 28;
33     y0[5] = 30;
34     y0[6] = 20;
35     y0[7] = 8;
36     y0[8] = 12;
37     y0[9] = 3;
38 
39     for (i = 0; i < 10; i++) {
40 	plcol0(i + 1);
41 	plpsty(0);
42 	plfbox((1980. + i), y0[i]);
43 	sprintf(string, "%.0f", y0[i]);
44 	plptex((1980. + i + .5), (y0[i] + 1.), 1.0, 0.0, .5, string);
45 	sprintf(string, "%d", 1980 + i);
46 	plmtex("b", 1.0, ((i + 1) * .1 - .05), 0.5, string);
47     }
48 
49 
50     plend();
51     exit(0);
52 }
53 
54 void
55 plfbox(PLFLT x0, PLFLT y0)
56 {
57     PLFLT x[4], y[4];
58 
59     x[0] = x0;
60     y[0] = 0.;
61     x[1] = x0;
62     y[1] = y0;
63     x[2] = x0 + 1.;
64     y[2] = y0;
65     x[3] = x0 + 1.;
66     y[3] = 0.;
67     plfill(4, x, y);
68     plcol0(1);
69     pllsty(1);
70     plline(4, x, y);
71 }

Copyright 2006 Roman Putanowicz

Email: putanowr at twins.pk.edu.pl

Last Modified: Thu, 13 Jul 2006 15:37:21 CEST

Made with PubTal 3.1.3