nodes: 0, module; 1, function_definition; 2, function_name:_prepare_data; 3, parameters; 4, block; 5, identifier:self; 6, expression_statement; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, expression_statement; 11, for_statement; 12, comment:"""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.
  
          """; 13, assignment; 14, assignment; 15, identifier:series; 16, attribute; 17, block; 18, assignment; 19, identifier:series; 20, attribute; 21, block; 22, pattern_list; 23, expression_list; 24, attribute; 25, list; 26, identifier:self; 27, identifier:plot_series_list; 28, expression_statement; 29, expression_statement; 30, expression_statement; 31, comment:# only limit data when the data is sorted; 32, if_statement; 33, expression_statement; 34, attribute; 35, list; 36, identifier:self; 37, identifier:shaded_regions_list; 38, expression_statement; 39, expression_statement; 40, expression_statement; 41, comment:# only limit data when the data is sorted; 42, if_statement; 43, expression_statement; 44, identifier:xmin; 45, identifier:xmax; 46, subscript; 47, subscript; 48, identifier:self; 49, identifier:prepared_plot_series_list; 50, assignment; 51, assignment; 52, assignment; 53, comparison_operator:sorted(x) == list(x); 54, block; 55, call; 56, identifier:self; 57, identifier:prepared_shaded_regions_list; 58, assignment; 59, assignment; 60, assignment; 61, comparison_operator:sorted(x) == list(x); 62, block; 63, call; 64, attribute; 65, string; 66, attribute; 67, string; 68, identifier:prepared_series; 69, call; 70, identifier:data; 71, subscript; 72, pattern_list; 73, call; 74, call; 75, call; 76, expression_statement; 77, if_statement; 78, if_statement; 79, expression_statement; 80, attribute; 81, argument_list; 82, identifier:prepared_series; 83, call; 84, identifier:data; 85, subscript; 86, pattern_list; 87, call; 88, call; 89, call; 90, expression_statement; 91, if_statement; 92, if_statement; 93, expression_statement; 94, attribute; 95, argument_list; 96, identifier:self; 97, identifier:limits; 98, string_content:xmin; 99, identifier:self; 100, identifier:limits; 101, string_content:xmax; 102, attribute; 103, argument_list; 104, identifier:prepared_series; 105, string; 106, identifier:x; 107, identifier:_; 108, identifier:_; 109, identifier:_; 110, identifier:zip; 111, argument_list; 112, identifier:sorted; 113, argument_list; 114, identifier:list; 115, argument_list; 116, assignment; 117, comparison_operator:xmin is not None; 118, block; 119, else_clause; 120, comparison_operator:xmax is not None; 121, block; 122, else_clause; 123, assignment; 124, attribute; 125, identifier:append; 126, identifier:prepared_series; 127, attribute; 128, argument_list; 129, identifier:prepared_series; 130, string; 131, identifier:x; 132, identifier:_; 133, identifier:_; 134, identifier:zip; 135, argument_list; 136, identifier:sorted; 137, argument_list; 138, identifier:list; 139, argument_list; 140, assignment; 141, comparison_operator:xmin is not None; 142, block; 143, else_clause; 144, comparison_operator:xmax is not None; 145, block; 146, else_clause; 147, assignment; 148, attribute; 149, identifier:append; 150, identifier:prepared_series; 151, identifier:series; 152, identifier:copy; 153, string_content:data; 154, list_splat; 155, identifier:x; 156, identifier:x; 157, identifier:x; 158, call; 159, identifier:xmin; 160, None; 161, expression_statement; 162, if_statement; 163, block; 164, identifier:xmax; 165, None; 166, expression_statement; 167, block; 168, subscript; 169, subscript; 170, identifier:self; 171, identifier:prepared_plot_series_list; 172, identifier:series; 173, identifier:copy; 174, string_content:data; 175, list_splat; 176, identifier:x; 177, identifier:x; 178, identifier:x; 179, call; 180, identifier:xmin; 181, None; 182, expression_statement; 183, if_statement; 184, block; 185, identifier:xmax; 186, None; 187, expression_statement; 188, block; 189, subscript; 190, subscript; 191, identifier:self; 192, identifier:prepared_shaded_regions_list; 193, identifier:data; 194, attribute; 195, argument_list; 196, assignment; 197, comparison_operator:min_idx > 0; 198, block; 199, expression_statement; 200, assignment; 201, expression_statement; 202, identifier:prepared_series; 203, string; 204, identifier:data; 205, slice; 206, identifier:data; 207, attribute; 208, argument_list; 209, assignment; 210, comparison_operator:min_idx > 0; 211, block; 212, expression_statement; 213, assignment; 214, expression_statement; 215, identifier:prepared_series; 216, string; 217, identifier:data; 218, slice; 219, identifier:np; 220, identifier:array; 221, identifier:x; 222, identifier:min_idx; 223, call; 224, identifier:min_idx; 225, integer:0; 226, expression_statement; 227, assignment; 228, identifier:max_idx; 229, binary_operator:x.searchsorted(xmax) + 1; 230, assignment; 231, string_content:data; 232, identifier:min_idx; 233, identifier:max_idx; 234, identifier:np; 235, identifier:array; 236, identifier:x; 237, identifier:min_idx; 238, call; 239, identifier:min_idx; 240, integer:0; 241, expression_statement; 242, assignment; 243, identifier:max_idx; 244, binary_operator:x.searchsorted(xmax) + 1; 245, assignment; 246, string_content:data; 247, identifier:min_idx; 248, identifier:max_idx; 249, attribute; 250, argument_list; 251, augmented_assignment; 252, identifier:min_idx; 253, None; 254, call; 255, integer:1; 256, identifier:max_idx; 257, None; 258, attribute; 259, argument_list; 260, augmented_assignment; 261, identifier:min_idx; 262, None; 263, call; 264, integer:1; 265, identifier:max_idx; 266, None; 267, identifier:x; 268, identifier:searchsorted; 269, identifier:xmin; 270, identifier:min_idx; 271, integer:1; 272, attribute; 273, argument_list; 274, identifier:x; 275, identifier:searchsorted; 276, identifier:xmin; 277, identifier:min_idx; 278, integer:1; 279, attribute; 280, argument_list; 281, identifier:x; 282, identifier:searchsorted; 283, identifier:xmax; 284, identifier:x; 285, identifier:searchsorted; 286, identifier:xmax
code: def _prepare_data(self):
          """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.
  
          """
          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)