original_docstring: Draws a legend onto the plot with the specified histograms.
  
          It is recommended that you construct the Plot with plot_header = True
          in order to make space for the legend.
  
          Args:
              drawables: The elements to include in the legend (via AddEntry)
          
docstring: Draws a legend onto the plot with the specified histograms.
  It is recommended that you construct the Plot with plot_header = True
  in order to make space for the legend.
docstring_tokens: Draws a legend onto the plot with the specified histograms . It is recommended that you construct the Plot with plot_header = True in order to make space for the legend .
code: def draw_legend(self, *drawables):
          """Draws a legend onto the plot with the specified histograms.
  
          It is recommended that you construct the Plot with plot_header = True
          in order to make space for the legend.
  
          Args:
              drawables: The elements to include in the legend (via AddEntry)
          """
          # Check if we already have a legend
          if hasattr(self, '_legend'):
              raise RuntimeError('legend already exists on this plot')
  
          # Switch to the context of the main plot
          self._plot.cd()
  
          # Create the legend
          if self._atlas_label_drawn:
              self._legend = TLegend(self.PLOT_LEGEND_LEFT,
                                     (self.PLOT_LEGEND_BOTTOM_WITH_RATIO
                                      if self._ratio_plot
                                      else self.PLOT_LEGEND_BOTTOM),
                                     self.PLOT_LEGEND_RIGHT,
                                     (self.PLOT_LEGEND_TOP_WITH_RATIO
                                      if self._ratio_plot
                                      else self.PLOT_LEGEND_TOP))
          else:
              # WJF may need customisation with ratio
              self._legend = TLegend(0.15, 0.7, 0.5, 0.88)
  
          SetOwnership(self._legend, False)
  
          # Style it
          self._legend.SetTextSize((
              self.PLOT_LEGEND_TEXT_SIZE_WITH_RATIO
              if self._ratio_plot
              else self.PLOT_LEGEND_TEXT_SIZE
          ))
          self._legend.SetBorderSize(0)
          self._legend.SetFillStyle(0) # transparent
          self._legend.SetNColumns(self.PLOT_LEGEND_N_COLUMNS)
  
          # Create a chained list of all drawables.  We decompose THStack
          # objects in reverse order, i.e. top-to-bottom.
          drawables = \
              list(chain(*(drawable_iterable(h, True, True)
                           for h
                           in drawables)))
  
          # Add anything to this list that we created internally
          drawables.extend(self._legend_extras)
  
          # Because ROOT draws legend entries from left-to-right across rows and
          # not top-to-bottom along columns, we need to do a bit of a pivot on
          # the list so that the histograms appear in the vertical order of the
          # stack
          n_entries = len(drawables)
          n_col = self.PLOT_LEGEND_N_COLUMNS
          n_row = int(ceil(float(n_entries) / n_col))
          legend_order = []
          for r in xrange(0, n_row):
              for c in xrange(0, n_col):
                  if (r * n_col + c) == n_entries:
                      # Don't need an outer break, this would only happen on the
                      # last row if n_row * n_col != n_entries
                      break
                  legend_order.append(drawables[r + c * n_row])
  
          # Add the drawables
          for drawable in legend_order:
              SetOwnership(drawable, False)
              title = drawable.GetTitle()
              # HACK: Convention: legend for drawables with a non-default
              # marker style (data) to be drawn as point, and with
              # empty fill (signal) to be drawn as line
              #print 'Adding plottable {0} to legend. Has MarkerStyle {1} and fill colour {2}'.format(drawable.GetName(), drawable.GetMarkerStyle(), drawable.GetFillColor())
              #self._legend.AddEntry(drawable, title, 'f')
              this_marker = drawable.GetMarkerStyle()
              if this_marker == 20:
                  self._legend.AddEntry(drawable, title, 'p')
                  #self._legend.AddEntry(drawable, title, 'l')
              elif drawable.GetTitle() == 'Total Background' or drawable.GetTitle() == 'Total background':
                  self._legend.AddEntry(drawable, title, 'lf')
              elif drawable.GetFillColor() == 0:
                  self._legend.AddEntry(drawable, title, 'l')
              elif this_marker == 21 or this_marker == 3 or this_marker == 22:
                  self._legend.AddEntry(drawable, title, 'lp')
              else:
                  self._legend.AddEntry(drawable, title, 'f')
  
          # Draw the legend
          self._legend.Draw()
code_tokens: def draw_legend ( self , * drawables ) : if hasattr ( self , '_legend' ) : raise RuntimeError ( 'legend already exists on this plot' ) self . _plot . cd ( ) if self . _atlas_label_drawn : self . _legend = TLegend ( self . PLOT_LEGEND_LEFT , ( self . PLOT_LEGEND_BOTTOM_WITH_RATIO if self . _ratio_plot else self . PLOT_LEGEND_BOTTOM ) , self . PLOT_LEGEND_RIGHT , ( self . PLOT_LEGEND_TOP_WITH_RATIO if self . _ratio_plot else self . PLOT_LEGEND_TOP ) ) else : self . _legend = TLegend ( 0.15 , 0.7 , 0.5 , 0.88 ) SetOwnership ( self . _legend , False ) self . _legend . SetTextSize ( ( self . PLOT_LEGEND_TEXT_SIZE_WITH_RATIO if self . _ratio_plot else self . PLOT_LEGEND_TEXT_SIZE ) ) self . _legend . SetBorderSize ( 0 ) self . _legend . SetFillStyle ( 0 ) self . _legend . SetNColumns ( self . PLOT_LEGEND_N_COLUMNS ) drawables = list ( chain ( * ( drawable_iterable ( h , True , True ) for h in drawables ) ) ) drawables . extend ( self . _legend_extras ) n_entries = len ( drawables ) n_col = self . PLOT_LEGEND_N_COLUMNS n_row = int ( ceil ( float ( n_entries ) / n_col ) ) legend_order = [ ] for r in xrange ( 0 , n_row ) : for c in xrange ( 0 , n_col ) : if ( r * n_col + c ) == n_entries : break legend_order . append ( drawables [ r + c * n_row ] ) for drawable in legend_order : SetOwnership ( drawable , False ) title = drawable . GetTitle ( ) this_marker = drawable . GetMarkerStyle ( ) if this_marker == 20 : self . _legend . AddEntry ( drawable , title , 'p' ) elif drawable . GetTitle ( ) == 'Total Background' or drawable . GetTitle ( ) == 'Total background' : self . _legend . AddEntry ( drawable , title , 'lf' ) elif drawable . GetFillColor ( ) == 0 : self . _legend . AddEntry ( drawable , title , 'l' ) elif this_marker == 21 or this_marker == 3 or this_marker == 22 : self . _legend . AddEntry ( drawable , title , 'lp' ) else : self . _legend . AddEntry ( drawable , title , 'f' ) self . _legend . Draw ( )
short_docstring: Draws a legend onto the plot with the specified histograms.
short_docstring_tokens: Draws a legend onto the plot with the specified histograms .
comment: """Draws a legend onto the plot with the specified histograms.
  
          It is recommended that you construct the Plot with plot_header = True
          in order to make space for the legend.
  
          Args:
              drawables: The elements to include in the legend (via AddEntry)
          """$SEP$# Check if we already have a legend$SEP$# Switch to the context of the main plot$SEP$# Create the legend$SEP$# WJF may need customisation with ratio$SEP$# Style it$SEP$# transparent$SEP$# Create a chained list of all drawables.  We decompose THStack$SEP$# objects in reverse order, i.e. top-to-bottom.$SEP$# Add anything to this list that we created internally$SEP$# Because ROOT draws legend entries from left-to-right across rows and$SEP$# not top-to-bottom along columns, we need to do a bit of a pivot on$SEP$# the list so that the histograms appear in the vertical order of the$SEP$# stack$SEP$# Don't need an outer break, this would only happen on the$SEP$# last row if n_row * n_col != n_entries$SEP$# Add the drawables$SEP$# HACK: Convention: legend for drawables with a non-default$SEP$# marker style (data) to be drawn as point, and with$SEP$# empty fill (signal) to be drawn as line$SEP$#print 'Adding plottable {0} to legend. Has MarkerStyle {1} and fill colour {2}'.format(drawable.GetName(), drawable.GetMarkerStyle(), drawable.GetFillColor())$SEP$#self._legend.AddEntry(drawable, title, 'f')$SEP$#self._legend.AddEntry(drawable, title, 'l')$SEP$# Draw the legend