Make legend smaller on analysis plots.

I decreased the legend because it kept getting in the way of the
actual data.

Two things change with this commit:
- Reduced font size and moved the legend closer to the top-left corner.
- Optionally omit binary from legend using command line option.

Change-Id: Id9e1197c6184a16e944a433553b3b284467ae369
diff --git a/frc971/analysis/analysis.py b/frc971/analysis/analysis.py
index 8152607..66a4dd4 100755
--- a/frc971/analysis/analysis.py
+++ b/frc971/analysis/analysis.py
@@ -1,6 +1,7 @@
 #!/usr/bin/python3
 import matplotlib
 from matplotlib import pylab
+from matplotlib.font_manager import FontProperties
 
 class Dataset(object):
   def __init__(self):
@@ -61,7 +62,7 @@
 
           value.Add(pline.time, data)
 
-  def Plot(self):
+  def Plot(self, no_binary_in_legend):
     """
     Plots all the data after it's parsed.
 
@@ -70,12 +71,23 @@
     """
     for key in self.signal:
       value = self.signal[key]
-      pylab.plot(value.time, value.data, label=key[0] + ' ' + key[1] + '.' + \
-          '.'.join(key[2]))
-    pylab.legend()
+
+      # Create a legend label using the binary name (optional), the structure
+      # name and the data search path.
+      label = key[1] + '.' + '.'.join(key[2])
+      if not no_binary_in_legend:
+        label = key[0] + ' ' + label
+
+      pylab.plot(value.time, value.data, label=label)
+
+    # Set legend font size to small and move it to the top center.
+    fontP = FontProperties()
+    fontP.set_size('small')
+    pylab.legend(bbox_to_anchor=(0.5, 1.05), prop=fontP)
+
     pylab.show()
 
-  def PlotFile(self, f):
+  def PlotFile(self, f, no_binary_in_legend=False):
     """
     Parses and plots all the data.
 
@@ -86,7 +98,7 @@
       None
     """
     self.HandleFile(f)
-    self.Plot()
+    self.Plot(no_binary_in_legend)
 
   def HandleFile(self, f):
     """
diff --git a/frc971/analysis/plot_action.py b/frc971/analysis/plot_action.py
index 1adb4db..f719c97 100755
--- a/frc971/analysis/plot_action.py
+++ b/frc971/analysis/plot_action.py
@@ -49,6 +49,8 @@
       help='The file from which to read logs and plot.')
   arg_parser.add_argument('--plot-defs', action='store', type=str, \
       help='Read the items to plot from this file.')
+  arg_parser.add_argument('--no-binary', '-n', action='store_true', \
+      help='Don\'t print the binary name in the legend.')
 
   args = arg_parser.parse_args(sys.argv[1:])
 
@@ -72,7 +74,7 @@
     p.Add('fridge', 'output', 'left_elevator')
     p.Add('fridge', 'output', 'right_elevator')
 
-  p.PlotFile(args.log_file)
+  p.PlotFile(args.log_file, args.no_binary)
 
 if __name__ == '__main__':
   main()