code: def patch_locator(locator, xdates):
      def _patched_datalim_to_dt(self):
          dmin, dmax = self.axis.get_data_interval()
  
          # proxy access to xdates
          dmin, dmax = (
              xdates[int(dmin)],
              xdates[min(int(dmax), len(xdates) - 1)],
          )
  
          a, b = num2date(dmin, self.tz), num2date(dmax, self.tz)
          return a, b
  
      def _patched_viewlim_to_dt(self):
          vmin, vmax = self.axis.get_view_interval()
  
          # proxy access to xdates
          vmin, vmax = (
              xdates[int(vmin)],
              xdates[min(int(vmax), len(xdates) - 1)],
          )
          a, b = num2date(vmin, self.tz), num2date(vmax, self.tz)
          return a, b
  
      # patch the instance with a bound method
      bound_datalim = _patched_datalim_to_dt.__get__(
          locator, locator.__class__
      )
      locator.datalim_to_dt = bound_datalim
  
      # patch the instance with a bound method
      bound_viewlim = _patched_viewlim_to_dt.__get__(
          locator, locator.__class__
      )
      locator.viewlim_to_dt = bound_viewlim
  
file_path: backtrader/backtrader/plot/formatters.py
imports: from __future__ import absolute_import, division, print_function, unicode_literals
  import matplotlib.dates
  import matplotlib.ticker
  from ..utils import num2date
label_desc: Use image node_id 1 for calling a global function with example usage: patch_locator(locator, xdates) and returns: a,  b, a,  b