def __init__(self, *args, **kwargs):
        """Create a matplotlib window with sliders for all parameters
        in this model, so that you may graphically guess initial fitting
        parameters. n_points is the number of points drawn for the plot.
        Data points are plotted as a blue contour plot, the proposed model as
        a red line. The errorbars on the proposed model represent the
        percentile of data within the thresholds.

        Slider extremes are taken from the parameters where possible. If
        these are not provided, the minimum is 0; and the maximum is value*2.
        If no initial value is provided, it defaults to 1.

        This will modify the values of the parameters present in model.

        :param n_points: The number of points used for drawing the
            fitted function. Defaults to 50.
        :type n_points: int

        :param log_contour: Whether to plot the contour plot of the log of the
            density, rather than the density itself. If True, any density less
            than 1e-7 will be considered 0. Defaults to True.
        :type log_contour: bool

        :param percentile: Controls the errorbars on the proposed model, such
            that the lower errorbar will cover percentile[0]% of the data, and
            the upper will cover percentile[1]%. Defaults to [5, 95], with
            corresponds to a 90% percentile. Should be a list of 2 numbers.
        :type percentile: list
        """
        self.log_contour = kwargs.pop('log_contour')
        n_points = kwargs.pop('n_points')
        self.percentile = kwargs.pop('percentile')
        super(InteractiveGuess, self).__init__(*args, **kwargs)
        if len(self.independent_data) > 1:
            self._dimension_strategy = StrategynD(self)
        else:
            self._dimension_strategy = Strategy2D(self)
        # TODO: Some of the code here is specific to the n-D case and should
        # be moved.
        self._projections = list(itertools.product(self.model.independent_vars,
                                                   self.model.dependent_vars))
        x_mins = {v: np.min(data) for v, data in self.independent_data.items()}
        x_maxs = {v: np.max(data) for v, data in self.independent_data.items()}

        # Stretch the plot 10-20% in the X direction, since that is visually
        # more appealing. We can't evaluate the model for x < x_initial, so
        # don't.
        for x in self.model.independent_vars:
            plotrange_x = x_maxs[x] - x_mins[x]
            if not hasattr(self.model, 'initial'):
                x_mins[x] -= 0.1 * plotrange_x
            x_maxs[x] += 0.1 * plotrange_x
        # Generate the points at which to evaluate the model with the proposed
        # parameters for plotting
        self._x_points = {v: np.linspace(x_mins[v], x_maxs[v], n_points)
                          for v in self.independent_data}
        meshgrid = np.meshgrid(*(self._x_points[v]
                                 for v in self.independent_data))
        self._x_grid = {v: meshgrid[idx].flatten()
                        for idx, v in enumerate(self.independent_data)}

        # Stretch the plot 20% in the Y direction, since that is visually more
        # appealing
        y_mins = {v: np.min(data) for v, data in self.dependent_data.items()}
        y_maxs = {v: np.max(data) for v, data in self.dependent_data.items()}
        for y in self.dependent_data:
            plotrange_y = y_maxs[y] - y_mins[y]
            y_mins[y] -= 0.1 * plotrange_y
            y_maxs[y] += 0.1 * plotrange_y

        self._y_points = {v: np.linspace(y_mins[v], y_maxs[v], n_points)
                          for v in self.dependent_data}

        self._set_up_figure(x_mins, x_maxs, y_mins, y_maxs)
        self._set_up_sliders()
        self._update_plot(None)
def __init__ ( self , * args , ** kwargs ) : self . log_contour = kwargs . pop ( 'log_contour' ) n_points = kwargs . pop ( 'n_points' ) self . percentile = kwargs . pop ( 'percentile' ) super ( InteractiveGuess , self ) . __init__ ( * args , ** kwargs ) if len ( self . independent_data ) > 1 : self . _dimension_strategy = StrategynD ( self ) else : self . _dimension_strategy = Strategy2D ( self ) self . _projections = list ( itertools . product ( self . model . independent_vars , self . model . dependent_vars ) ) x_mins = { v : np . min ( data ) for v , data in self . independent_data . items ( ) } x_maxs = { v : np . max ( data ) for v , data in self . independent_data . items ( ) } for x in self . model . independent_vars : plotrange_x = x_maxs [ x ] - x_mins [ x ] if not hasattr ( self . model , 'initial' ) : x_mins [ x ] -= 0.1 * plotrange_x x_maxs [ x ] += 0.1 * plotrange_x self . _x_points = { v : np . linspace ( x_mins [ v ] , x_maxs [ v ] , n_points ) for v in self . independent_data } meshgrid = np . meshgrid ( * ( self . _x_points [ v ] for v in self . independent_data ) ) self . _x_grid = { v : meshgrid [ idx ] . flatten ( ) for idx , v in enumerate ( self . independent_data ) } y_mins = { v : np . min ( data ) for v , data in self . dependent_data . items ( ) } y_maxs = { v : np . max ( data ) for v , data in self . dependent_data . items ( ) } for y in self . dependent_data : plotrange_y = y_maxs [ y ] - y_mins [ y ] y_mins [ y ] -= 0.1 * plotrange_y y_maxs [ y ] += 0.1 * plotrange_y self . _y_points = { v : np . linspace ( y_mins [ v ] , y_maxs [ v ] , n_points ) for v in self . dependent_data } self . _set_up_figure ( x_mins , x_maxs , y_mins , y_maxs ) self . _set_up_sliders ( ) self . _update_plot ( None )
Create a matplotlib window with sliders for all parameters
        in this model, so that you may graphically guess initial fitting
        parameters. n_points is the number of points drawn for the plot.
        Data points are plotted as a blue contour plot, the proposed model as
        a red line. The errorbars on the proposed model represent the
        percentile of data within the thresholds.

        Slider extremes are taken from the parameters where possible. If
        these are not provided, the minimum is 0; and the maximum is value*2.
        If no initial value is provided, it defaults to 1.

        This will modify the values of the parameters present in model.

        :param n_points: The number of points used for drawing the
            fitted function. Defaults to 50.
        :type n_points: int

        :param log_contour: Whether to plot the contour plot of the log of the
            density, rather than the density itself. If True, any density less
            than 1e-7 will be considered 0. Defaults to True.
        :type log_contour: bool

        :param percentile: Controls the errorbars on the proposed model, such
            that the lower errorbar will cover percentile[0]% of the data, and
            the upper will cover percentile[1]%. Defaults to [5, 95], with
            corresponds to a 90% percentile. Should be a list of 2 numbers.
        :type percentile: list