You can define a function based on the subplots command (note s at the end, different from the subplot command indicates urinieto) matplotlib.pyplot .
Below is an example of such a function, based on yours, which allows you to build several axes in a figure. You can determine the desired number of rows and columns in the layout of the picture.
def plot_figures(figures, nrows = 1, ncols=1): """Plot a dictionary of figures. Parameters ---------- figures : <title, figure> dictionary ncols : number of columns of subplots wanted in the display nrows : number of rows of subplots wanted in the figure """ fig, axeslist = plt.subplots(ncols=ncols, nrows=nrows) for ind,title in enumerate(figures): axeslist.ravel()[ind].imshow(figures[title], cmap=plt.gray()) axeslist.ravel()[ind].set_title(title) axeslist.ravel()[ind].set_axis_off() plt.tight_layout()
In fact, the function creates the number of axes in the drawings in accordance with nrows number of rows ( nrows ) and columns ( ncols ), and then ncols over the list of axes to build images and adds a title for each of them.,
Note that if there is only one image in your dictionary, your previous syntax, plot_figures(figures) will work, since nrows and ncols are set to 1 by default.
An example of what you can get:
import matplotlib.pyplot as plt import numpy as np

gcalmettes
source share