df_extensions/space.py
def plot(
        self,
        limit_columns: Optional[List[str]] = None,
        only_one: Optional[Any] = None,
        show_legend: bool = True,
    ):
        """
        Plot either all possible x, y graphs for k clusters
        or just the subset with the named x_var and y_var.
        """
        k = self.k
        df = self.df

        num_rows = 3

        vars = self.cols
        if limit_columns:
            vars = [x for x in vars if x in limit_columns]
        combos = list(combinations(vars, 2))
        rows = math.ceil(len(combos) / num_rows)

        plt.rcParams["figure.figsize"] = (15, 5 * rows)

        df["labels"] = self.get_cluster_labels()

        if only_one:
            df["labels"] = df["labels"] == only_one
            df["labels"] = df["labels"].map({True: only_one, False: "Other clusters"})
        chart_no = 0

        rgb_values = sns.color_palette("Set2", len(df["labels"].unique()))
        color_map = dict(zip(df["labels"].unique(), rgb_values))
        fig = plt.figure()

        for x_var, y_var in combos:
            chart_no += 1
            ax = fig.add_subplot(rows, num_rows, chart_no)
            for c, d in df.groupby("labels"):
                scatter = ax.scatter(d[x_var], d[y_var], color=color_map[c], label=c)

            ax.set_xlabel(self._axis_label(x_var))
            ax.set_ylabel(self._axis_label(y_var))
            if show_legend:
                ax.legend()

        plt.show()

        Plot either all possible x, y graphs for k clusters
        or just the subset with the named x_var and y_var.
        
Plot either all possible x, y graphs for k clusters
or just the subset with the named x_var and y_var.
Plot either all possible x y graphs for k clusters or just the subset with the named x_var and y_var .
def plot(
        self,
        limit_columns: Optional[List[str]] = None,
        only_one: Optional[Any] = None,
        show_legend: bool = True,
    ):
        k = self.k
        df = self.df
        num_rows = 3
        vars = self.cols
        if limit_columns:
            vars = [x for x in vars if x in limit_columns]
        combos = list(combinations(vars, 2))
        rows = math.ceil(len(combos) / num_rows)
        plt.rcParams["figure.figsize"] = (15, 5 * rows)
        df["labels"] = self.get_cluster_labels()
        if only_one:
            df["labels"] = df["labels"] == only_one
            df["labels"] = df["labels"].map({True: only_one, False: "Other clusters"})
        chart_no = 0
        rgb_values = sns.color_palette("Set2", len(df["labels"].unique()))
        color_map = dict(zip(df["labels"].unique(), rgb_values))
        fig = plt.figure()
        for x_var, y_var in combos:
            chart_no += 1
            ax = fig.add_subplot(rows, num_rows, chart_no)
            for c, d in df.groupby("labels"):
                scatter = ax.scatter(d[x_var], d[y_var], color=color_map[c], label=c)
            ax.set_xlabel(self._axis_label(x_var))
            ax.set_ylabel(self._axis_label(y_var))
            if show_legend:
                ax.legend()
        plt.show()
def plot ( self , limit_columns : Optional [ List [ str ] ] = None , only_one : Optional [ Any ] = None , show_legend : bool = True , ) : k = self . k df = self . df num_rows = 3 vars = self . cols if limit_columns : vars = [ x for x in vars if x in limit_columns ] combos = list ( combinations ( vars , 2 ) ) rows = math . ceil ( len ( combos ) / num_rows ) plt . rcParams [ "figure.figsize" ] = ( 15 , 5 * rows ) df [ "labels" ] = self . get_cluster_labels ( ) if only_one : df [ "labels" ] = df [ "labels" ] == only_one df [ "labels" ] = df [ "labels" ] . map ( { True : only_one , False : "Other clusters" } ) chart_no = 0 rgb_values = sns . color_palette ( "Set2" , len ( df [ "labels" ] . unique ( ) ) ) color_map = dict ( zip ( df [ "labels" ] . unique ( ) , rgb_values ) ) fig = plt . figure ( ) for x_var , y_var in combos : chart_no += 1 ax = fig . add_subplot ( rows , num_rows , chart_no ) for c , d in df . groupby ( "labels" ) : scatter = ax . scatter ( d [ x_var ] , d [ y_var ] , color = color_map [ c ] , label = c ) ax . set_xlabel ( self . _axis_label ( x_var ) ) ax . set_ylabel ( self . _axis_label ( y_var ) ) if show_legend : ax . legend ( ) plt . show ( )
Plot either all possible x, y graphs for k clusters
or just the subset with the named x_var and y_var.
Plot either all possible x y graphs for k clusters or just the subset with the named x_var and y_var .
"""
        Plot either all possible x, y graphs for k clusters
        or just the subset with the named x_var and y_var.
        """
self
limit_columns
Optional[List[str]]
only_one
Optional[Any]
show_legend
bool