Argument order of pyplot.subplots

Hi. It’s not really a big issue, but I’m often confused by the order of the arguments of pyplot.subplots. It starts with nrows and ncols, meaning the vertical parameter comes first and the horizontal next. Meanwhile, when you put figsize as its argument, it must be a tuple of (width, height), meaning the horizontal comes before the vertical.

So here comes the confusion: the number of subplots is vertical-first, but the figure size is horizontal-first.

Of course, I know I can always specify the arguments by the name (I mean, not plt.subplots(2,3) but plt.subplots(nrows=2, ncols=3)), but it is sometimes handy if I can omit the argument names. And anyway, figsize is a tuple, so you cannot do like this: figsize=(width=4, height=5).

Having said this, I haven’t come up with any good alternative ideas. Changing the order of either (nrows, ncols) or (width, height) will certainly lead to backward incompatibility, so I don’t think simply changing one of the orders is a good solution.

Hi Cycentum,

This isn’t a solution, just the way I think about it. I think it’s related to conventions with indexing matrices/images and conventions for listing dimensions.

For matrices/images/grids/arrays sizes are integers and listed as (row, col); for example a 5x4 matrix has 5 rows by 4 columns. subplots arranges things in a grid so rows then cols are listed.

For physical dimensions sizes are floats and usually (x, y) dimensions are listed, which is confusingly opposite to the convention for matrices/images/grids/arrays, etc.

If you wanted you could define a wrapper around subplots that switches the order of nrows and ncols so match the convention for width and height.