1 //      Bar chart demo.
2 //
3 
4 #include "plcdemos.h"
5 
6 void
7 plfbox( PLFLT x0, PLFLT y0 );
8 
9 //--------------------------------------------------------------------------
10 // main
11 //
12 // Does a simple bar chart, using color fill.  If color fill is
13 // unavailable, pattern fill is used instead (automatic).
14 //--------------------------------------------------------------------------
15 
16 int
main(int argc,char * argv[])17 main( int argc, char *argv[] )
18 {
19     int          i;
20     char         string[20];
21     PLFLT        y0[10];
22 
23     static PLFLT pos[]   = { 0.0, 0.25, 0.5, 0.75, 1.0 };
24     static PLFLT red[]   = { 0.0, 0.25, 0.5, 1.0, 1.0 };
25     static PLFLT green[] = { 1.0, 0.5, 0.5, 0.5, 1.0 };
26     static PLFLT blue[]  = { 1.0, 1.0, 0.5, 0.25, 0.0 };
27 
28 // Parse and process command line arguments
29 
30     (void) plparseopts( &argc, argv, PL_PARSE_FULL );
31 
32 // Initialize plplot
33 
34     plinit();
35 
36     pladv( 0 );
37     plvsta();
38     plwind( 1980.0, 1990.0, 0.0, 35.0 );
39     plbox( "bc", 1.0, 0, "bcnv", 10.0, 0 );
40     plcol0( 2 );
41     pllab( "Year", "Widget Sales (millions)", "#frPLplot Example 12" );
42 
43     y0[0] = 5;
44     y0[1] = 15;
45     y0[2] = 12;
46     y0[3] = 24;
47     y0[4] = 28;
48     y0[5] = 30;
49     y0[6] = 20;
50     y0[7] = 8;
51     y0[8] = 12;
52     y0[9] = 3;
53 
54     plscmap1l( 1, 5, pos, red, green, blue, NULL );
55 
56     for ( i = 0; i < 10; i++ )
57     {
58         //plcol0(i + 1);
59         plcol1( i / 9.0 );
60         plpsty( 0 );
61         plfbox( ( 1980. + i ), y0[i] );
62         sprintf( string, "%.0f", y0[i] );
63         plptex( ( 1980. + i + .5 ), ( y0[i] + 1. ), 1.0, 0.0, .5, string );
64         sprintf( string, "%d", 1980 + i );
65         plmtex( "b", 1.0, ( ( i + 1 ) * .1 - .05 ), 0.5, string );
66     }
67 
68 // Don't forget to call plend() to finish off!
69 
70     plend();
71     exit( 0 );
72 }
73 
74 void
plfbox(PLFLT x0,PLFLT y0)75 plfbox( PLFLT x0, PLFLT y0 )
76 {
77     PLFLT x[4], y[4];
78 
79     x[0] = x0;
80     y[0] = 0.;
81     x[1] = x0;
82     y[1] = y0;
83     x[2] = x0 + 1.;
84     y[2] = y0;
85     x[3] = x0 + 1.;
86     y[3] = 0.;
87     plfill( 4, x, y );
88     plcol0( 1 );
89     pllsty( 1 );
90     plline( 4, x, y );
91 }
92