def get_best_layout(n_plots):

    assert n_plots > 0

    # Initialize the layout
    n_rows = 1
    n_cols = np.ceil(n_plots*1./n_rows)
    n_cols = int(n_cols)
    half_perimeter = n_cols + 1

    # Limit the range of possible layouts
    max_row = np.sqrt(n_plots)
    max_row = np.round(max_row)
    max_row = int(max_row)

    for l in xrange(1, max_row + 1):
        width = np.ceil(n_plots*1./l)
        width = int(width)
        if half_perimeter >= (width + l):
            n_rows = l
            n_cols = np.ceil(n_plots*1./n_rows)
            n_cols = int(n_cols)
            half_perimeter = n_rows + n_cols

    return n_rows, n_cols
Find the best basic layout for a given number of plots.
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/train_extensions/plots.py/get_best_layout