1 //      Bar chart demo.
2 //
3 
4 import std.string;
5 
6 import plplot;
7 
8 //--------------------------------------------------------------------------
9 // main
10 //
11 // Does a simple bar chart, using color fill.  If color fill is
12 // unavailable, pattern fill is used instead (automatic).
13 //--------------------------------------------------------------------------
14 int main( char[][] args )
15 {
16     string text;
17 
18     // Parse and process command line arguments
19     plparseopts( args, PL_PARSE_FULL );
20 
21     // Initialize plplot
22     plinit();
23 
24     pladv( 0 );
25     plvsta();
26     plwind( 1980.0, 1990.0, 0.0, 35.0 );
27     plbox( "bc", 1.0, 0, "bcnv", 10.0, 0 );
cmap1_init()28     plcol0( 2 );
29     pllab( "Year", "Widget Sales (millions)", "#frPLplot Example 12" );
30 
31     PLFLT[] pos   = [ 0.0, 0.25, 0.5, 0.75, 1.0 ];
32     PLFLT[] red   = [ 0.0, 0.25, 0.5, 1.0, 1.0 ];
33     PLFLT[] green = [ 1.0, 0.5, 0.5, 0.5, 1.0 ];
34     PLFLT[] blue  = [ 1.0, 1.0, 0.5, 0.25, 0.0 ];
35     plscmap1l( 1, pos, red, green, blue );
36 
37     PLFLT[] y0 = [ 5.0, 15.0, 12.0, 24.0, 28.0, 30.0, 20.0, 8.0, 12.0, 3.0 ];
38     for ( size_t i = 0; i < 10; i++ )
39     {
40         plcol1( i / 9.0 );
41         plpsty( 0 );
42         plfbox( ( 1980. + i ), y0[i] );
43         text = format( "%.0f", y0[i] );
44         plptex( ( 1980. + i + .5 ), ( y0[i] + 1. ), 1.0, 0.0, .5, text );
45         text = format( "%d", 1980 + i );
46         plmtex( "b", 1.0, ( ( i + 1 ) * .1 - .05 ), 0.5, text );
47     }
48 
main(char[][]args)49     // Don't forget to call plend() to finish off!
50     plend();
51     return 0;
52 }
53 
54 
55 void plfbox( PLFLT x0, PLFLT y0 )
56 {
57     PLFLT[4] x = [x0, x0, x0 + 1.0, x0 + 1.0];;
58     PLFLT[4] y = [0.0, y0, y0, 0.0];
59 
60     plfill( x, y );
61     plcol0( 1 );
62     pllsty( 1 );
63     plline( x, y );
64 }
65