original_docstring: Create a violin plot indicating within and between label distance.
  
      Args:
          distance:  pandas dataframe of distance
          labels: labels indicating columns and rows to group
          ax: matplotlib axis to plot on
          permutation_test: (bool) indicates whether to run permuatation test or not
          n_permute: (int) number of permutations to run
          fontsize: (int) fontsize for plot labels
      Returns:
          f: heatmap
          stats: (optional if permutation_test=True) permutation results
  
      
docstring: Create a violin plot indicating within and between label distance.
docstring_tokens: Create a violin plot indicating within and between label distance .
code: def plot_mean_label_distance(
      distance,
      labels,
      ax=None,
      permutation_test=False,
      n_permute=5000,
      fontsize=18,
      **kwargs,
  ):
      """Create a violin plot indicating within and between label distance.
  
      Args:
          distance:  pandas dataframe of distance
          labels: labels indicating columns and rows to group
          ax: matplotlib axis to plot on
          permutation_test: (bool) indicates whether to run permuatation test or not
          n_permute: (int) number of permutations to run
          fontsize: (int) fontsize for plot labels
      Returns:
          f: heatmap
          stats: (optional if permutation_test=True) permutation results
  
      """
  
      if not isinstance(distance, pd.DataFrame):
          raise ValueError("distance must be a pandas dataframe")
  
      if distance.shape[0] != distance.shape[1]:
          raise ValueError("distance must be square.")
  
      if len(labels) != distance.shape[0]:
          raise ValueError("Labels must be same length as distance matrix")
  
      out = pd.DataFrame(columns=["Distance", "Group", "Type"], index=None)
      for i in labels.unique():
          tmp_w = pd.DataFrame(columns=out.columns, index=None)
          tmp_w["Distance"] = distance.loc[labels == i, labels == i].values[
              np.triu_indices(sum(labels == i), k=1)
          ]
          tmp_w["Type"] = "Within"
          tmp_w["Group"] = i
          tmp_b = pd.DataFrame(columns=out.columns, index=None)
          tmp_b["Distance"] = distance.loc[labels == i, labels != i].values.flatten()
          tmp_b["Type"] = "Between"
          tmp_b["Group"] = i
          out = out.append(tmp_w).append(tmp_b)
      f = sns.violinplot(
          x="Group",
          y="Distance",
          hue="Type",
          data=out,
          split=True,
          inner="quartile",
          palette={"Within": "lightskyblue", "Between": "red"},
          ax=ax,
          **kwargs,
      )
      f.set_ylabel("Average Distance", fontsize=fontsize)
      f.set_title("Average Group Distance", fontsize=fontsize)
      if permutation_test:
          stats = dict()
          for i in labels.unique():
              # Between group test
              tmp1 = out.loc[(out["Group"] == i) & (out["Type"] == "Within"), "Distance"]
              tmp2 = out.loc[(out["Group"] == i) & (out["Type"] == "Between"), "Distance"]
              stats[str(i)] = two_sample_permutation(tmp1, tmp2, n_permute=n_permute)
          return (f, stats)
      else:
          return f
code_tokens: def plot_mean_label_distance ( distance , labels , ax = None , permutation_test = False , n_permute = 5000 , fontsize = 18 , ** kwargs , ) : if not isinstance ( distance , pd . DataFrame ) : raise ValueError ( "distance must be a pandas dataframe" ) if distance . shape [ 0 ] != distance . shape [ 1 ] : raise ValueError ( "distance must be square." ) if len ( labels ) != distance . shape [ 0 ] : raise ValueError ( "Labels must be same length as distance matrix" ) out = pd . DataFrame ( columns = [ "Distance" , "Group" , "Type" ] , index = None ) for i in labels . unique ( ) : tmp_w = pd . DataFrame ( columns = out . columns , index = None ) tmp_w [ "Distance" ] = distance . loc [ labels == i , labels == i ] . values [ np . triu_indices ( sum ( labels == i ) , k = 1 ) ] tmp_w [ "Type" ] = "Within" tmp_w [ "Group" ] = i tmp_b = pd . DataFrame ( columns = out . columns , index = None ) tmp_b [ "Distance" ] = distance . loc [ labels == i , labels != i ] . values . flatten ( ) tmp_b [ "Type" ] = "Between" tmp_b [ "Group" ] = i out = out . append ( tmp_w ) . append ( tmp_b ) f = sns . violinplot ( x = "Group" , y = "Distance" , hue = "Type" , data = out , split = True , inner = "quartile" , palette = { "Within" : "lightskyblue" , "Between" : "red" } , ax = ax , ** kwargs , ) f . set_ylabel ( "Average Distance" , fontsize = fontsize ) f . set_title ( "Average Group Distance" , fontsize = fontsize ) if permutation_test : stats = dict ( ) for i in labels . unique ( ) : tmp1 = out . loc [ ( out [ "Group" ] == i ) & ( out [ "Type" ] == "Within" ) , "Distance" ] tmp2 = out . loc [ ( out [ "Group" ] == i ) & ( out [ "Type" ] == "Between" ) , "Distance" ] stats [ str ( i ) ] = two_sample_permutation ( tmp1 , tmp2 , n_permute = n_permute ) return ( f , stats ) else : return f
short_docstring: Create a violin plot indicating within and between label distance.
short_docstring_tokens: Create a violin plot indicating within and between label distance .
comment: """Create a violin plot indicating within and between label distance.
  
      Args:
          distance:  pandas dataframe of distance
          labels: labels indicating columns and rows to group
          ax: matplotlib axis to plot on
          permutation_test: (bool) indicates whether to run permuatation test or not
          n_permute: (int) number of permutations to run
          fontsize: (int) fontsize for plot labels
      Returns:
          f: heatmap
          stats: (optional if permutation_test=True) permutation results
  
      """$SEP$# Between group test