          xmax = self.calcs.iterations - 1 if self.calcs.iterations > 1 else 1
          if data:
              ymin, ymax = self.axes_data_get_min_max(data)
              self.ax1.set_ylim(ymin, ymax)
              self.ax1.set_xlim(0, xmax)
              logger.trace("axes ranges: (y: (%s, %s), x:(0, %s)", ymin, ymax, xmax)
          else:
              self.axes_limits_set_default()
  
      @staticmethod
 
</s> remove         xmax = self.calcs.iterations - 1 if self.calcs.iterations > 1 else 1
 </s> add         xmin = self.calcs.start_iteration
        if self.calcs.start_iteration > 0:
            xmax = self.calcs.iterations + self.calcs.start_iteration
        else:
            xmax = self.calcs.iterations
        xmax = max(1, xmax - 1)
 </s> remove         for item in data:
            dataset = list(filter(lambda x: x is not None, item))
            if not dataset:
                continue
            ymin.append(min(dataset) * 1000)
            ymax.append(max(dataset) * 1000)
 </s> add         for item in data:  # TODO Handle as array not loop
            ymin.append(np.nanmin(item) * 1000)
            ymax.append(np.nanmax(item) * 1000) </s> remove         xrng = [x for x in range(self.calcs.iterations)]
 </s> add         if self.calcs.start_iteration > 0:
            end_iteration = self.calcs.start_iteration + self.calcs.iterations
            xrng = list(range(self.calcs.start_iteration, end_iteration))
        else:
            xrng = list(range(self.calcs.iterations))
 </s> remove                 if self.args["flatten_outliers"]:
                    loss = self.flatten_outliers(loss)
                iterations.add(len(loss))
                raw["raw_{}".format(loss_name)] = loss
 </s> add                 iterations.add(loss.shape[0])

                if self._limit > 0:
                    loss = loss[-self._limit:]

                if self._args["flatten_outliers"]:
                    loss = self._flatten_outliers(loss)

                self.stats["raw_{}".format(loss_name)] = loss

            self._iterations = 0 if not iterations else min(iterations)
            if self._limit > 1:
                self._start_iteration = max(0, self._iterations - self._limit)
                self._iterations = min(self._iterations, self._limit)
            else:
                self._start_iteration = 0 </s> remove     def remove_raw(self):
        """ Remove raw values from stats if not requested """
        if "raw" in self.selections:
 </s> add     @classmethod
    def _flatten_outliers(cls, data):
        """ Remove the outliers from a provided list.

        Removes data more than 1 Standard Deviation from the mean.

        Parameters
        ----------
        data: :class:`numpy.ndarray`
            The data to remove the outliers from

        Returns
        -------
        :class:`numpy.ndarray`
            The data with outliers removed
        """
        logger.debug("Flattening outliers: %s", data.shape)
        mean = np.mean(data)
        limit = np.std(data)
        logger.debug("mean: %s, limit: %s", mean, limit)
        retdata = np.where(abs(data - mean) < limit, data, mean)
        logger.debug("Flattened outliers")
        return retdata

    def _remove_raw(self):
        """ Remove raw values from :attr:`stats` if they are not requested. """
        if "raw" in self._selections:
            self.ax1.set_xlim(xmin, xmax)
          xmax = self.calcs.iterations - 1 if self.calcs.iterations > 1 else 1
          if data:
              ymin, ymax = self.axes_data_get_min_max(data)
              self.ax1.set_ylim(ymin, ymax)
            self.ax1.set_xlim(xmin, xmax)
              logger.trace("axes ranges: (y: (%s, %s), x:(0, %s)", ymin, ymax, xmax)
          else:
              self.axes_limits_set_default()
  
      @staticmethod
keep keep keep keep replace keep keep keep keep keep
 GUI - Stats optimization (#1067)

* Faster stat loading + caching

* Compress data in cache

* Optimize some calculations

* Vectorize smoothing

* stats.Calculations optimized

* Load latest training data from live iterator

* Add options to training graph 
lib/gui/display_graph.py