#NEWLINE# def _create_labels( rects , horizontal , ax , rotation ) : #NEWLINE# #INDENT# 'find the position of the label for each value of each category\n\n    right now it supports only up to the four categories\n\n    ax: the axis on which the label should be applied\n    rotation: the rotation list for each side\n    ' #NEWLINE# categories = _categories_level ( list ( iterkeys ( rects ) ) ) #NEWLINE# if ( len ( categories ) > 4 ) : #NEWLINE# #INDENT# msg = 'maximum of 4 level supported for axes labeling..and 4is alreay a lot of level, are you sure you need them all?' #NEWLINE# raise NotImplementedError ( msg ) #NEWLINE# #UNINDENT# labels = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# items = list ( iteritems ( rects ) ) #NEWLINE# vertical = ( not horizontal ) #NEWLINE# ax2 = ax . twinx ( ) #NEWLINE# ax3 = ax . twiny ( ) #NEWLINE# ticks_pos = [ ax . set_xticks , ax . set_yticks , ax3 . set_xticks , ax2 . set_yticks ] #NEWLINE# ticks_lab = [ ax . set_xticklabels , ax . set_yticklabels , ax3 . set_xticklabels , ax2 . set_yticklabels ] #NEWLINE# if vertical : #NEWLINE# #INDENT# ticks_pos = ( ticks_pos [ 1 : ] + ticks_pos [ : 1 ] ) #NEWLINE# ticks_lab = ( ticks_lab [ 1 : ] + ticks_lab [ : 1 ] ) #NEWLINE# #UNINDENT# for ( pos , lab ) in zip ( ticks_pos , ticks_lab ) : #NEWLINE# #INDENT# pos ( [ ] ) #NEWLINE# lab ( [ ] ) #NEWLINE# #UNINDENT# for ( level_idx , level ) in enumerate ( categories ) : #NEWLINE# #INDENT# level_ticks = dict ( ) #NEWLINE# for value in level : #NEWLINE# #INDENT# if horizontal : #NEWLINE# #INDENT# if ( level_idx == 3 ) : #NEWLINE# #INDENT# index_select = [ ( - 1 ) , ( - 1 ) , ( - 1 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# index_select = [ ( + 0 ) , ( - 1 ) , ( - 1 ) ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( level_idx == 3 ) : #NEWLINE# #INDENT# index_select = [ ( + 0 ) , ( - 1 ) , ( + 0 ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# index_select = [ ( - 1 ) , ( - 1 ) , ( - 1 ) ] #NEWLINE# #UNINDENT# #UNINDENT# basekey = tuple ( ( categories [ i ] [ index_select [ i ] ] for i in range ( level_idx ) ) ) #NEWLINE# basekey = ( basekey + ( value , ) ) #NEWLINE# subset = dict ( ( ( k , v ) for ( k , v ) in items if ( basekey == k [ : ( level_idx + 1 ) ] ) ) ) #NEWLINE# vals = list ( itervalues ( subset ) ) #NEWLINE# W = sum ( ( ( w * h ) for ( x , y , w , h ) in vals ) ) #NEWLINE# x_lab = sum ( ( _get_position ( x , w , h , W ) for ( x , y , w , h ) in vals ) ) #NEWLINE# y_lab = sum ( ( _get_position ( y , h , w , W ) for ( x , y , w , h ) in vals ) ) #NEWLINE# side = ( ( level_idx + vertical ) % 4 ) #NEWLINE# level_ticks [ value ] = ( y_lab if ( side % 2 ) else x_lab ) #NEWLINE# #UNINDENT# ticks_pos [ level_idx ] ( list ( itervalues ( level_ticks ) ) ) #NEWLINE# ticks_lab [ level_idx ] ( list ( iterkeys ( level_ticks ) ) , rotation = rotation [ level_idx ] ) #NEWLINE# #UNINDENT# return labels