def plot( self, font_fname=None ) : plt = Gnuplot() plt.open() plt.xlabel( "Time (s)" ) plt.ylabel( "$$$ spent (estimate)" ) plt.set_style( "linespoints" ) plots = [] labels = [] for i in range( self.nplayers ) : player = self.kwr.players[i] if not player.is_player() : continue pair = self.split( self.spents[ i ] ) if not pair : continue ts, costs = pair plt.plot( ts, costs ) labels.append( sanitize_name( player, xor=True ) ) plt.legend( labels ) plt.show() plt.close()
def plot_unit_distribution( self ) : color = 1 for i in range( self.nplayers ) : player = self.kwr.players[i] if not player.is_player() : continue plt = Gnuplot() plt.open() histo = self.units[ i ] plt.write( 'set style fill solid\n' ) plt.write( 'set key off\n' ) plt.write( 'set boxwidth 0.5\n' ) plt.write( 'set title "%s"\n' % sanitize_name( player ) ) n_kinds = len( histo ) plt.write( 'set xrange[-1:%d]\n' % n_kinds ) # set X tics, 45 degress rotated. cmd = "set xtics (" i = 0 items = [] for unit, cnt in histo.items() : items.append( '"%s" %d' % ( unit, i ) ) i += 1 cmd += ", ".join( items ) cmd += ") rotate by 45 right\n" plt.write( cmd ) # write values on the graph (labels) #i = 0 #for unit, cnt in histo.items() : # cmd = 'set label "%d" at %d,%d\n' % ( cnt, i, cnt+5 ) # plt.write( cmd ) # i += 1 # y range, manually. max_cnt = 0 for unit, cnt in histo.items() : max_cnt = max( max_cnt, cnt ) print( max_cnt ) plt.write( "set yrange [0:%f]\n" % ( 1.2*max_cnt ) ) # feed data cmd = 'plot "-" using 0:1 with boxes linecolor %s, ' % color cmd += "'-' using 0:1:1 with labels offset 0, 1\n" plt.write( cmd ) for unit, cnt in histo.items() : plt.write( str(cnt) + "\n" ) plt.write( 'e\n' ) for unit, cnt in histo.items() : plt.write( str(cnt) + "\n" ) plt.write( 'e\n' ) color += 1 plt.close()
def plot( self, interval, font_fname=None ) : plt = Gnuplot() plt.open() cmds_at_second = self.group_commands_by_time() counts_at_second = self.count_player_actions( interval, cmds_at_second ) # actions counted for that second... ts = [ t for t in range( len( counts_at_second ) ) ] apmss = self.make_apmss( interval, counts_at_second ) #apmss[pid][t] = apm at time t, of player pid. plt.xlabel( "Time (s)" ) plt.ylabel( "APM" ) labels = [] for i in range( self.nplayers ) : player = self.kwr.players[i] if not player.is_player() : continue plt.plot( ts, apmss[ i ] ) name = sanitize_name( player, xor=True ) labels.append( name ) # touch up label of the curve # draw legend plt.legend( labels ) avg_apms = self.calc_avg_apm( cmds_at_second ) avg_apm_texts = self.avg_apm2txts( avg_apms ) # draw peak arrow. self.draw_peak_labels( plt, apmss ) # now the plot begins. plt.write( 'plot \\\n' ) # begin the plot command. color = 1 for pid in range( self.nplayers ) : player = self.kwr.players[pid] if not player.is_player() : continue #name = sanitize_name( player, xor=True ) #print( name, avg_apms[ pid ] ) plt.write( "%f title \"%s\" linecolor %d linetype 0 linewidth 2, \\\n" % ( avg_apms[ pid ], avg_apm_texts[pid], color ) ) color += 1 plt.data_plot_command() # plot apm(player, t) data. plt.close()