WrightTools.artists.create_figure

WrightTools.artists.create_figure(*, width='single', nrows=1, cols=[1], margin=1.0, hspace=0.25, wspace=0.25, cbar_width=0.25, aspects=[], default_aspect=1)[source]

Re-parameterization of matplotlib figure creation tools, exposing convenient variables.

Figures are defined primarily by their width. Height is defined by the aspect ratios of the subplots contained within. hspace, wspace, and cbar_width are defined in inches, making it easier to make consistent plots. Margins are enforced to be equal around the entire plot, starting from the edges of the subplots.

Parameters
  • width ({'single', 'double', 'dissertation'} or float (optional)) – The total width of the generated figure. Can be given in inches directly, or can be specified using keys. Default is ‘single’ (6.5 inches).

  • nrows (int (optional)) – The number of subplot rows in the figure. Default is 1.

  • cols (list (optional)) – A list of numbers, defining the number and width-ratios of the figure columns. May also contain the special string ‘cbar’, defining a column as a colorbar-containing column. Default is [1].

  • margin (float (optional)) – Margin in inches. Margin is applied evenly around the figure, starting from the subplot boundaries (so that ticks and labels appear in the margin). Default is 1.

  • hspace (float (optional)) – The ‘height space’ (space seperating two subplots vertically), in inches. Default is 0.25.

  • wspace (float (optional)) – The ‘width space’ (space seperating two subplots horizontally), in inches. Default is 0.25.

  • cbar_width (float (optional)) – The width of the colorbar in inches. Default is 0.25.

  • aspects (list of lists (optional)) – Define the aspect ratio of individual subplots. List of lists, each sub-ist having the format [[row, col], aspect]. The figure will expand vertically to acomidate the defined aspect ratio. Aspects are V/H so aspects larger than 1 will be taller than wide and vice-versa for aspects smaller than 1. You may only define the aspect for one subplot in each row. If no aspect is defined for a particular row, the leftmost subplot will have an aspect of default_aspect. Default is given by default_aspect kwarg.

  • default_aspect (number (optional)) – Default aspect of left-most column, if no aspect is defined for a given row.

Returns

(WrightTools.artists.Figure, WrightTools.artists.GridSpec). GridSpec contains SubplotSpec objects that can have axes placed into them. The SubplotSpec objects can be accessed through indexing: [row, col]. Slicing works, for example cax = plt.subplot(gs[:, -1]). See matplotlib gridspec documentation for more information.

Return type

tuple

Notes

To ensure the margins work as expected, save the fig with the same margins (pad_inches) as specified in this function. Common savefig call: plt.savefig(plt.savefig(output_path, dpi=300, transparent=True, pad_inches=1))

See also

wt.artists.plot_margins()

Plot lines to visualize the figure edges, margins, and centers. For debug and design purposes.

wt.artists.subplots_adjust()

Enforce margins for figure generated elsewhere.