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 |
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 |
124 dim = len(shape(self.inputdata)) 125 cshape = shape(self.chartdata) |
126 if dim == 1: 127 colors = self.gen_colors(cshape[2]) 128 colors = [ [ colors ] * cshape[1] ] * cshape[0] |
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 |
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 |
150 self.metaaxes.set_yticklabels([]) 151 self.metaaxes.set_yticks([]) 152 size = [0] * 4 153 size[0] = self.figure_size[0] |
154 size[1] = self.figure_size[1] + .05 |
155 size[2] = self.figure_size[2] |
156 size[3] = self.figure_size[3] - .05 |
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 |
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 |
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 ] |
285 if len(myshape) > 2: |
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() |