<s> import sys <EOL> import json <EOL> from pyproct . tools . commonTools import convert_to_utf8 <EOL> from pyproct . clustering . clustering import Clustering <EOL> import matplotlib . cm as cm <EOL> import numpy as np <EOL> import matplotlib . pyplot as plt <EOL> from matplotlib . path import Path <EOL> from matplotlib . spines import Spine <EOL> from matplotlib . projections . polar import PolarAxes <EOL> from matplotlib . projections import register_projection <EOL> N = <NUM_LIT:9> <EOL> def unit_poly_verts ( theta ) : <EOL> """<STR_LIT>""" <EOL> x0 , y0 , r = [ <NUM_LIT:0.5> ] * <NUM_LIT:3> <EOL> verts = [ ( r * np . cos ( t ) + x0 , r * np . sin ( t ) + y0 ) for t in theta ] <EOL> return verts <EOL> def radar_factory ( num_vars , frame = '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> theta = <NUM_LIT:2> * np . pi * np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> - <NUM_LIT:1.> / num_vars , num_vars ) <EOL> theta += np . pi / <NUM_LIT:2> <EOL> def draw_poly_patch ( self ) : <EOL> verts = unit_poly_verts ( theta ) <EOL> return plt . Polygon ( verts , closed = True , edgecolor = '<STR_LIT:k>' ) <EOL> def draw_circle_patch ( self ) : <EOL> return plt . Circle ( ( <NUM_LIT:0.5> , <NUM_LIT:0.5> ) , <NUM_LIT:0.5> ) <EOL> patch_dict = { '<STR_LIT>' : draw_poly_patch , '<STR_LIT>' : draw_circle_patch } <EOL> if frame not in patch_dict : <EOL> raise ValueError ( '<STR_LIT>' % frame ) <EOL> class RadarAxes ( PolarAxes ) : <EOL> name = '<STR_LIT>' <EOL> RESOLUTION = <NUM_LIT:1> <EOL> draw_patch = patch_dict [ frame ] <EOL> def fill ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> closed = kwargs . pop ( '<STR_LIT>' , True ) <EOL> return super ( RadarAxes , self ) . fill ( closed = closed , * args , ** kwargs ) <EOL> def plot ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> lines = super ( RadarAxes , self ) . plot ( * args , ** kwargs ) <EOL> for line in lines : <EOL> self . _close_line ( line ) <EOL> def _close_line ( self , line ) : <EOL> x , y = line . get_data ( ) <EOL> if x [ <NUM_LIT:0> ] != x [ - <NUM_LIT:1> ] : <EOL> x = np . concatenate ( ( x , [ x [ <NUM_LIT:0> ] ] ) ) <EOL> y = np . concatenate ( ( y , [ y [ <NUM_LIT:0> ] ] ) ) <EOL> line . set_data ( x , y ) <EOL> def set_varlabels ( self , labels ) : <EOL> self . set_thetagrids ( theta * <NUM_LIT> / np . pi , labels ) <EOL> def _gen_axes_patch ( self ) : <EOL> return self . draw_patch ( ) <EOL> def _gen_axes_spines ( self ) : <EOL> if frame == '<STR_LIT>' : <EOL> return PolarAxes . _gen_axes_spines ( self ) <EOL> spine_type = '<STR_LIT>' <EOL> verts = unit_poly_verts ( theta ) <EOL> verts . append ( verts [ <NUM_LIT:0> ] ) <EOL> path = Path ( verts ) <EOL> spine = Spine ( self , spine_type , path ) <EOL> spine . set_transform ( self . transAxes ) <EOL> return { '<STR_LIT>' : spine } <EOL> register_projection ( RadarAxes ) <EOL> return theta <EOL> def gen_data ( cluster , index_to_interpolation ) : <EOL> cluster . percents = { } <EOL> for element in cluster . all_elements : <EOL> try : <EOL> cluster . percents [ index_to_interpolation [ element ] ] += <NUM_LIT:1> <EOL> a , b = index_to_interpolation [ element ] <EOL> cluster . percents [ ( b , a ) ] += <NUM_LIT:1> <EOL> except KeyError : <EOL> cluster . percents [ index_to_interpolation [ element ] ] = <NUM_LIT:1> <EOL> a , b = index_to_interpolation [ element ] <EOL> cluster . percents [ ( b , a ) ] = <NUM_LIT:1> <EOL> for percent in cluster . percents : <EOL> cluster . percents [ percent ] /= <NUM_LIT> <EOL> data = { } <EOL> data [ "<STR_LIT>" ] = [ str ( x ) for x in range ( N ) ] <EOL> for i in range ( <NUM_LIT:0> , N ) : <EOL> data [ str ( i ) ] = [ ] <EOL> for j in range ( <NUM_LIT:0> , N ) : <EOL> if ( i , j ) in cluster . percents : <EOL> data [ str ( i ) ] . append ( cluster . percents [ ( i , j ) ] ) <EOL> else : <EOL> data [ str ( i ) ] . append ( <NUM_LIT:0> ) <EOL> return data <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> results = convert_to_utf8 ( json . loads ( open ( sys . argv [ <NUM_LIT:1> ] ) . read ( ) ) ) <EOL> best_clustering_id = results [ "<STR_LIT>" ] <EOL> best_clustering_dic = results [ "<STR_LIT>" ] [ best_clustering_id ] <EOL> num_clusters = best_clustering_dic [ "<STR_LIT>" ] [ "<STR_LIT>" ] <EOL> clustering = Clustering . from_dic ( best_clustering_dic [ "<STR_LIT>" ] ) <EOL> file_frames = int ( sys . argv [ <NUM_LIT:2> ] ) <EOL> index_to_interpolation = { } <EOL> acc = <NUM_LIT:0> <EOL> for i in range ( <NUM_LIT:0> , file_frames - <NUM_LIT:1> ) : <EOL> for j in range ( i + <NUM_LIT:1> , file_frames ) : <EOL> for k in range ( <NUM_LIT:20> ) : <EOL> index_to_interpolation [ acc ] = ( i , j ) <EOL> acc += <NUM_LIT:1> <EOL> for cluster in clustering . clusters : <EOL> colors = iter ( cm . rainbow ( np . linspace ( <NUM_LIT:0> , <NUM_LIT:1> , N ) ) ) <EOL> theta = radar_factory ( N , frame = '<STR_LIT>' ) <EOL> data = gen_data ( cluster , index_to_interpolation ) <EOL> spoke_labels = data . pop ( '<STR_LIT>' ) <EOL> fig = plt . figure ( figsize = ( <NUM_LIT:9> , <NUM_LIT:9> ) ) <EOL> fig . subplots_adjust ( wspace = <NUM_LIT> , hspace = <NUM_LIT> , top = <NUM_LIT> , bottom = <NUM_LIT> ) <EOL> for n , title in enumerate ( data . keys ( ) ) : <EOL> ax = fig . add_subplot ( <NUM_LIT:3> , <NUM_LIT:3> , n + <NUM_LIT:1> , projection = '<STR_LIT>' ) <EOL> ax . set_rmax ( <NUM_LIT:1.> ) <EOL> ax . autoscale ( False ) <EOL> plt . rgrids ( [ <NUM_LIT:0.5> ] ) <EOL> ax . set_title ( title , weight = '<STR_LIT>' , size = '<STR_LIT>' , position = ( <NUM_LIT:0.5> , <NUM_LIT> ) , <EOL> horizontalalignment = '<STR_LIT>' , verticalalignment = '<STR_LIT>' ) <EOL> color = next ( colors ) <EOL> sorted_data_indices = np . argsort ( data [ title ] ) <EOL> sorted_data = np . array ( data [ title ] ) [ sorted_data_indices ] <EOL> sorted_labels = np . array ( spoke_labels ) [ sorted_data_indices ] <EOL> ax . plot ( theta , sorted_data , color = '<STR_LIT:k>' ) <EOL> ax . fill ( theta , sorted_data , facecolor = color , alpha = <NUM_LIT> ) <EOL> ax . set_varlabels ( sorted_labels ) <EOL> plt . figtext ( <NUM_LIT:0.5> , <NUM_LIT> , cluster . id , ha = '<STR_LIT>' , color = '<STR_LIT>' , weight = '<STR_LIT>' , size = '<STR_LIT>' ) <EOL> plt . show ( ) </s>
