def _calculate(self, data):
        x = data.pop('x')
        fun = self.params['fun']
        n = self.params['n']
        args = self.params['args']

        if not hasattr(fun, '__call__'):
            raise GgplotError("stat_function requires parameter 'fun' to be " +
                            "a function or any other callable object")

        old_fun = fun
        if isinstance(args,list):
            fun = lambda x: old_fun(x, *args)
        elif isinstance(args,dict):
            fun = lambda x: old_fun(x, **args)
        elif args is not None:
            fun = lambda x: old_fun(x, args)
        else:
            fun = lambda x: old_fun(x)

        x = np.linspace(x.min(), x.max(),n)
        y = list(map(fun, x))

        new_data = pd.DataFrame({'x': x, 'y': y})

        # Copy the other aesthetics into the new dataframe
        # Don't copy the any previous 'y' assignments
        try:
            del data['y']
        except __HOLE__:
            pass

        n = len(x)
        for ae in data:
            new_data[ae] = make_iterable_ntimes(data[ae].iloc[0], n)
        return new_data
dataset/ETHPy150Open yhat/ggplot/ggplot/stats/stat_function.py/stat_function._calculate