summaryrefslogtreecommitdiff
path: root/util/stats/barchart.py
diff options
context:
space:
mode:
authorNathan Binkert <binkertn@umich.edu>2005-11-22 21:50:34 -0500
committerNathan Binkert <binkertn@umich.edu>2005-11-22 21:50:34 -0500
commitc0a4836077425e03cc39dfba88bec7da21af950b (patch)
tree1e609627fbc2cc30df64a0698fc150a7ad3e3fd3 /util/stats/barchart.py
parent7819ca6b97f96f1f5e5aeb66b33aa9a764e649ae (diff)
downloadgem5-c0a4836077425e03cc39dfba88bec7da21af950b.tar.xz
Major improvements in the graph output code. Mostly adding more
options, making existing options more visible and dealing with holes in data better. util/stats/barchart.py: - move the options for BarChart to a base class ChartOptions so they can be more easily set and copied. - add an option to set the chart size (so you can adjust the aspect ratio) - don't do the add_subplot thing, use add_axes directly so we can affect the size of the figure itself to make room for the legend - make the initial array bottom floating point so we don't lose precision - add an option to set the limits on the y axis - use a figure legend instead of an axes legend so we can put the legend outside of the actual chart. Also add an option to set the fontsize of the legend. - initial hack at outputting csv files util/stats/db.py: don't print out an error when the run is missing from the database just return None, the error will be print elsewhere. util/stats/output.py: - make StatOutput derive from ChartOptions so that it's easier to set default chart options. - make the various output functions (graph, display, etc.) take the name of the data as a parameter instead of making it a parameter to __init__. This allows me to create the StatOutput object with generic parameters while still being able to specialize the name after the fact - add support for graph_group and graph_bars to be applied to multiple configuration groups. This results in a cross product of the groups to be generated and used. - flush the html file output as we go so that we can load the file while graphs are still being generated. - make the proxy a parameter to the graph function so the proper system's data can be graphed - for any groups or bars that are completely missing, remove them from the graph. This way, if we decide not to do a set of runs, there won't be holes in the data. - output eps and ps by default in addition to the png. util/stats/profile.py: - clean up the data structures that are used to store the function profile information and try our best to avoid keeping extra data around that isn't used. - make get() return None if a job is missing so we know it was missing rather than the all zeroes thing. - make the function profile categorization stuff total up to 100% - Fixup the x-axis and y-axis labels. - fix the dot file output stuff. util/stats/stats.py: support the new options stuff for StatOutput --HG-- extra : convert_revision : fae35df8c57a36257ea93bc3e0a0e617edc46bb7
Diffstat (limited to 'util/stats/barchart.py')
-rw-r--r--util/stats/barchart.py65
1 files changed, 44 insertions, 21 deletions
diff --git a/util/stats/barchart.py b/util/stats/barchart.py
index a2cbea816..19cccb58a 100644
--- a/util/stats/barchart.py
+++ b/util/stats/barchart.py
@@ -28,28 +28,19 @@
# Lisa Hsu
import matplotlib, pylab
+from matplotlib.font_manager import FontProperties
from matplotlib.numerix import array, arange, reshape, shape, transpose, zeros
from matplotlib.numerix import Float
matplotlib.interactive(False)
-class BarChart(object):
- def __init__(self, **kwargs):
- self.init(**kwargs)
+from chart import ChartOptions
- def init(self, **kwargs):
- self.colormap = 'jet'
+class BarChart(ChartOptions):
+ def __init__(self, default=None, **kwargs):
+ super(BarChart, self).__init__(default, **kwargs)
self.inputdata = None
self.chartdata = None
- self.xlabel = None
- self.ylabel = None
- self.legend = None
- self.xticks = None
- self.yticks = None
- self.title = None
-
- for key,value in kwargs.iteritems():
- self.__setattr__(key, value)
def gen_colors(self, count):
cmap = matplotlib.cm.get_cmap(self.colormap)
@@ -129,8 +120,8 @@ class BarChart(object):
if self.chartdata is None:
raise AttributeError, "Data not set for bar chart!"
- self.figure = pylab.figure()
- self.axes = self.figure.add_subplot(111)
+ self.figure = pylab.figure(figsize=self.chart_size)
+ self.axes = self.figure.add_axes(self.figure_size)
dim = len(shape(self.inputdata))
cshape = shape(self.chartdata)
@@ -158,7 +149,7 @@ class BarChart(object):
bars = []
for i,stackdata in enumerate(self.chartdata):
- bottom = array([0] * len(stackdata[0]))
+ bottom = array([0.0] * len(stackdata[0]), Float)
stack = []
for j,bardata in enumerate(stackdata):
bardata = array(bardata)
@@ -181,6 +172,8 @@ class BarChart(object):
ticks = arange(nticks) / (nticks - 1) * (ymax - ymin) + ymin
self.axes.set_yticks(ticks)
self.axes.set_yticklabels(self.yticks)
+ elif self.ylim is not None:
+ self.axes.set_ylim(self.ylim)
if self.xticks is not None:
self.axes.set_xticks(arange(cshape[2]) + .5)
@@ -195,7 +188,8 @@ class BarChart(object):
number = len(bars[0])
lbars = [ bars[0][number - j - 1][0] for j in xrange(number)]
- self.axes.legend(lbars, self.legend, loc='best')
+ self.figure.legend(lbars, self.legend, self.legend_loc,
+ prop=FontProperties(size=self.legend_size))
if self.title is not None:
self.axes.set_title(self.title)
@@ -203,7 +197,32 @@ class BarChart(object):
def savefig(self, name):
self.figure.savefig(name)
+ def savecsv(self, name):
+ f = file(name, 'w')
+ data = array(self.inputdata)
+ dim = len(data.shape)
+
+ if dim == 1:
+ #if self.xlabel:
+ # f.write(', '.join(list(self.xlabel)) + '\n')
+ f.write(', '.join([ '%f' % val for val in data]) + '\n')
+ if dim == 2:
+ #if self.xlabel:
+ # f.write(', '.join([''] + list(self.xlabel)) + '\n')
+ for i,row in enumerate(data):
+ ylabel = []
+ #if self.ylabel:
+ # ylabel = [ self.ylabel[i] ]
+ f.write(', '.join(ylabel + [ '%f' % val for val in row]) + '\n')
+ if dim == 3:
+ f.write("don't do 3D csv files\n")
+ pass
+
+ f.close()
+
+
if __name__ == '__main__':
+ from random import randrange
import random, sys
dim = 3
@@ -234,13 +253,17 @@ if __name__ == '__main__':
chart1.xticks = [ 'xtick%d' % x for x in xrange(myshape[0]) ]
chart1.title = 'this is the title'
chart1.graph()
- #chart1.savefig('/tmp/test1.png')
+ chart1.savefig('/tmp/test1.png')
+ chart1.savefig('/tmp/test1.ps')
+ chart1.savefig('/tmp/test1.eps')
+ chart1.savecsv('/tmp/test1.csv')
if False:
chart2 = BarChart()
chart2.data = data
chart2.colormap = 'gray'
chart2.graph()
- #chart2.savefig('/tmp/test2.png')
+ chart2.savefig('/tmp/test2.png')
+ chart2.savefig('/tmp/test2.ps')
- pylab.show()
+ #pylab.show()