Deleted Added
sdiff udiff text old ( 2006:3ca085495c69 ) new ( 2115:beeeb8bb7550 )
full compact
1# Copyright (c) 2005 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
9# notice, this list of conditions and the following disclaimer in the

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

71 if dim == 1:
72 self.chartdata = array([[data]])
73
74 # If the input data is a 2d matrix, then it describes a bar
75 # chart with groups. The matrix being an array of groups of
76 # bars.
77 if dim == 2:
78 self.chartdata = transpose([data], axes=(2,0,1))
79
80 # If the input data is a 3d matrix, then it describes an array
81 # of groups of bars with each bar being an array of stacked
82 # values.
83 if dim == 3:
84 self.chartdata = transpose(data, axes=(1,2,0))
85
86 def get_data(self):
87 return self.inputdata
88
89 data = property(get_data, set_data)
90
91 # Graph the chart data.
92 # Input is a 3d matrix that describes a plot that has multiple

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

115 #
116 # This code deals with one of the dimensions in the matrix being
117 # one wide.
118 #
119 def graph(self):
120 if self.chartdata is None:
121 raise AttributeError, "Data not set for bar chart!"
122
123 self.figure = pylab.figure(figsize=self.chart_size)
124 self.axes = self.figure.add_axes(self.figure_size)
125
126 dim = len(shape(self.inputdata))
127 cshape = shape(self.chartdata)
128 if dim == 1:
129 colors = self.gen_colors(cshape[2])
130 colors = [ [ colors ] * cshape[1] ] * cshape[0]
131
132 if dim == 2:
133 colors = self.gen_colors(cshape[0])
134 colors = [ [ [ c ] * cshape[2] ] * cshape[1] for c in colors ]
135
136 if dim == 3:
137 colors = self.gen_colors(cshape[1])
138 colors = [ [ [ c ] * cshape[2] for c in colors ] ] * cshape[0]
139
140 colors = array(colors)
141
142 bars_in_group = len(self.chartdata)
143 if bars_in_group < 5:
144 width = 1.0 / ( bars_in_group + 1)
145 center = width / 2
146 else:
147 width = .8 / bars_in_group
148 center = .1
149
150 bars = []
151 for i,stackdata in enumerate(self.chartdata):
152 bottom = array([0.0] * len(stackdata[0]), Float)
153 stack = []
154 for j,bardata in enumerate(stackdata):
155 bardata = array(bardata)
156 ind = arange(len(bardata)) + i * width + center
157 bar = self.axes.bar(ind, bardata, width, bottom=bottom,
158 color=colors[i][j])
159 stack.append(bar)
160 bottom += bardata
161 bars.append(stack)
162
163 if self.xlabel is not None:
164 self.axes.set_xlabel(self.xlabel)
165
166 if self.ylabel is not None:
167 self.axes.set_ylabel(self.ylabel)
168
169 if self.yticks is not None:
170 ymin, ymax = self.axes.get_ylim()
171 nticks = float(len(self.yticks))
172 ticks = arange(nticks) / (nticks - 1) * (ymax - ymin) + ymin
173 self.axes.set_yticks(ticks)
174 self.axes.set_yticklabels(self.yticks)
175 elif self.ylim is not None:
176 self.axes.set_ylim(self.ylim)
177
178 if self.xticks is not None:
179 self.axes.set_xticks(arange(cshape[2]) + .5)
180 self.axes.set_xticklabels(self.xticks)
181
182 if self.legend is not None:
183 if dim == 1:
184 lbars = bars[0][0]
185 if dim == 2:
186 lbars = [ bars[i][0][0] for i in xrange(len(bars))]
187 if dim == 3:
188 number = len(bars[0])
189 lbars = [ bars[0][number - j - 1][0] for j in xrange(number)]

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

215 # ylabel = [ self.ylabel[i] ]
216 f.write(', '.join(ylabel + [ '%f' % val for val in row]) + '\n')
217 if dim == 3:
218 f.write("don't do 3D csv files\n")
219 pass
220
221 f.close()
222
223
224if __name__ == '__main__':
225 from random import randrange
226 import random, sys
227
228 dim = 3
229 number = 5
230
231 args = sys.argv[1:]

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

247 chart1 = BarChart()
248 chart1.data = data
249
250 chart1.xlabel = 'Benchmark'
251 chart1.ylabel = 'Bandwidth (GBps)'
252 chart1.legend = [ 'x%d' % x for x in xrange(myshape[-1]) ]
253 chart1.xticks = [ 'xtick%d' % x for x in xrange(myshape[0]) ]
254 chart1.title = 'this is the title'
255 chart1.graph()
256 chart1.savefig('/tmp/test1.png')
257 chart1.savefig('/tmp/test1.ps')
258 chart1.savefig('/tmp/test1.eps')
259 chart1.savecsv('/tmp/test1.csv')
260
261 if False:
262 chart2 = BarChart()
263 chart2.data = data
264 chart2.colormap = 'gray'
265 chart2.graph()
266 chart2.savefig('/tmp/test2.png')
267 chart2.savefig('/tmp/test2.ps')
268
269 #pylab.show()