code: def set_legend_location(self, loc, onaxis):
          "set legend location"
          self.legend_onaxis = 'on plot'
          if not onaxis:
              self.legend_onaxis = 'off plot'
              if loc == 'best':
                  loc = 'upper right'
          if loc in self.legend_abbrevs:
              loc = self.legend_abbrevs[loc]
          if loc in self.legend_locs:
              self.legend_loc = lof set_legend_location(self, loc, onaxis):
          "set legend location"
          self.legend_onaxis = 'on plot'
          if not onaxis:
              self.legend_onaxis = 'off plot'
              if loc == 'best':
                  loc = 'upper right'
          if loc in self.legend_abbrevs:
              loc = self.legend_abbrevs[loc]
          if loc in self.legend_locs:
              self.legend_loc = loc
docs: set legend location