original_docstring: Create a heatmap indicating average between label distance
  
  
      Args:
          distance: (pandas dataframe) brain_distance matrix
          labels: (pandas dataframe) group labels
          ax: axis to plot (default=None)
          permutation_test: (boolean)
          n_permute: (int) number of samples for permuation test
          fontsize: (int) size of font for plot
      Returns:
          f: heatmap
          out: pandas dataframe of pairwise distance between conditions
          within_dist_out: average pairwise distance matrix
          mn_dist_out: (optional if permutation_test=True) average difference in distance between conditions
          p_dist_out: (optional if permutation_test=True) p-value for difference in distance between conditions
      
docstring: Create a heatmap indicating average between label distance
docstring_tokens: Create a heatmap indicating average between label distance
code: def plot_between_label_distance(
      distance,
      labels,
      ax=None,
      permutation_test=True,
      n_permute=5000,
      fontsize=18,
      **kwargs,
  ):
      """Create a heatmap indicating average between label distance
  
  
      Args:
          distance: (pandas dataframe) brain_distance matrix
          labels: (pandas dataframe) group labels
          ax: axis to plot (default=None)
          permutation_test: (boolean)
          n_permute: (int) number of samples for permuation test
          fontsize: (int) size of font for plot
      Returns:
          f: heatmap
          out: pandas dataframe of pairwise distance between conditions
          within_dist_out: average pairwise distance matrix
          mn_dist_out: (optional if permutation_test=True) average difference in distance between conditions
          p_dist_out: (optional if permutation_test=True) p-value for difference in distance between conditions
      """
  
      labels = np.unique(np.array(labels))
  
      out = pd.DataFrame(columns=["Distance", "Group", "Comparison"], index=None)
      for i in labels:
          for j in labels:
              tmp_b = pd.DataFrame(columns=out.columns, index=None)
              if (
                  distance.loc[labels == i, labels == j].shape[0]
                  == distance.loc[labels == i, labels == j].shape[1]
              ):
                  tmp_b["Distance"] = distance.loc[labels == i, labels == i].values[
                      np.triu_indices(sum(labels == i), k=1)
                  ]
              else:
                  tmp_b["Distance"] = distance.loc[
                      labels == i, labels == j
                  ].values.flatten()
              tmp_b["Comparison"] = j
              tmp_b["Group"] = i
              out = out.append(tmp_b)
  
      within_dist_out = pd.DataFrame(
          np.zeros((len(out["Group"].unique()), len(out["Group"].unique()))),
          columns=out["Group"].unique(),
          index=out["Group"].unique(),
      )
      for i in out["Group"].unique():
          for j in out["Comparison"].unique():
              within_dist_out.loc[i, j] = out.loc[
                  (out["Group"] == i) & (out["Comparison"] == j)
              ]["Distance"].mean()
  
      if ax is None:
          _, ax = plt.subplots(1)
      else:
          plt.figure()
  
      if permutation_test:
          mn_dist_out = pd.DataFrame(
              np.zeros((len(out["Group"].unique()), len(out["Group"].unique()))),
              columns=out["Group"].unique(),
              index=out["Group"].unique(),
          )
          p_dist_out = pd.DataFrame(
              np.zeros((len(out["Group"].unique()), len(out["Group"].unique()))),
              columns=out["Group"].unique(),
              index=out["Group"].unique(),
          )
          for i in out["Group"].unique():
              for j in out["Comparison"].unique():
                  tmp1 = out.loc[
                      (out["Group"] == i) & (out["Comparison"] == i), "Distance"
                  ]
                  tmp2 = out.loc[
                      (out["Group"] == i) & (out["Comparison"] == j), "Distance"
                  ]
                  s = two_sample_permutation(tmp1, tmp2, n_permute=n_permute)
                  mn_dist_out.loc[i, j] = s["mean"]
                  p_dist_out.loc[i, j] = s["p"]
          sns.heatmap(mn_dist_out, ax=ax, square=True, **kwargs)
          sns.heatmap(
              mn_dist_out,
              mask=p_dist_out > 0.05,
              square=True,
              linewidth=2,
              annot=True,
              ax=ax,
              cbar=False,
          )
          return (out, within_dist_out, mn_dist_out, p_dist_out)
      else:
          sns.heatmap(within_dist_out, ax=ax, square=True, **kwargs)
          return (out, within_dist_out)
code_tokens: def plot_between_label_distance ( distance , labels , ax = None , permutation_test = True , n_permute = 5000 , fontsize = 18 , ** kwargs , ) : labels = np . unique ( np . array ( labels ) ) out = pd . DataFrame ( columns = [ "Distance" , "Group" , "Comparison" ] , index = None ) for i in labels : for j in labels : tmp_b = pd . DataFrame ( columns = out . columns , index = None ) if ( distance . loc [ labels == i , labels == j ] . shape [ 0 ] == distance . loc [ labels == i , labels == j ] . shape [ 1 ] ) : tmp_b [ "Distance" ] = distance . loc [ labels == i , labels == i ] . values [ np . triu_indices ( sum ( labels == i ) , k = 1 ) ] else : tmp_b [ "Distance" ] = distance . loc [ labels == i , labels == j ] . values . flatten ( ) tmp_b [ "Comparison" ] = j tmp_b [ "Group" ] = i out = out . append ( tmp_b ) within_dist_out = pd . DataFrame ( np . zeros ( ( len ( out [ "Group" ] . unique ( ) ) , len ( out [ "Group" ] . unique ( ) ) ) ) , columns = out [ "Group" ] . unique ( ) , index = out [ "Group" ] . unique ( ) , ) for i in out [ "Group" ] . unique ( ) : for j in out [ "Comparison" ] . unique ( ) : within_dist_out . loc [ i , j ] = out . loc [ ( out [ "Group" ] == i ) & ( out [ "Comparison" ] == j ) ] [ "Distance" ] . mean ( ) if ax is None : _ , ax = plt . subplots ( 1 ) else : plt . figure ( ) if permutation_test : mn_dist_out = pd . DataFrame ( np . zeros ( ( len ( out [ "Group" ] . unique ( ) ) , len ( out [ "Group" ] . unique ( ) ) ) ) , columns = out [ "Group" ] . unique ( ) , index = out [ "Group" ] . unique ( ) , ) p_dist_out = pd . DataFrame ( np . zeros ( ( len ( out [ "Group" ] . unique ( ) ) , len ( out [ "Group" ] . unique ( ) ) ) ) , columns = out [ "Group" ] . unique ( ) , index = out [ "Group" ] . unique ( ) , ) for i in out [ "Group" ] . unique ( ) : for j in out [ "Comparison" ] . unique ( ) : tmp1 = out . loc [ ( out [ "Group" ] == i ) & ( out [ "Comparison" ] == i ) , "Distance" ] tmp2 = out . loc [ ( out [ "Group" ] == i ) & ( out [ "Comparison" ] == j ) , "Distance" ] s = two_sample_permutation ( tmp1 , tmp2 , n_permute = n_permute ) mn_dist_out . loc [ i , j ] = s [ "mean" ] p_dist_out . loc [ i , j ] = s [ "p" ] sns . heatmap ( mn_dist_out , ax = ax , square = True , ** kwargs ) sns . heatmap ( mn_dist_out , mask = p_dist_out > 0.05 , square = True , linewidth = 2 , annot = True , ax = ax , cbar = False , ) return ( out , within_dist_out , mn_dist_out , p_dist_out ) else : sns . heatmap ( within_dist_out , ax = ax , square = True , ** kwargs ) return ( out , within_dist_out )
short_docstring: Create a heatmap indicating average between label distance
short_docstring_tokens: Create a heatmap indicating average between label distance
comment: """Create a heatmap indicating average between label distance
  
  
      Args:
          distance: (pandas dataframe) brain_distance matrix
          labels: (pandas dataframe) group labels
          ax: axis to plot (default=None)
          permutation_test: (boolean)
          n_permute: (int) number of samples for permuation test
          fontsize: (int) size of font for plot
      Returns:
          f: heatmap
          out: pandas dataframe of pairwise distance between conditions
          within_dist_out: average pairwise distance matrix
          mn_dist_out: (optional if permutation_test=True) average difference in distance between conditions
          p_dist_out: (optional if permutation_test=True) p-value for difference in distance between conditions
      """