nodes: 0, module; 1, function_definition; 2, function_name:dendrogram; 3, parameters; 4, block; 5, identifier:df; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, default_parameter; 12, default_parameter; 13, default_parameter; 14, default_parameter; 15, expression_statement; 16, if_statement; 17, expression_statement; 18, expression_statement; 19, expression_statement; 20, expression_statement; 21, expression_statement; 22, comment:# Link the hierarchical output matrix, figure out orientation, construct base dendrogram.; 23, expression_statement; 24, expression_statement; 25, if_statement; 26, expression_statement; 27, comment:# Remove extraneous default visual elements.; 28, expression_statement; 29, expression_statement; 30, if_statement; 31, expression_statement; 32, expression_statement; 33, expression_statement; 34, expression_statement; 35, expression_statement; 36, expression_statement; 37, expression_statement; 38, comment:# Set up the categorical axis labels and draw.; 39, if_statement; 40, if_statement; 41, if_statement; 42, identifier:method; 43, string; 44, identifier:filter; 45, None; 46, identifier:n; 47, integer:0; 48, identifier:p; 49, integer:0; 50, identifier:sort; 51, None; 52, identifier:orientation; 53, None; 54, identifier:figsize; 55, None; 56, identifier:fontsize; 57, integer:16; 58, identifier:inline; 59, False; 60, comment:"""
      Fits a `scipy` hierarchical clustering algorithm to the given DataFrame's variables and visualizes the results as
      a `scipy` dendrogram.
      
      The default vertical display will fit up to 50 columns. If more than 50 columns are specified and orientation is
      left unspecified the dendrogram will automatically swap to a horizontal display to fit the additional variables.
  
      :param df: The DataFrame whose completeness is being dendrogrammed.
      :param method: The distance measure being used for clustering. This is a parameter that is passed to 
      `scipy.hierarchy`.
      :param filter: The filter to apply to the heatmap. Should be one of "top", "bottom", or None (default).
      :param n: The cap on the number of columns to include in the filtered DataFrame.
      :param p: The cap on the percentage fill of the columns in the filtered DataFrame.
      :param sort: The sort to apply to the heatmap. Should be one of "ascending", "descending", or None.
      :param figsize: The size of the figure to display. This is a `matplotlib` parameter which defaults to `(25, 10)`.
      :param fontsize: The figure's font size.
      :param orientation: The way the dendrogram is oriented. Defaults to top-down if there are less than or equal to 50
      columns and left-right if there are more.
      :param inline: Whether or not the figure is inline. If it's not then instead of getting plotted, this method will
      return its figure.
      :return: If `inline` is False, the underlying `matplotlib.figure` object. Else, nothing.
      """; 61, not_operator; 62, block; 63, call; 64, assignment; 65, assignment; 66, assignment; 67, assignment; 68, assignment; 69, assignment; 70, not_operator; 71, block; 72, call; 73, call; 74, call; 75, comparison_operator:orientation == 'bottom'; 76, block; 77, call; 78, call; 79, call; 80, call; 81, call; 82, call; 83, call; 84, comparison_operator:orientation == 'bottom'; 85, block; 86, elif_clause; 87, boolean_operator; 88, block; 89, else_clause; 90, identifier:inline; 91, block; 92, else_clause; 93, string_content:average; 94, identifier:figsize; 95, if_statement; 96, attribute; 97, argument_list; 98, identifier:gs; 99, call; 100, identifier:ax0; 101, call; 102, identifier:df; 103, call; 104, identifier:df; 105, call; 106, identifier:x; 107, call; 108, identifier:z; 109, call; 110, identifier:orientation; 111, if_statement; 112, attribute; 113, argument_list; 114, attribute; 115, argument_list; 116, attribute; 117, argument_list; 118, identifier:orientation; 119, string; 120, expression_statement; 121, attribute; 122, argument_list; 123, attribute; 124, argument_list; 125, attribute; 126, argument_list; 127, attribute; 128, argument_list; 129, attribute; 130, argument_list; 131, attribute; 132, argument_list; 133, attribute; 134, argument_list; 135, identifier:orientation; 136, string; 137, expression_statement; 138, comparison_operator:orientation == 'top'; 139, block; 140, comparison_operator:orientation == 'bottom'; 141, comparison_operator:orientation == 'top'; 142, expression_statement; 143, block; 144, expression_statement; 145, block; 146, boolean_operator; 147, block; 148, else_clause; 149, identifier:plt; 150, identifier:figure; 151, keyword_argument; 152, attribute; 153, argument_list; 154, attribute; 155, argument_list; 156, identifier:nullity_filter; 157, argument_list; 158, identifier:nullity_sort; 159, argument_list; 160, attribute; 161, argument_list; 162, attribute; 163, argument_list; 164, comparison_operator:len(df.columns) > 50; 165, block; 166, else_clause; 167, identifier:hierarchy; 168, identifier:dendrogram; 169, identifier:z; 170, keyword_argument; 171, keyword_argument; 172, keyword_argument; 173, keyword_argument; 174, keyword_argument; 175, keyword_argument; 176, identifier:ax0; 177, identifier:set_aspect; 178, string; 179, identifier:ax0; 180, identifier:grid; 181, keyword_argument; 182, string_content:bottom; 183, call; 184, attribute; 185, identifier:set_ticks_position; 186, string; 187, attribute; 188, identifier:set_ticks_position; 189, string; 190, subscript; 191, identifier:set_visible; 192, False; 193, subscript; 194, identifier:set_visible; 195, False; 196, subscript; 197, identifier:set_visible; 198, False; 199, subscript; 200, identifier:set_visible; 201, False; 202, attribute; 203, identifier:set_visible; 204, False; 205, string_content:bottom; 206, call; 207, identifier:orientation; 208, string; 209, expression_statement; 210, identifier:orientation; 211, string; 212, identifier:orientation; 213, string; 214, call; 215, expression_statement; 216, call; 217, return_statement; 218, boolean_operator; 219, comparison_operator:orientation == 'bottom'; 220, expression_statement; 221, block; 222, identifier:figsize; 223, identifier:figsize; 224, identifier:gridspec; 225, identifier:GridSpec; 226, integer:1; 227, integer:1; 228, identifier:plt; 229, identifier:subplot; 230, subscript; 231, identifier:df; 232, keyword_argument; 233, keyword_argument; 234, keyword_argument; 235, identifier:df; 236, keyword_argument; 237, identifier:np; 238, identifier:transpose; 239, attribute; 240, identifier:hierarchy; 241, identifier:linkage; 242, identifier:x; 243, identifier:method; 244, call; 245, integer:50; 246, expression_statement; 247, block; 248, identifier:orientation; 249, identifier:orientation; 250, identifier:labels; 251, call; 252, identifier:distance_sort; 253, string; 254, identifier:link_color_func; 255, lambda; 256, identifier:leaf_font_size; 257, identifier:fontsize; 258, identifier:ax; 259, identifier:ax0; 260, string_content:auto; 261, identifier:b; 262, False; 263, attribute; 264, argument_list; 265, identifier:ax0; 266, identifier:xaxis; 267, string_content:none; 268, identifier:ax0; 269, identifier:yaxis; 270, string_content:none; 271, attribute; 272, string; 273, attribute; 274, string; 275, attribute; 276, string; 277, attribute; 278, string; 279, identifier:ax0; 280, identifier:patch; 281, attribute; 282, argument_list; 283, string_content:top; 284, call; 285, string_content:bottom; 286, string_content:top; 287, attribute; 288, argument_list; 289, call; 290, attribute; 291, argument_list; 292, identifier:ax0; 293, comparison_operator:len(df.columns) <= 50; 294, comparison_operator:orientation == 'top'; 295, identifier:orientation; 296, string; 297, assignment; 298, expression_statement; 299, identifier:gs; 300, integer:0; 301, identifier:filter; 302, identifier:filter; 303, identifier:n; 304, identifier:n; 305, identifier:p; 306, identifier:p; 307, identifier:sort; 308, identifier:sort; 309, call; 310, identifier:values; 311, identifier:len; 312, argument_list; 313, assignment; 314, expression_statement; 315, attribute; 316, argument_list; 317, string_content:descending; 318, lambda_parameters; 319, string; 320, attribute; 321, identifier:tick_top; 322, identifier:ax0; 323, identifier:spines; 324, string_content:top; 325, identifier:ax0; 326, identifier:spines; 327, string_content:right; 328, identifier:ax0; 329, identifier:spines; 330, string_content:bottom; 331, identifier:ax0; 332, identifier:spines; 333, string_content:left; 334, identifier:ax0; 335, identifier:set_xticklabels; 336, call; 337, keyword_argument; 338, keyword_argument; 339, attribute; 340, argument_list; 341, identifier:ax0; 342, identifier:tick_params; 343, keyword_argument; 344, keyword_argument; 345, attribute; 346, argument_list; 347, identifier:plt; 348, identifier:show; 349, call; 350, integer:50; 351, identifier:orientation; 352, string; 353, string_content:bottom; 354, identifier:figsize; 355, tuple; 356, assignment; 357, attribute; 358, argument_list; 359, attribute; 360, identifier:orientation; 361, string; 362, assignment; 363, attribute; 364, identifier:tolist; 365, identifier:c; 366, string_content:black; 367, identifier:ax0; 368, identifier:xaxis; 369, attribute; 370, argument_list; 371, identifier:rotation; 372, integer:45; 373, identifier:ha; 374, string; 375, identifier:ax0; 376, identifier:set_xticklabels; 377, call; 378, keyword_argument; 379, keyword_argument; 380, identifier:axis; 381, string; 382, identifier:labelsize; 383, call; 384, identifier:ax0; 385, identifier:tick_params; 386, keyword_argument; 387, keyword_argument; 388, identifier:len; 389, argument_list; 390, string_content:top; 391, integer:25; 392, integer:10; 393, identifier:figsize; 394, tuple; 395, call; 396, identifier:astype; 397, identifier:int; 398, identifier:df; 399, identifier:columns; 400, string_content:left; 401, identifier:orientation; 402, string; 403, identifier:df; 404, identifier:columns; 405, attribute; 406, identifier:get_majorticklabels; 407, string_content:left; 408, attribute; 409, argument_list; 410, identifier:rotation; 411, integer:45; 412, identifier:ha; 413, string; 414, string_content:y; 415, identifier:int; 416, argument_list; 417, identifier:axis; 418, string; 419, identifier:labelsize; 420, call; 421, attribute; 422, integer:25; 423, binary_operator:(25 + len(df.columns) - 50)*0.5; 424, attribute; 425, argument_list; 426, string_content:bottom; 427, identifier:ax0; 428, identifier:xaxis; 429, attribute; 430, identifier:get_majorticklabels; 431, string_content:right; 432, binary_operator:fontsize / 16 * 20; 433, string_content:x; 434, identifier:int; 435, argument_list; 436, identifier:df; 437, identifier:columns; 438, parenthesized_expression; 439, float:0.5; 440, identifier:df; 441, identifier:isnull; 442, identifier:ax0; 443, identifier:xaxis; 444, binary_operator:fontsize / 16; 445, integer:20; 446, binary_operator:fontsize / 16 * 20; 447, binary_operator:25 + len(df.columns) - 50; 448, identifier:fontsize; 449, integer:16; 450, binary_operator:fontsize / 16; 451, integer:20; 452, binary_operator:25 + len(df.columns); 453, integer:50; 454, identifier:fontsize; 455, integer:16; 456, integer:25; 457, call; 458, identifier:len; 459, argument_list; 460, attribute; 461, identifier:df; 462, identifier:columns
code: def dendrogram(df, method='average',
                 filter=None, n=0, p=0, sort=None,
                 orientation=None, figsize=None,
                 fontsize=16, inline=False
                 ):
      """
      Fits a `scipy` hierarchical clustering algorithm to the given DataFrame's variables and visualizes the results as
      a `scipy` dendrogram.
      
      The default vertical display will fit up to 50 columns. If more than 50 columns are specified and orientation is
      left unspecified the dendrogram will automatically swap to a horizontal display to fit the additional variables.
  
      :param df: The DataFrame whose completeness is being dendrogrammed.
      :param method: The distance measure being used for clustering. This is a parameter that is passed to 
      `scipy.hierarchy`.
      :param filter: The filter to apply to the heatmap. Should be one of "top", "bottom", or None (default).
      :param n: The cap on the number of columns to include in the filtered DataFrame.
      :param p: The cap on the percentage fill of the columns in the filtered DataFrame.
      :param sort: The sort to apply to the heatmap. Should be one of "ascending", "descending", or None.
      :param figsize: The size of the figure to display. This is a `matplotlib` parameter which defaults to `(25, 10)`.
      :param fontsize: The figure's font size.
      :param orientation: The way the dendrogram is oriented. Defaults to top-down if there are less than or equal to 50
      columns and left-right if there are more.
      :param inline: Whether or not the figure is inline. If it's not then instead of getting plotted, this method will
      return its figure.
      :return: If `inline` is False, the underlying `matplotlib.figure` object. Else, nothing.
      """
      if not figsize:
          if len(df.columns) <= 50 or orientation == 'top' or orientation == 'bottom':
              figsize = (25, 10)
          else:
              figsize = (25, (25 + len(df.columns) - 50)*0.5)
      
      plt.figure(figsize=figsize)
      gs = gridspec.GridSpec(1, 1)
      ax0 = plt.subplot(gs[0])
  
      df = nullity_filter(df, filter=filter, n=n, p=p)
      df = nullity_sort(df, sort=sort)
  
      # Link the hierarchical output matrix, figure out orientation, construct base dendrogram.
      x = np.transpose(df.isnull().astype(int).values)
      z = hierarchy.linkage(x, method)
  
      if not orientation:
          if len(df.columns) > 50:
              orientation = 'left'
          else:
              orientation = 'bottom'
  
      hierarchy.dendrogram(z,
                           orientation=orientation,
                           labels=df.columns.tolist(),
                           distance_sort='descending',
                           link_color_func=lambda c: 'black',
                           leaf_font_size=fontsize,
                           ax=ax0
                          )
  
      # Remove extraneous default visual elements.
      ax0.set_aspect('auto')
      ax0.grid(b=False)
      if orientation == 'bottom':
          ax0.xaxis.tick_top()
      ax0.xaxis.set_ticks_position('none')
      ax0.yaxis.set_ticks_position('none')
      ax0.spines['top'].set_visible(False)
      ax0.spines['right'].set_visible(False)
      ax0.spines['bottom'].set_visible(False)
      ax0.spines['left'].set_visible(False)
      ax0.patch.set_visible(False)
  
      # Set up the categorical axis labels and draw.
      if orientation == 'bottom':
          ax0.set_xticklabels(ax0.xaxis.get_majorticklabels(), rotation=45, ha='left')
      elif orientation == 'top':
          ax0.set_xticklabels(ax0.xaxis.get_majorticklabels(), rotation=45, ha='right')
      if orientation == 'bottom' or orientation == 'top':
          ax0.tick_params(axis='y', labelsize=int(fontsize / 16 * 20))
      else:
          ax0.tick_params(axis='x', labelsize=int(fontsize / 16 * 20))
  
      if inline:
          plt.show()
      else:
          return ax0