#NEWLINE# def get_best_layout( n_plots ) : #NEWLINE# #INDENT# '\n    Find the best basic layout for a given number of plots.\n    Minimize the perimeter with a minimum area (``n_plots``) for\n    an integer rectangle.\n\n\n    Parameters\n    ----------\n    n_plots : int\n        The number of plots to display\n\n    Returns\n    -------\n    n_rows : int\n        Number of rows in the layout\n    n_cols :\n        Number of columns in the layout\n    ' #NEWLINE# assert ( n_plots > 0 ) #NEWLINE# n_rows = 1 #NEWLINE# n_cols = np . ceil ( ( ( n_plots * 1.0 ) / n_rows ) ) #NEWLINE# n_cols = int ( n_cols ) #NEWLINE# half_perimeter = ( n_cols + 1 ) #NEWLINE# max_row = np . sqrt ( n_plots ) #NEWLINE# max_row = np . round ( n_plots ) #NEWLINE# max_row = int ( max_row ) #NEWLINE# for l in xrange ( 1 , ( max_row + 1 ) ) : #NEWLINE# #INDENT# width = np . ceil ( ( ( n_plots * 1.0 ) / l ) ) #NEWLINE# width = int ( width ) #NEWLINE# if ( half_perimeter >= ( width + l ) ) : #NEWLINE# #INDENT# n_rows = l #NEWLINE# n_cols = np . ceil ( ( ( n_plots * 1.0 ) / n_rows ) ) #NEWLINE# n_cols = int ( n_cols ) #NEWLINE# half_perimeter = ( n_rows + n_cols ) #NEWLINE# #UNINDENT# #UNINDENT# return ( n_rows , n_cols )