1#  Copyright (C) 2001-2016 Alan W. Irwin
2
3#  Bar chart demo.
4#
5#  This file is part of PLplot.
6#
7#  PLplot is free software; you can redistribute it and/or modify
8#  it under the terms of the GNU Library General Public License as published
9#  by the Free Software Foundation; either version 2 of the License, or
10#  (at your option) any later version.
11#
12#  PLplot is distributed in the hope that it will be useful,
13#  but WITHOUT ANY WARRANTY; without even the implied warranty of
14#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15#  GNU Library General Public License for more details.
16#
17#  You should have received a copy of the GNU Library General Public License
18#  along with PLplot; if not, write to the Free Software
19#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20#
21
22from numpy import *
23
24# main
25#
26# Does a simple bar chart, using color fill.  If color fill is
27# unavailable, pattern fill is used instead (automatic).
28
29def main(w):
30
31    pos = array ([0.0, 0.25, 0.5, 0.75, 1.0])
32    red = array ([0.0, 0.25, 0.5, 1.0, 1.0])
33    green = array ([1.0, 0.5, 0.5, 0.5, 1.0])
34    blue = array ([1.0, 1.0, 0.5, 0.25, 0.0])
35
36    w.pladv(0)
37    w.plvsta()
38    w.plwind(1980.0, 1990.0, 0.0, 35.0)
39    w.plbox("bc", 1.0, 0, "bcnv", 10.0, 0)
40    w.plcol0(2)
41    w.pllab("Year", "Widget Sales (millions)", "#frPLplot Example 12")
42
43    y0 = [5, 15, 12, 24, 28, 30, 20, 8, 12, 3]
44
45    w.plscmap1l(1, pos, red, green, blue)
46
47    for i in range(10):
48        # w.plcol0(i + 1)
49        w.plcol1(i / 9.0)
50        w.plpsty(0)
51        fbox(w, (1980. + i), y0[i] )
52        string = str(y0[i])
53        w.plptex((1980. + i + .5), (y0[i] + 1.), 1.0, 0.0, .5, string)
54        string = str(1980 + i)
55        w.plmtex("b", 1.0, ((i + 1) * .1 - .05), 0.5, string)
56
57    # Restore defaults
58    # cmap1 default color palette.
59    w.plspal1("cmap1_default.pal",1)
60
61    # Must be done independently because otherwise this changes output files
62    # and destroys agreement with C examples.
63    #w.plcol0(1)
64
65def fbox(w,  x0, y0 ):
66
67    x = [x0, x0, x0 + 1., x0 + 1.]
68    y = [0., y0, y0, 0.]
69    w.plfill(x, y)
70    w.plcol0(1)
71    w.pllsty(1)
72    w.plline(x, y)
73