Dave Smith | acbca19 | 2016-03-06 15:27:23 -0800 | [diff] [blame] | 1 | #!/usr/bin/python3 |
| 2 | |
| 3 | from logreader import CollectingLogReader |
| 4 | import matplotlib |
| 5 | from matplotlib import pylab |
| 6 | from matplotlib.font_manager import FontProperties |
| 7 | |
| 8 | class Plotter(CollectingLogReader): |
| 9 | """ |
| 10 | A CollectingLogReader that plots collected data. |
| 11 | """ |
| 12 | |
| 13 | def PlotFile(self, f, no_binary_in_legend=False): |
| 14 | """ |
| 15 | Parses and plots all the data. |
| 16 | |
| 17 | Args: |
| 18 | f: str, The filename of the log whose data to parse and plot. |
| 19 | |
| 20 | Returns: |
| 21 | None |
| 22 | """ |
| 23 | self.HandleFile(f) |
| 24 | self.Plot(no_binary_in_legend) |
| 25 | |
| 26 | def Plot(self, no_binary_in_legend): |
| 27 | """ |
| 28 | Plots all the data after it's parsed. |
| 29 | |
| 30 | This should only be called after `HandleFile` has been called so that there |
| 31 | is actual data to plot. |
| 32 | """ |
| 33 | for key in self.signal: |
| 34 | value = self.signal[key] |
| 35 | |
| 36 | # Create a legend label using the binary name (optional), the structure |
| 37 | # name and the data search path. |
Lee Mracek | 437d1dd | 2019-01-22 10:38:01 -0500 | [diff] [blame^] | 38 | label = key[1] + '.' + '.'.join(str(x) for x in key[2]) |
Dave Smith | acbca19 | 2016-03-06 15:27:23 -0800 | [diff] [blame] | 39 | if not no_binary_in_legend: |
| 40 | label = key[0] + ' ' + label |
| 41 | |
| 42 | pylab.plot(value.time, value.data, label=label) |
| 43 | |
| 44 | # Set legend font size to small and move it to the top center. |
| 45 | fontP = FontProperties() |
| 46 | fontP.set_size('small') |
Austin Schuh | 8c14cf4 | 2017-04-09 18:14:34 -0700 | [diff] [blame] | 47 | pylab.legend(bbox_to_anchor=(0.2, 1.10), prop=fontP) |
Dave Smith | acbca19 | 2016-03-06 15:27:23 -0800 | [diff] [blame] | 48 | |
| 49 | pylab.show() |
| 50 | |