h2o-py/h2o/frame.py
def hist(self, breaks="sturges", plot=True, **kwargs):
        """
        Compute a histogram over a numeric column.

        :param breaks: Can be one of ``"sturges"``, ``"rice"``, ``"sqrt"``, ``"doane"``, ``"fd"``, ``"scott"``;
            or a single number for the number of breaks; or a list containing the split points, e.g:
            ``[-50, 213.2123, 9324834]``. If breaks is "fd", the MAD is used over the IQR in computing bin width.
        :param bool plot: If True (default), then a plot will be generated using ``matplotlib``.

        :returns: If ``plot`` is False, return H2OFrame with these columns: breaks, counts, mids_true,
            mids, and density; otherwise this method draws a plot and returns nothing.
        """
        server = kwargs.pop("server") if "server" in kwargs else False
        assert_is_type(breaks, int, [numeric], Enum("sturges", "rice", "sqrt", "doane", "fd", "scott"))
        assert_is_type(plot, bool)
        assert_is_type(server, bool)
        if kwargs:
            raise H2OValueError("Unknown parameters to hist(): %r" % kwargs)
        hist = H2OFrame._expr(expr=ExprNode("hist", self, breaks))._frame()

        if plot:
            try:
                import matplotlib
                if server:
                    matplotlib.use("Agg", warn=False)
                import matplotlib.pyplot as plt
            except ImportError:
                print("ERROR: matplotlib is required to make the histogram plot. "
                      "Set `plot` to False, if a plot is not desired.")
                return

            hist["widths"] = hist["breaks"].difflag1()
            # [2:] because we're removing the title and the first row (which consists of NaNs)
            lefts = [float(c[0]) for c in h2o.as_list(hist["breaks"], use_pandas=False)[2:]]
            widths = [float(c[0]) for c in h2o.as_list(hist["widths"], use_pandas=False)[2:]]
            counts = [float(c[0]) for c in h2o.as_list(hist["counts"], use_pandas=False)[2:]]

            plt.xlabel(self.names[0])
            plt.ylabel("Frequency")
            plt.title("Histogram of %s" % self.names[0])
            plt.bar(left=lefts, width=widths, height=counts, bottom=0)
            if not server:
                plt.show()
        else:
            hist["density"] = hist["counts"] / (hist["breaks"].difflag1() * hist["counts"].sum())
            return hist
def hist(self, breaks="sturges", plot=True, **kwargs):
        """
        Compute a histogram over a numeric column.

        :param breaks: Can be one of ``"sturges"``, ``"rice"``, ``"sqrt"``, ``"doane"``, ``"fd"``, ``"scott"``;
            or a single number for the number of breaks; or a list containing the split points, e.g:
            ``[-50, 213.2123, 9324834]``. If breaks is "fd", the MAD is used over the IQR in computing bin width.
        :param bool plot: If True (default), then a plot will be generated using ``matplotlib``.

        :returns: If ``plot`` is False, return H2OFrame with these columns: breaks, counts, mids_true,
            mids, and density; otherwise this method draws a plot and returns nothing.
        """
        server = kwargs.pop("server") if "server" in kwargs else False
        assert_is_type(breaks, int, [numeric], Enum("sturges", "rice", "sqrt", "doane", "fd", "scott"))
        assert_is_type(plot, bool)
        assert_is_type(server, bool)
        if kwargs:
            raise H2OValueError("Unknown parameters to hist(): %r" % kwargs)
        hist = H2OFrame._expr(expr=ExprNode("hist", self, breaks))._frame()

        if plot:
            try:
                import matplotlib
                if server:
                    matplotlib.use("Agg", warn=False)
                import matplotlib.pyplot as plt
            except ImportError:
                print("ERROR: matplotlib is required to make the histogram plot. "
                      "Set `plot` to False, if a plot is not desired.")
                return

            hist["widths"] = hist["breaks"].difflag1()
            # [2:] because we're removing the title and the first row (which consists of NaNs)
            lefts = [float(c[0]) for c in h2o.as_list(hist["breaks"], use_pandas=False)[2:]]
            widths = [float(c[0]) for c in h2o.as_list(hist["widths"], use_pandas=False)[2:]]
            counts = [float(c[0]) for c in h2o.as_list(hist["counts"], use_pandas=False)[2:]]

            plt.xlabel(self.names[0])
            plt.ylabel("Frequency")
            plt.title("Histogram of %s" % self.names[0])
            plt.bar(left=lefts, width=widths, height=counts, bottom=0)
            if not server:
                plt.show()
        else:
            hist["density"] = hist["counts"] / (hist["breaks"].difflag1() * hist["counts"].sum())
            return hist
Compute a histogram over a numeric column.

        :param breaks: Can be one of ``"sturges"``, ``"rice"``, ``"sqrt"``, ``"doane"``, ``"fd"``, ``"scott"``;
            or a single number for the number of breaks; or a list containing the split points, e.g:
            ``[-50, 213.2123, 9324834]``. If breaks is "fd", the MAD is used over the IQR in computing bin width.
        :param bool plot: If True (default), then a plot will be generated using ``matplotlib``.

        :returns: If ``plot`` is False, return H2OFrame with these columns: breaks, counts, mids_true,
            mids, and density; otherwise this method draws a plot and returns nothing.