df_extensions/space.py
def plot3d(
        self,
        x_var: Optional[str] = None,
        y_var: Optional[str] = None,
        z_var: Optional[str] = None,
    ):
        k = self.k
        """
        Plot either all possible x, y, z graphs for k clusters
        or just the subset with the named x_var and y_var.
        """
        df = self.df

        labels = self.get_cluster_labels()
        combos = list(combinations(df.columns, 3))
        if x_var:
            combos = [x for x in combos if x[0] == x_var]
        if y_var:
            combos = [x for x in combos if x[1] == y_var]
        if z_var:
            combos = [x for x in combos if x[1] == y_var]
        rows = math.ceil(len(combos) / 2)

        plt.rcParams["figure.figsize"] = (20, 10 * rows)

        chart_no = 0
        fig = plt.figure()
        for x_var, y_var, z_var in combos:
            chart_no += 1
            ax = fig.add_subplot(rows, 2, chart_no, projection="3d")
            ax.scatter(df[x_var], df[y_var], df[z_var], c=labels)
            ax.set_xlabel(self._axis_label(x_var))
            ax.set_ylabel(self._axis_label(y_var))
            ax.set_zlabel(self._axis_label(z_var))
            plt.title(f"Data with {k} clusters")

        plt.show()

        Plot either all possible x, y, z graphs for k clusters
        or just the subset with the named x_var and y_var.
        
Plot either all possible x, y, z graphs for k clusters
or just the subset with the named x_var and y_var.
Plot either all possible x y z graphs for k clusters or just the subset with the named x_var and y_var .
def plot3d(
        self,
        x_var: Optional[str] = None,
        y_var: Optional[str] = None,
        z_var: Optional[str] = None,
    ):
        k = self.k
        df = self.df
        labels = self.get_cluster_labels()
        combos = list(combinations(df.columns, 3))
        if x_var:
            combos = [x for x in combos if x[0] == x_var]
        if y_var:
            combos = [x for x in combos if x[1] == y_var]
        if z_var:
            combos = [x for x in combos if x[1] == y_var]
        rows = math.ceil(len(combos) / 2)
        plt.rcParams["figure.figsize"] = (20, 10 * rows)
        chart_no = 0
        fig = plt.figure()
        for x_var, y_var, z_var in combos:
            chart_no += 1
            ax = fig.add_subplot(rows, 2, chart_no, projection="3d")
            ax.scatter(df[x_var], df[y_var], df[z_var], c=labels)
            ax.set_xlabel(self._axis_label(x_var))
            ax.set_ylabel(self._axis_label(y_var))
            ax.set_zlabel(self._axis_label(z_var))
            plt.title(f"Data with {k} clusters")
        plt.show()
def plot3d ( self , x_var : Optional [ str ] = None , y_var : Optional [ str ] = None , z_var : Optional [ str ] = None , ) : k = self . k df = self . df labels = self . get_cluster_labels ( ) combos = list ( combinations ( df . columns , 3 ) ) if x_var : combos = [ x for x in combos if x [ 0 ] == x_var ] if y_var : combos = [ x for x in combos if x [ 1 ] == y_var ] if z_var : combos = [ x for x in combos if x [ 1 ] == y_var ] rows = math . ceil ( len ( combos ) / 2 ) plt . rcParams [ "figure.figsize" ] = ( 20 , 10 * rows ) chart_no = 0 fig = plt . figure ( ) for x_var , y_var , z_var in combos : chart_no += 1 ax = fig . add_subplot ( rows , 2 , chart_no , projection = "3d" ) ax . scatter ( df [ x_var ] , df [ y_var ] , df [ z_var ] , c = labels ) ax . set_xlabel ( self . _axis_label ( x_var ) ) ax . set_ylabel ( self . _axis_label ( y_var ) ) ax . set_zlabel ( self . _axis_label ( z_var ) ) plt . title ( f"Data with {k} clusters" ) plt . show ( )
Plot either all possible x, y, z graphs for k clusters
or just the subset with the named x_var and y_var.
Plot either all possible x y z graphs for k clusters or just the subset with the named x_var and y_var .
"""
        Plot either all possible x, y, z graphs for k clusters
        or just the subset with the named x_var and y_var.
        """
self
x_var
Optional[str]
y_var
Optional[str]
z_var
Optional[str]