Deleted Added
sdiff udiff text old ( 2179:7e15ffdd03d8 ) new ( 2180:44599b79ef80 )
full compact
1# Copyright (c) 2005-2006 The Regents of The University of Michigan
2# All rights reserved.
3#
4# Redistribution and use in source and binary forms, with or without
5# modification, are permitted provided that the following conditions are
6# met: redistributions of source code must retain the above copyright
7# notice, this list of conditions and the following disclaimer;
8# redistributions in binary form must reproduce the above copyright

--- 28 unchanged lines hidden (view full) ---

37
38from chart import ChartOptions
39
40class BarChart(ChartOptions):
41 def __init__(self, default=None, **kwargs):
42 super(BarChart, self).__init__(default, **kwargs)
43 self.inputdata = None
44 self.chartdata = None
45
46 def gen_colors(self, count):
47 cmap = matplotlib.cm.get_cmap(self.colormap)
48 if count == 1:
49 return cmap([ 0.5 ])
50
51 if count < 5:
52 return cmap(arange(5) / float(4))[:count]

--- 34 unchanged lines hidden (view full) ---

87 if dim == 3:
88 self.chartdata = transpose(data, axes=(1,2,0))
89
90 def get_data(self):
91 return self.inputdata
92
93 data = property(get_data, set_data)
94
95 # Graph the chart data.
96 # Input is a 3d matrix that describes a plot that has multiple
97 # groups, multiple bars in each group, and multiple values stacked
98 # in each bar. The underlying bar() function expects a sequence of
99 # bars in the same stack location and same group location, so the
100 # organization of the matrix is that the inner most sequence
101 # represents one of these bar groups, then those are grouped
102 # together to make one full stack of bars in each group, and then

--- 18 unchanged lines hidden (view full) ---

121 # one wide.
122 #
123 def graph(self):
124 if self.chartdata is None:
125 raise AttributeError, "Data not set for bar chart!"
126
127 dim = len(shape(self.inputdata))
128 cshape = shape(self.chartdata)
129 if dim == 1:
130 colors = self.gen_colors(cshape[2])
131 colors = [ [ colors ] * cshape[1] ] * cshape[0]
132
133 if dim == 2:
134 colors = self.gen_colors(cshape[0])
135 colors = [ [ [ c ] * cshape[2] ] * cshape[1] for c in colors ]
136

--- 35 unchanged lines hidden (view full) ---

172
173 bars = []
174 for i,stackdata in enumerate(self.chartdata):
175 bottom = array([0.0] * len(stackdata[0]), Float)
176 stack = []
177 for j,bardata in enumerate(stackdata):
178 bardata = array(bardata)
179 ind = arange(len(bardata)) + i * width + center
180 bar = self.axes.bar(ind, bardata, width, bottom=bottom,
181 color=colors[i][j])
182 if self.xsubticks is not None:
183 self.metaaxes.bar(ind, [0] * len(bardata), width)
184 stack.append(bar)
185 bottom += bardata
186 bars.append(stack)
187
188 if self.xlabel is not None:
189 outer_axes.set_xlabel(self.xlabel)

--- 23 unchanged lines hidden (view full) ---

213 if dim == 1:
214 lbars = bars[0][0]
215 if dim == 2:
216 lbars = [ bars[i][0][0] for i in xrange(len(bars))]
217 if dim == 3:
218 number = len(bars[0])
219 lbars = [ bars[0][number - j - 1][0] for j in xrange(number)]
220
221 self.figure.legend(lbars, self.legend, self.legend_loc,
222 prop=FontProperties(size=self.legend_size))
223
224 if self.title is not None:
225 self.axes.set_title(self.title)
226
227 def savefig(self, name):
228 self.figure.savefig(name)
229
230 def savecsv(self, name):

--- 70 unchanged lines hidden ---