get_rows_cols(n, nrows=None, ncols=None, ratio=1, make=False, tight=True, remove_extra=True, **kwargs)#

Get the number of rows and columns needed to plot N figures.

If you have 37 plots, then how many rows and columns of axes do you know? This function convert a number (i.e. of plots) to a number of required rows and columns. If nrows or ncols is provided, the other will be calculated. Ties are broken in favor of more rows (i.e. 7x6 is preferred to 6x7). It can also generate the plots, if make=True.

Note: sc.getrowscols() and sc.get_rows_cols() are aliases.

  • n (int) – the number (of plots) to accommodate

  • nrows (int) – if supplied, keep this fixed and calculate the columns

  • ncols (int) – if supplied, keep this fixed and calculate the rows

  • ratio (float) – sets the number of rows relative to the number of columns (i.e. for 100 plots, 1 will give 10x10, 4 will give 20x5, etc.).

  • make (bool) – if True, generate subplots

  • tight (bool) – if True and make is True, then apply tight layout

  • remove_extra (bool) – if True and make is True, then remove extra subplots

  • kwargs (dict) – passed to pl.subplots()


A tuple of ints for the number of rows and the number of columns (which, of course, you can reverse)


nrows,ncols = sc.get_rows_cols(36) # Returns 6,6
nrows,ncols = sc.get_rows_cols(37) # Returns 7,6
nrows,ncols = sc.get_rows_cols(100, ratio=2) # Returns 15,7
nrows,ncols = sc.get_rows_cols(100, ratio=0.5) # Returns 8,13 since rows are prioritized
fig,axs     = sc.getrowscols(37, make=True) # Create 7x6 subplots, using the alias
New in version 1.0.0.
New in version 1.2.0: “make”, “tight”, and “remove_extra” arguments
New in version 1.3.0: alias without underscores