barchart.py (2118:1fe7d0ddf765) barchart.py (2119:f0de10227ae5)
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

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

26#
27# Authors: Nathan Binkert
28# Lisa Hsu
29
30import matplotlib, pylab
31from matplotlib.font_manager import FontProperties
32from matplotlib.numerix import array, arange, reshape, shape, transpose, zeros
33from matplotlib.numerix import Float
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

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

26#
27# Authors: Nathan Binkert
28# Lisa Hsu
29
30import matplotlib, pylab
31from matplotlib.font_manager import FontProperties
32from matplotlib.numerix import array, arange, reshape, shape, transpose, zeros
33from matplotlib.numerix import Float
34from matplotlib.ticker import NullLocator
34
35matplotlib.interactive(False)
36
37from chart import ChartOptions
38
39class BarChart(ChartOptions):
40 def __init__(self, default=None, **kwargs):
41 super(BarChart, self).__init__(default, **kwargs)

--- 73 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
35
36matplotlib.interactive(False)
37
38from chart import ChartOptions
39
40class BarChart(ChartOptions):
41 def __init__(self, default=None, **kwargs):
42 super(BarChart, self).__init__(default, **kwargs)

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

116 #
117 # This code deals with one of the dimensions in the matrix being
118 # one wide.
119 #
120 def graph(self):
121 if self.chartdata is None:
122 raise AttributeError, "Data not set for bar chart!"
123
123 need_subticks = True
124
125 dim = len(shape(self.inputdata))
126 cshape = shape(self.chartdata)
124 dim = len(shape(self.inputdata))
125 cshape = shape(self.chartdata)
127 print cshape
128 if dim == 1:
129 colors = self.gen_colors(cshape[2])
130 colors = [ [ colors ] * cshape[1] ] * cshape[0]
126 if dim == 1:
127 colors = self.gen_colors(cshape[2])
128 colors = [ [ colors ] * cshape[1] ] * cshape[0]
131 need_subticks = False
132
133 if dim == 2:
134 colors = self.gen_colors(cshape[0])
135 colors = [ [ [ c ] * cshape[2] ] * cshape[1] for c in colors ]
136
137 if dim == 3:
138 colors = self.gen_colors(cshape[1])
139 colors = [ [ [ c ] * cshape[2] for c in colors ] ] * cshape[0]
140
141 colors = array(colors)
142
143 self.figure = pylab.figure(figsize=self.chart_size)
144
145 outer_axes = None
146 inner_axes = None
129
130 if dim == 2:
131 colors = self.gen_colors(cshape[0])
132 colors = [ [ [ c ] * cshape[2] ] * cshape[1] for c in colors ]
133
134 if dim == 3:
135 colors = self.gen_colors(cshape[1])
136 colors = [ [ [ c ] * cshape[2] for c in colors ] ] * cshape[0]
137
138 colors = array(colors)
139
140 self.figure = pylab.figure(figsize=self.chart_size)
141
142 outer_axes = None
143 inner_axes = None
147 if need_subticks:
148 self.metaaxes = self.figure.add_axes(self.figure_size)
144 if self.xsubticks is not None:
145 color = self.figure.get_facecolor()
146 self.metaaxes = self.figure.add_axes(self.figure_size, axisbg=color, frameon=False)
147 for tick in self.metaaxes.xaxis.majorTicks:
148 tick.tick1On = False
149 tick.tick2On = False
149 self.metaaxes.set_yticklabels([])
150 self.metaaxes.set_yticks([])
151 size = [0] * 4
152 size[0] = self.figure_size[0]
150 self.metaaxes.set_yticklabels([])
151 self.metaaxes.set_yticks([])
152 size = [0] * 4
153 size[0] = self.figure_size[0]
153 size[1] = self.figure_size[1] + .075
154 size[1] = self.figure_size[1] + .05
154 size[2] = self.figure_size[2]
155 size[2] = self.figure_size[2]
155 size[3] = self.figure_size[3] - .075
156 size[3] = self.figure_size[3] - .05
156 self.axes = self.figure.add_axes(size)
157 outer_axes = self.metaaxes
158 inner_axes = self.axes
159 else:
160 self.axes = self.figure.add_axes(self.figure_size)
161 outer_axes = self.axes
162 inner_axes = self.axes
163

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

197 inner_axes.set_yticks(ticks)
198 inner_axes.set_yticklabels(self.yticks)
199 elif self.ylim is not None:
200 self.inner_axes.set_ylim(self.ylim)
201
202 if self.xticks is not None:
203 outer_axes.set_xticks(arange(cshape[2]) + .5)
204 outer_axes.set_xticklabels(self.xticks)
157 self.axes = self.figure.add_axes(size)
158 outer_axes = self.metaaxes
159 inner_axes = self.axes
160 else:
161 self.axes = self.figure.add_axes(self.figure_size)
162 outer_axes = self.axes
163 inner_axes = self.axes
164

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

198 inner_axes.set_yticks(ticks)
199 inner_axes.set_yticklabels(self.yticks)
200 elif self.ylim is not None:
201 self.inner_axes.set_ylim(self.ylim)
202
203 if self.xticks is not None:
204 outer_axes.set_xticks(arange(cshape[2]) + .5)
205 outer_axes.set_xticklabels(self.xticks)
206
205 if self.xsubticks is not None:
206 inner_axes.set_xticks(arange((cshape[0] + 1)*cshape[2])*width + 2*center)
207 self.xsubticks.append('')
208 inner_axes.set_xticklabels(self.xsubticks * cshape[2], fontsize=8)
207 if self.xsubticks is not None:
208 inner_axes.set_xticks(arange((cshape[0] + 1)*cshape[2])*width + 2*center)
209 self.xsubticks.append('')
210 inner_axes.set_xticklabels(self.xsubticks * cshape[2], fontsize=8)
211
209 if self.legend is not None:
210 if dim == 1:
211 lbars = bars[0][0]
212 if dim == 2:
213 lbars = [ bars[i][0][0] for i in xrange(len(bars))]
214 if dim == 3:
215 number = len(bars[0])
216 lbars = [ bars[0][number - j - 1][0] for j in xrange(number)]

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

274 chart1.data = data
275
276 chart1.xlabel = 'Benchmark'
277 chart1.ylabel = 'Bandwidth (GBps)'
278 chart1.legend = [ 'x%d' % x for x in xrange(myshape[-1]) ]
279 chart1.xticks = [ 'xtick%d' % x for x in xrange(myshape[0]) ]
280 chart1.title = 'this is the title'
281 chart1.figure_size = [0.1, 0.2, 0.7, 0.85 ]
212 if self.legend is not None:
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)]

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

277 chart1.data = data
278
279 chart1.xlabel = 'Benchmark'
280 chart1.ylabel = 'Bandwidth (GBps)'
281 chart1.legend = [ 'x%d' % x for x in xrange(myshape[-1]) ]
282 chart1.xticks = [ 'xtick%d' % x for x in xrange(myshape[0]) ]
283 chart1.title = 'this is the title'
284 chart1.figure_size = [0.1, 0.2, 0.7, 0.85 ]
282 if len(myshape) > 1:
285 if len(myshape) > 2:
283 chart1.xsubticks = [ '%d' % x for x in xrange(myshape[1]) ]
284 chart1.graph()
285 chart1.savefig('/tmp/test1.png')
286 chart1.savefig('/tmp/test1.ps')
287 chart1.savefig('/tmp/test1.eps')
288 chart1.savecsv('/tmp/test1.csv')
289
290 if False:
291 chart2 = BarChart()
292 chart2.data = data
293 chart2.colormap = 'gray'
294 chart2.graph()
295 chart2.savefig('/tmp/test2.png')
296 chart2.savefig('/tmp/test2.ps')
297
298 pylab.myshow()
286 chart1.xsubticks = [ '%d' % x for x in xrange(myshape[1]) ]
287 chart1.graph()
288 chart1.savefig('/tmp/test1.png')
289 chart1.savefig('/tmp/test1.ps')
290 chart1.savefig('/tmp/test1.eps')
291 chart1.savecsv('/tmp/test1.csv')
292
293 if False:
294 chart2 = BarChart()
295 chart2.data = data
296 chart2.colormap = 'gray'
297 chart2.graph()
298 chart2.savefig('/tmp/test2.png')
299 chart2.savefig('/tmp/test2.ps')
300
301 pylab.myshow()