def dendrogram(Z, p=30, truncate_mode=None, color_threshold=None, get_leaves=True, orientation='top', labels=None, count_sort=False, distance_sort=False, show_leaf_counts=True, no_plot=False, no_labels=False, leaf_font_size=None, leaf_rotation=None, leaf_label_func=None, show_contracted=False, link_color_func=None, ax=None, above_threshold_color='b'):
 Z = np.asarray(Z, order='c')
 if (orientation not in ['top', 'left', 'bottom', 'right']):
  raise ValueError("orientation must be one of 'top', 'left', 'bottom', or 'right'")
 is_valid_linkage(Z, throw=True, name='Z')
 Zs = Z.shape
 n = (Zs[0] + 1)
 if (type(p) in (int, float)):
  p = int(p)
 else:
  raise TypeError('The second argument must be a number')
 if (truncate_mode not in ('lastp', 'mlab', 'mtica', 'level', 'none', None)):
  raise ValueError('Invalid truncation mode.')
 if ((truncate_mode == 'lastp') or (truncate_mode == 'mlab')):
  if ((p > n) or (p == 0)):
   p = n
 if (truncate_mode == 'mtica'):
  truncate_mode = 'level'
 if (truncate_mode == 'level'):
  if (p <= 0):
   p = np.inf
 if get_leaves:
  lvs = []
 else:
  lvs = None
 icoord_list = []
 dcoord_list = []
 color_list = []
 current_color = [0]
 currently_below_threshold = [False]
 ivl = []
 if ((color_threshold is None) or (isinstance(color_threshold, string_types) and (color_threshold == 'default'))):
  color_threshold = (max(Z[:, 2]) * 0.7)
 R = {'icoord': icoord_list, 'dcoord': dcoord_list, 'ivl': ivl, 'leaves': lvs, 'color_list': color_list}
 contraction_marks = ([] if show_contracted else None)
 _dendrogram_calculate_info(Z=Z, p=p, truncate_mode=truncate_mode, color_threshold=color_threshold, get_leaves=get_leaves, orientation=orientation, labels=labels, count_sort=count_sort, distance_sort=distance_sort, show_leaf_counts=show_leaf_counts, i=((2 * n) - 2), iv=0.0, ivl=ivl, n=n, icoord_list=icoord_list, dcoord_list=dcoord_list, lvs=lvs, current_color=current_color, color_list=color_list, currently_below_threshold=currently_below_threshold, leaf_label_func=leaf_label_func, contraction_marks=contraction_marks, link_color_func=link_color_func, above_threshold_color=above_threshold_color)
 if (not no_plot):
  mh = max(Z[:, 2])
  _plot_dendrogram(icoord_list, dcoord_list, ivl, p, n, mh, orientation, no_labels, color_list, leaf_font_size=leaf_font_size, leaf_rotation=leaf_rotation, contraction_marks=contraction_marks, ax=ax, above_threshold_color=above_threshold_color)
 return R

def dendrogram ( Z , p = 30 , truncate_mode = None , color_threshold = None , get_leaves = True , orientation = 'top' , labels = None , count_sort = False , distance_sort = False , show_leaf_counts = True , no_plot = False , no_labels = False , leaf_font_size = None , leaf_rotation = None , leaf_label_func = None , show_contracted = False , link_color_func = None , ax = None , above_threshold_color = 'b' ) : Z = np . asarray ( Z , order = 'c' ) if ( orientation not in [ 'top' , 'left' , 'bottom' , 'right' ] ) : raise ValueError ( "orientation must be one of 'top', 'left', 'bottom', or 'right'" ) is_valid_linkage ( Z , throw = True , name = 'Z' ) Zs = Z . shape n = ( Zs [ 0 ] + 1 ) if ( type ( p ) in ( int , float ) ) : p = int ( p ) else : raise TypeError ( 'The second argument must be a number' ) if ( truncate_mode not in ( 'lastp' , 'mlab' , 'mtica' , 'level' , 'none' , None ) ) : raise ValueError ( 'Invalid truncation mode.' ) if ( ( truncate_mode == 'lastp' ) or ( truncate_mode == 'mlab' ) ) : if ( ( p > n ) or ( p == 0 ) ) : p = n if ( truncate_mode == 'mtica' ) : truncate_mode = 'level' if ( truncate_mode == 'level' ) : if ( p <= 0 ) : p = np . inf if get_leaves : lvs = [ ] else : lvs = None icoord_list = [ ] dcoord_list = [ ] color_list = [ ] current_color = [ 0 ] currently_below_threshold = [ False ] ivl = [ ] if ( ( color_threshold is None ) or ( isinstance ( color_threshold , string_types ) and ( color_threshold == 'default' ) ) ) : color_threshold = ( max ( Z [ : , 2 ] ) * 0.7 ) R = { 'icoord' : icoord_list , 'dcoord' : dcoord_list , 'ivl' : ivl , 'leaves' : lvs , 'color_list' : color_list } contraction_marks = ( [ ] if show_contracted else None ) _dendrogram_calculate_info ( Z = Z , p = p , truncate_mode = truncate_mode , color_threshold = color_threshold , get_leaves = get_leaves , orientation = orientation , labels = labels , count_sort = count_sort , distance_sort = distance_sort , show_leaf_counts = show_leaf_counts , i = ( ( 2 * n ) - 2 ) , iv = 0.0 , ivl = ivl , n = n , icoord_list = icoord_list , dcoord_list = dcoord_list , lvs = lvs , current_color = current_color , color_list = color_list , currently_below_threshold = currently_below_threshold , leaf_label_func = leaf_label_func , contraction_marks = contraction_marks , link_color_func = link_color_func , above_threshold_color = above_threshold_color ) if ( not no_plot ) : mh = max ( Z [ : , 2 ] ) _plot_dendrogram ( icoord_list , dcoord_list , ivl , p , n , mh , orientation , no_labels , color_list , leaf_font_size = leaf_font_size , leaf_rotation = leaf_rotation , contraction_marks = contraction_marks , ax = ax , above_threshold_color = above_threshold_color ) return R
draw a tree diagram of relationships within a matrix parameters data : pandas .