TAGS :Viewed: 12 - Published at: a few seconds ago

[ What are the parameters of host_subplot in matplotlib's mpl_toolkits.axes_grid1? ]

I am trying to understand how this Matplotlib example plot is made so I can derive from it for my own program:

enter image description here

The very first line of code is

host = host_subplot(111, axes_class=AA.Axes)

and I am trying to figure out what those parameters are to avoid "magic source code" in the future. A call to pydoc doesn't say much:

$ pydoc2.7 mpl_toolkits.axes_grid1.host_subplot
Help on function host_subplot in mpl_toolkits.axes_grid1:
mpl_toolkits.axes_grid1.host_subplot = host_subplot(*args, **kwargs)

The library source code isn't very illuminating:

def host_subplot(*args, **kwargs)

Moreover, in my search I've found that lots of these examples have that magical 111 parameter and I have no idea what it does.

Can anybody help me figure out:

  1. what the arguments of host_subplot() are
  2. how to go about finding this out for myself when pydoc and online documentation fail?

Answer 1


I'm not sure where you can find more info on host_subplot (I presume you have seen this page?), but the 111 argument must get passed onto subplot at some point, and is shorthand for saying 1 row, 1 column, plot number 1.

From the docs:

Typical call signature:

subplot(nrows, ncols, plot_number)

Where nrows and ncols are used to notionally split the figure into nrows * ncols sub-axes, and plot_number is used to identify the particular subplot that this function is to create within the notional grid. plot_number starts at 1, increments across rows first and has a maximum of nrows * ncols.