#NEWLINE# def render( self , fig = None ) : #NEWLINE# #INDENT# 'Render all the layers on a matplotlib figure.\n\n        Parameters:\n        -----------\n        fig: matplotlib figure\n        ' #NEWLINE# import matplotlib.pyplot as plt #NEWLINE# if ( fig is None ) : #NEWLINE# #INDENT# fig = plt . gcf ( ) #NEWLINE# #UNINDENT# last_trellis = None #NEWLINE# for layer in self . layers : #NEWLINE# #INDENT# if isinstance ( layer , TrellisGrid ) : #NEWLINE# #INDENT# last_trellis = layer #NEWLINE# #UNINDENT# #UNINDENT# if ( last_trellis is None ) : #NEWLINE# #INDENT# new_layers = sequence_layers ( self . layers ) #NEWLINE# for layer in new_layers : #NEWLINE# #INDENT# layer . work ( fig = fig ) #NEWLINE# #UNINDENT# legend = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for layer in new_layers : #NEWLINE# #INDENT# legend = dictionary_union ( legend , layer . legend ) #NEWLINE# #UNINDENT# patches = [ ] #NEWLINE# labels = [ ] #NEWLINE# if ( len ( list ( legend . keys ( ) ) ) == 0 ) : #NEWLINE# #INDENT# key_function = ( lambda tup : tup ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( list ( legend . keys ( ) ) [ 0 ] ) == 2 ) : #NEWLINE# #INDENT# key_function = ( lambda tup : tup [ 1 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# key_function = ( lambda tup : ( tup [ 1 ] , tup [ 3 ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# for key in sorted ( list ( legend . keys ( ) ) , key = key_function ) : #NEWLINE# #INDENT# value = legend [ key ] #NEWLINE# patches . append ( value ) #NEWLINE# if ( len ( key ) == 2 ) : #NEWLINE# #INDENT# ( col , val ) = key #NEWLINE# labels . append ( ( '%s' % str ( val ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( len ( key ) == 4 ) : #NEWLINE# #INDENT# ( col1 , val1 , col2 , val2 ) = key #NEWLINE# labels . append ( ( '%s, %s' % ( str ( val1 ) , str ( val2 ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( 'Maximum 2 categorical attributes to display a lengend of' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if len ( legend ) : #NEWLINE# #INDENT# fig . legend ( patches , labels , loc = 'upper right' ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# new_layers = [ ] #NEWLINE# for layer in last_trellis . layers : #NEWLINE# #INDENT# if ( not isinstance ( layer , TrellisGrid ) ) : #NEWLINE# #INDENT# new_layers . append ( layer ) #NEWLINE# #UNINDENT# #UNINDENT# new_layers = sequence_layers ( new_layers ) #NEWLINE# new_layers = last_trellis . trellis ( new_layers ) #NEWLINE# new_layers = sequence_grids ( new_layers ) #NEWLINE# axes_grids = [ work_grid ( grid , fig ) for grid in new_layers ] #NEWLINE# axes_grid = axes_grids [ ( - 1 ) ] #NEWLINE# adjust_subplots ( fig , axes_grid , last_trellis , new_layers [ ( - 1 ) ] ) #NEWLINE# #UNINDENT# return fig