nodes: 0, module; 1, function_definition; 2, function_name:color_table; 3, parameters; 4, block; 5, identifier:color; 6, default_parameter; 7, default_parameter; 8, default_parameter; 9, default_parameter; 10, default_parameter; 11, expression_statement; 12, if_statement; 13, function_definition; 14, expression_statement; 15, for_statement; 16, expression_statement; 17, if_statement; 18, return_statement; 19, identifier:N; 20, integer:1; 21, identifier:sort; 22, False; 23, identifier:sort_values; 24, False; 25, identifier:inline; 26, False; 27, identifier:as_html; 28, False; 29, comment:"""
      Generates a colour table 
  
      Parameters:
      -----------
              color : string | list | dict
                      Color representation in rgba|rgb|hex
                      If a list of colors is passed then these
                      are displayed in a table
              N   : int
                      number of colours to generate
                      When color is not a list then it generaes 
                      a range of N colors
              sort : bool 
                      if True then items are sorted
              sort_values : bool 
                      if True then items are sorted by color values.
                      Only applies if color is a dictionary
              inline : bool
                      if True it returns single line color blocks
              as_html : bool
                      if True it returns the HTML code
  
      Example:
              color_table('#ff9933')
              color_table(cufflinks.cnames)
              color_table(['pink','salmon','yellow'])
      Note:
              This function only works in iPython Notebook
      """; 30, call; 31, block; 32, elif_clause; 33, else_clause; 34, function_name:_color; 35, parameters; 36, block; 37, assignment; 38, identifier:c; 39, identifier:rgb_tup; 40, block; 41, augmented_assignment; 42, identifier:as_html; 43, block; 44, call; 45, identifier:isinstance; 46, argument_list; 47, expression_statement; 48, expression_statement; 49, if_statement; 50, call; 51, block; 52, block; 53, identifier:c; 54, if_statement; 55, if_statement; 56, return_statement; 57, identifier:s; 58, conditional_expression:'<ul style="list-style-type: none;">' if not inline else ''; 59, if_statement; 60, if_statement; 61, identifier:s; 62, conditional_expression:'</ul>' if not inline else ''; 63, return_statement; 64, identifier:display; 65, argument_list; 66, identifier:color; 67, identifier:list; 68, assignment; 69, assignment; 70, identifier:sort; 71, block; 72, identifier:isinstance; 73, argument_list; 74, expression_statement; 75, expression_statement; 76, if_statement; 77, expression_statement; 78, expression_statement; 79, if_statement; 80, comparison_operator:hex_to_hsv(c)[2] < .5; 81, block; 82, else_clause; 83, comparison_operator:c == c_; 84, block; 85, else_clause; 86, expression_list; 87, string:'<ul style="list-style-type: none;">'; 88, not_operator; 89, string; 90, call; 91, block; 92, else_clause; 93, identifier:inline; 94, block; 95, else_clause; 96, string; 97, not_operator; 98, string; 99, identifier:s; 100, call; 101, identifier:c_; 102, string; 103, identifier:rgb_tup; 104, list_comprehension; 105, expression_statement; 106, identifier:color; 107, identifier:dict; 108, assignment; 109, assignment; 110, identifier:sort_values; 111, block; 112, elif_clause; 113, assignment; 114, assignment; 115, comparison_operator:N > 1; 116, block; 117, else_clause; 118, subscript; 119, float:.5; 120, expression_statement; 121, expression_statement; 122, block; 123, identifier:c; 124, identifier:c_; 125, expression_statement; 126, block; 127, identifier:color; 128, identifier:shadow; 129, identifier:border; 130, identifier:inline; 131, identifier:isinstance; 132, argument_list; 133, expression_statement; 134, expression_statement; 135, block; 136, expression_statement; 137, block; 138, string_content:</ul>; 139, identifier:inline; 140, identifier:HTML; 141, argument_list; 142, call; 143, for_in_clause; 144, call; 145, identifier:c_; 146, string; 147, identifier:items; 148, list_comprehension; 149, expression_statement; 150, identifier:sort; 151, block; 152, identifier:rgb_tup; 153, list_comprehension; 154, identifier:c_; 155, call; 156, identifier:N; 157, integer:1; 158, expression_statement; 159, block; 160, call; 161, integer:2; 162, assignment; 163, assignment; 164, expression_statement; 165, expression_statement; 166, assignment; 167, expression_statement; 168, identifier:c; 169, identifier:tuple; 170, assignment; 171, augmented_assignment; 172, expression_statement; 173, augmented_assignment; 174, expression_statement; 175, expression_statement; 176, identifier:s; 177, identifier:normalize; 178, argument_list; 179, identifier:c; 180, identifier:color; 181, attribute; 182, argument_list; 183, tuple; 184, for_in_clause; 185, assignment; 186, expression_statement; 187, tuple; 188, for_in_clause; 189, identifier:normalize; 190, argument_list; 191, assignment; 192, expression_statement; 193, identifier:hex_to_hsv; 194, argument_list; 195, identifier:color; 196, string:"#ffffff"; 197, identifier:shadow; 198, string; 199, assignment; 200, assignment; 201, identifier:border; 202, string:" border: 1px solid #ffffff;"; 203, assignment; 204, pattern_list; 205, identifier:c; 206, identifier:k; 207, string; 208, assignment; 209, identifier:s; 210, call; 211, assignment; 212, augmented_assignment; 213, identifier:c; 214, identifier:rgb_tup; 215, identifier:sort; 216, identifier:k; 217, call; 218, call; 219, pattern_list; 220, call; 221, identifier:items; 222, call; 223, assignment; 224, identifier:k; 225, identifier:v; 226, pattern_list; 227, identifier:items; 228, identifier:color; 229, identifier:rgb_tup; 230, subscript; 231, assignment; 232, identifier:c; 233, string_content:0 1px 0 #000; 234, identifier:color; 235, string:"#000000"; 236, identifier:shadow; 237, string; 238, identifier:border; 239, string; 240, identifier:k; 241, identifier:c; 242, string_content::; 243, identifier:k; 244, string; 245, attribute; 246, argument_list; 247, pattern_list; 248, call; 249, identifier:s; 250, binary_operator:"""<li style="text-align:center;""" + border + """line-height:30px;background-color:""" + c + """;"> 
              <span style=" text-shadow:""" + shadow + """; color:""" + color + """;">""" + k + c.upper() + """</span>
              </li>"""; 251, identifier:normalize; 252, argument_list; 253, identifier:hex_to_hsv; 254, argument_list; 255, identifier:k; 256, identifier:v; 257, identifier:list; 258, argument_list; 259, identifier:sorted; 260, argument_list; 261, identifier:items; 262, call; 263, identifier:k; 264, identifier:v; 265, identifier:_; 266, call; 267, slice; 268, identifier:rgb_tup; 269, list; 270, string_content:0 1px 0 rgba(255,255,255,0.6); 271, string:'<div style="background-color:{0};height:20px;width:20px;display:inline-block;"></div>'; 272, identifier:format; 273, identifier:c; 274, identifier:color; 275, identifier:shadow; 276, identifier:border; 277, identifier:_color; 278, argument_list; 279, binary_operator:"""<li style="text-align:center;""" + border + """line-height:30px;background-color:""" + c + """;"> 
              <span style=" text-shadow:""" + shadow + """; color:""" + color + """;">""" + k + c.upper(); 280, comment:"""</span>
              </li>"""; 281, identifier:v; 282, call; 283, call; 284, identifier:items; 285, keyword_argument; 286, identifier:sorted; 287, argument_list; 288, attribute; 289, argument_list; 290, unary_operator; 291, identifier:c_; 292, identifier:c; 293, binary_operator:"""<li style="text-align:center;""" + border + """line-height:30px;background-color:""" + c + """;"> 
              <span style=" text-shadow:""" + shadow + """; color:""" + color + """;">""" + k; 294, call; 295, identifier:normalize; 296, argument_list; 297, attribute; 298, argument_list; 299, identifier:key; 300, call; 301, identifier:items; 302, keyword_argument; 303, identifier:np; 304, identifier:array; 305, call; 306, integer:1; 307, binary_operator:"""<li style="text-align:center;""" + border + """line-height:30px;background-color:""" + c + """;"> 
              <span style=" text-shadow:""" + shadow + """; color:""" + color + """;">"""; 308, identifier:k; 309, attribute; 310, argument_list; 311, identifier:v; 312, identifier:color; 313, identifier:items; 314, attribute; 315, argument_list; 316, identifier:key; 317, call; 318, identifier:color_range; 319, argument_list; 320, binary_operator:"""<li style="text-align:center;""" + border + """line-height:30px;background-color:""" + c + """;"> 
              <span style=" text-shadow:""" + shadow + """; color:""" + color; 321, comment:""";">"""; 322, identifier:c; 323, identifier:upper; 324, identifier:operator; 325, identifier:itemgetter; 326, integer:2; 327, attribute; 328, argument_list; 329, identifier:c_; 330, identifier:N; 331, binary_operator:"""<li style="text-align:center;""" + border + """line-height:30px;background-color:""" + c + """;"> 
              <span style=" text-shadow:""" + shadow + """; color:"""; 332, identifier:color; 333, identifier:operator; 334, identifier:itemgetter; 335, integer:0; 336, binary_operator:"""<li style="text-align:center;""" + border + """line-height:30px;background-color:""" + c + """;"> 
              <span style=" text-shadow:""" + shadow; 337, comment:"""; color:"""; 338, binary_operator:"""<li style="text-align:center;""" + border + """line-height:30px;background-color:""" + c + """;"> 
              <span style=" text-shadow:"""; 339, identifier:shadow; 340, binary_operator:"""<li style="text-align:center;""" + border + """line-height:30px;background-color:""" + c; 341, comment:""";"> 
              <span style=" text-shadow:"""; 342, binary_operator:"""<li style="text-align:center;""" + border + """line-height:30px;background-color:"""; 343, identifier:c; 344, binary_operator:"""<li style="text-align:center;""" + border; 345, comment:"""line-height:30px;background-color:"""; 346, comment:"""<li style="text-align:center;"""; 347, identifier:border
code: def color_table(color, N=1, sort=False, sort_values=False, inline=False, as_html=False):
      """
      Generates a colour table 
  
      Parameters:
      -----------
              color : string | list | dict
                      Color representation in rgba|rgb|hex
                      If a list of colors is passed then these
                      are displayed in a table
              N   : int
                      number of colours to generate
                      When color is not a list then it generaes 
                      a range of N colors
              sort : bool 
                      if True then items are sorted
              sort_values : bool 
                      if True then items are sorted by color values.
                      Only applies if color is a dictionary
              inline : bool
                      if True it returns single line color blocks
              as_html : bool
                      if True it returns the HTML code
  
      Example:
              color_table('#ff9933')
              color_table(cufflinks.cnames)
              color_table(['pink','salmon','yellow'])
      Note:
              This function only works in iPython Notebook
      """
      if isinstance(color, list):
          c_ = ''
          rgb_tup = [normalize(c) for c in color]
          if sort:
              rgb_tup.sort()
      elif isinstance(color, dict):
          c_ = ''
          items = [(k, normalize(v), hex_to_hsv(normalize(v)))
                   for k, v in list(color.items())]
          if sort_values:
              items = sorted(items, key=operator.itemgetter(2))
          elif sort:
              items = sorted(items, key=operator.itemgetter(0))
          rgb_tup = [(k, v) for k, v, _ in items]
      else:
          c_ = normalize(color)
          if N > 1:
              rgb_tup = np.array(color_range(c_, N))[::-1]
          else:
              rgb_tup = [c_]
  
      def _color(c):
          if hex_to_hsv(c)[2] < .5:
              color = "#ffffff"
              shadow = '0 1px 0 #000'
          else:
              color = "#000000"
              shadow = '0 1px 0 rgba(255,255,255,0.6)'
          if c == c_:
              border = " border: 1px solid #ffffff;"
          else:
              border = ''
          return color, shadow, border
  
      s = '<ul style="list-style-type: none;">' if not inline else ''
      for c in rgb_tup:
          if isinstance(c, tuple):
              k, c = c
              k += ' : '
          else:
              k = ''
          if inline:
              s += '<div style="background-color:{0};height:20px;width:20px;display:inline-block;"></div>'.format(
                  c)
          else:
              color, shadow, border = _color(c)
              s += """<li style="text-align:center;""" + border + """line-height:30px;background-color:""" + c + """;"> 
              <span style=" text-shadow:""" + shadow + """; color:""" + color + """;">""" + k + c.upper() + """</span>
              </li>"""
      s += '</ul>' if not inline else ''
      if as_html:
          return s
      return display(HTML(s))