blob: 6d2358786b7fbab0e87552d8e6e1cd1d7bdc8ad1 [file] [log] [blame]
Lee Mracek3e16a862019-01-24 11:15:36 -05001#!/usr/bin/python
Dave Smithacbca192016-03-06 15:27:23 -08002
Lee Mracek3e16a862019-01-24 11:15:36 -05003from frc971.analysis.logreader import CollectingLogReader
Dave Smithacbca192016-03-06 15:27:23 -08004import matplotlib
5from matplotlib import pylab
6from matplotlib.font_manager import FontProperties
7
8class 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 Mracek437d1dd2019-01-22 10:38:01 -050038 label = key[1] + '.' + '.'.join(str(x) for x in key[2])
Dave Smithacbca192016-03-06 15:27:23 -080039 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 Schuh8c14cf42017-04-09 18:14:34 -070047 pylab.legend(bbox_to_anchor=(0.2, 1.10), prop=fontP)
Dave Smithacbca192016-03-06 15:27:23 -080048
49 pylab.show()
50