code: def _prepare_data(self):
          
          xmin, xmax = self.limits['xmin'], self.limits['xmax']
  
          self.prepared_plot_series_list = []
          for series in self.plot_series_list:
              prepared_series = series.copy()
              data = prepared_series['data']
  
              x, _, _, _ = zip(*data)
              # only limit data when the data is sorted
              if sorted(x) == list(x):
                  x = np.array(x)
                  if xmin is not None:
                      min_idx = x.searchsorted(xmin)
                      if min_idx > 0:
                          min_idx -= 1
                  else:
                      min_idx = None
                  if xmax is not None:
                      max_idx = x.searchsorted(xmax) + 1
                  else:
                      max_idx = None
  
                  prepared_series['data'] = data[min_idx:max_idx]
              self.prepared_plot_series_list.append(prepared_series)
  
          self.prepared_shaded_regions_list = []
          for series in self.shaded_regions_list:
              prepared_series = series.copy()
              data = prepared_series['data']
  
              x, _, _ = zip(*data)
              # only limit data when the data is sorted
              if sorted(x) == list(x):
                  x = np.array(x)
                  if xmin is not None:
                      min_idx = x.searchsorted(xmin)
                      if min_idx > 0:
                          min_idx -= 1
                  else:
                      min_idx = None
                  if xmax is not None:
                      max_idx = x.searchsorted(xmax) + 1
                  else:
                      max_idx = None
  
                  prepared_series['data'] = data[min_idx:max_idx]
              self.prepared_shaded_regions_list.append(prepared_series)
docs: Prepare data before rendering
  
          When plotting very large datasets, we don't want to include data points
          which are outside the x-axis limits. LaTeX is very slow and consumes a
          lot of memory otherwise. Limiting the data points is only (easily)
          possible when the data are sorted.