<s> import numpy as np <EOL> def gen_colors ( clusters ) : <EOL> """<STR_LIT>""" <EOL> import matplotlib . cm as cm <EOL> n = len ( set ( clusters ) ) <EOL> colorm = [ cm . hsv ( i * <NUM_LIT:1.0> / n , <NUM_LIT:1> ) for i in xrange ( n ) ] <EOL> return colorm <EOL> def plot_clusters ( arr , labels , clusters = [ ] , size = [ ] ) : <EOL> """<STR_LIT>""" <EOL> import matplotlib . pyplot as plt <EOL> n = arr . shape [ <NUM_LIT:0> ] <EOL> X = arr [ : , <NUM_LIT:0> ] <EOL> Y = arr [ : , <NUM_LIT:1> ] <EOL> if len ( size ) == <NUM_LIT:0> : <EOL> size = [ <NUM_LIT> for i in xrange ( n ) ] <EOL> fig = plt . figure ( figsize = ( <NUM_LIT:10> , <NUM_LIT:10> ) ) <EOL> ax = plt . subplot ( <NUM_LIT> ) <EOL> if len ( clusters ) == <NUM_LIT:0> : <EOL> plt . scatter ( X , Y , size ) <EOL> else : <EOL> colors = gen_colors ( clusters ) <EOL> colors = [ colors [ i ] for i in clusters ] <EOL> for i in xrange ( n ) : <EOL> plt . scatter ( X [ i ] , Y [ i ] , size , color = colors [ i ] ) <EOL> ax . set_xlim ( np . min ( X ) - <NUM_LIT> , np . max ( X ) + <NUM_LIT> ) <EOL> ax . set_ylim ( np . min ( Y ) - <NUM_LIT> , np . max ( Y ) + <NUM_LIT> ) <EOL> ax . set_xticks ( [ ] ) <EOL> ax . set_yticks ( [ ] ) <EOL> for label , x , y in zip ( labels , X , Y ) : <EOL> plt . annotate ( label , xy = ( x , y ) , xytext = ( - <NUM_LIT:2> , <NUM_LIT:3> ) , <EOL> textcoords = '<STR_LIT>' , fontsize = <NUM_LIT:10> ) <EOL> plt . show ( ) </s>
